Ancora update gestione conf

This commit is contained in:
Samuele Locatelli
2022-12-23 15:10:19 +01:00
parent 639e77ee7a
commit ee3adc7fbd
8 changed files with 244 additions and 41 deletions
+74 -12
View File
@@ -5,8 +5,81 @@
/// </summary>
public class CmdUri
{
#region Public Constructors
/// <summary>
/// Init classe gestione comandi
/// </summary>
/// <param name="baseURI"></param>
public CmdUri(string baseURI)
{
BaseUri = baseURI;
}
#endregion Public Constructors
#region Public Properties
/// <summary>
/// comando base x USER LOG - salvataggio parametri extra sistema MAPO
/// </summary>
public string ULog { get; set; } = "IOB/ulog/";
/// <summary>
/// comando base x USER LOG - salvataggio parametri extra sistema MAPO in modalità JSON
/// payload come lista
/// </summary>
public string ULogJson { get; set; } = "IOB/ulogJson/";
#endregion Public Properties
#region Public Methods
/// <summary>
/// Recupera path/URI comando richiesto (SE disponibile)
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public string GetCommand(string key)
{
// default ad implicito...
string answ = $"{BaseUri}/{key}/";
if (CurrSetup.ContainsKey(key))
{
answ = CurrSetup[key];
}
return answ;
}
public Dictionary<string, string> StdCommands()
{
CurrSetup = new Dictionary<string, string>();
CurrSetup.Add("Alive", "IOB");
CurrSetup.Add("Base", "IOB/input/");
CurrSetup.Add("BaseJson", "IOB/evListJson/");
CurrSetup.Add("RawTransfJson", "IOB/rawTransfJson/");
CurrSetup.Add("Enabled", "IOB/enabled/");
CurrSetup.Add("Flog", "IOB/flog/");
CurrSetup.Add("FlogJson", "IOB/flogJson/");
CurrSetup.Add("ForcleSplitOdl", "IOB/forceSplitOdlFull/");
CurrSetup.Add("IdleTime", "IOB/getIdlePeriod/");
CurrSetup.Add("OdlStarted", "IOB/getCurrOdlStart/");
CurrSetup.Add("Reboot", "IOB/sendReboot.aspx?idxMacchina=/");
// riordino
CurrSetup = CurrSetup.OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
return CurrSetup;
}
#endregion Public Methods
#region Protected Properties
protected string BaseUri { get; set; } = "IOB";
protected Dictionary<string, string> CurrSetup { get; set; } = new Dictionary<string, string>();
#endregion Protected Properties
#if false
/// <summary>
/// comando base x check ALIVE
/// </summary>
@@ -64,17 +137,6 @@
/// </summary>
public string Reboot { get; set; } = "sendReboot.aspx?idxMacchina=";
/// <summary>
/// comando base x USER LOG - salvataggio parametri extra sistema MAPO
/// </summary>
public string ULog { get; set; } = "IOB/ulog/";
/// <summary>
/// comando base x USER LOG - salvataggio parametri extra sistema MAPO in modalità JSON
/// payload come lista
/// </summary>
public string ULogJson { get; set; } = "IOB/ulogJson/";
#endregion Public Properties
#endif
}
}
+2 -2
View File
@@ -37,11 +37,11 @@ namespace IobConf.Core
/// <summary>
/// Rack (Siemens S7)
/// </summary>
public short rack { get; set; } = 0;
public short Rack { get; set; } = 0;
/// <summary>
/// Slot (Siemens S7)
/// </summary>
public short slot { get; set; } = 0;
public short Slot { get; set; } = 0;
}
}
+1
View File
@@ -8,6 +8,7 @@
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="NLog" Version="5.1.0" />
<PackageReference Include="YamlDotNet" Version="12.3.1" />
</ItemGroup>
+119 -20
View File
@@ -2,6 +2,7 @@
using YamlDotNet.Serialization.NamingConventions;
using YamlDotNet.Serialization;
using static IobConf.Core.EnumConf;
using NLog;
// <Auto-Generated>
// This is here so CodeMaid doesn't reorganize this document
@@ -32,39 +33,137 @@ namespace IobConf.Core
{
// leggo file INI
IniFile fIni = new IniFile(iniFilePath);
// effettuo conversione
newConfObj = ConvertFromINI(fIni);
string codIob= Path.GetFileNameWithoutExtension(iniFilePath);
// effettuo conversione...
// Dati generali (vendor, modello...)
newConfObj.CodIOB = fIni.ReadString("IOB", "IOB_NAME", codIob);
newConfObj.Vendor = fIni.ReadString("MACHINE", "VENDOR", "STEAMWARE");
newConfObj.Model = fIni.ReadString("MACHINE", "MODEL", "NONE");
newConfObj.ConfFileName = Path.GetFileName(iniFilePath);
// tipo adapter// verifico tipo adapter
try
{
newConfObj.IobType = (AdapterType)Enum.Parse(typeof(AdapterType), fIni.ReadString("IOB", "CNCTYPE", "ND"));
}
catch (Exception exc)
{
newConfObj.IobType = AdapterType.ND;
string rawVal = fIni.ReadString("IOB", "CNCTYPE", "DEMO");
//newConfObj.lgError($"Eccezione in conversione tipo adapter: richiesto {rawVal} | tipo non codificato...{Environment.NewLine}{exc}");
}
newConfObj.GeneralCom = (ComLayer)Enum.Parse(typeof(ComLayer), fIni.ReadString("IOB", "CNCFAMILY", "ND"));
// CNC
newConfObj.CncData.pingMsTimeout = fIni.ReadInteger("IOB", "PING_MS_TIMEOUT", 500);
newConfObj.CncData.IpAddr = fIni.ReadString("CNC", "IP", "::1");
newConfObj.CncData.Port = fIni.ReadString("CNC", "PORT", "0");
newConfObj.CncData.CpuType = fIni.ReadString("CNC", "CPUTYPE", "");
newConfObj.CncData.Rack = (short)fIni.ReadInteger("CNC", "RACK", 0);
newConfObj.CncData.Slot = (short)fIni.ReadInteger("CNC", "SLOT", 0);
// BLINK
newConfObj.InputDataProc.BlinkMaxCounter = Convert.ToInt32(fIni.ReadString("BLINK", "MAX_COUNTER_BLINK", "1"));
newConfObj.InputDataProc.BlinkFilterMask = Convert.ToInt32(fIni.ReadString("BLINK", "BLINK_FILT", "0"));
newConfObj.TempoCiclo.MaxDelayFactor = Convert.ToDouble(fIni.ReadString("OPTPAR", "TC_MAX_TC_FACTOR", "1.2").Replace(".", ","));
newConfObj.TempoCiclo.Lambda = Convert.ToDouble(fIni.ReadString("OPTPAR", "TC_LAMBDA", "0.5").Replace(".", ","));
newConfObj.TempoCiclo.MaxIncrPz = Convert.ToDouble(fIni.ReadString("OPTPAR", "TC_MAX_INCR", "5").Replace(".", ","));
// Server
string MpIp=fIni.ReadString("SERVER", "MPIP", "::1");
if (!string.IsNullOrEmpty(MpIp))
{
newConfObj.ServerMES.Transport = MpIp.StartsWith("https://") ? "https" : "http";
newConfObj.ServerMES.IpAddr = MpIp.Replace($"{newConfObj.ServerMES.Transport}://", ""); // tolgo http/https...
}
//newConfObj.ServerMES.Commands.Alive
// Altro (versione, ...)
newConfObj.ReleaseVers = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
newConfObj.IobManConf.MinDeltaSec = fIni.ReadInteger("IOB", "MinDeltaSec", 6);
// OptPar
Dictionary<string, string> optParRead = new Dictionary<string, string>();
string[] optParRows = fIni.ReadSection("OPTPAR");
if (optParRows.Length > 0)
{
try
{
string[] kvp;
foreach (var item in optParRows)
{
kvp = item.Split('=');
optParRead.Add(kvp[0], kvp[1]);
}
//newConfObj.lgDebug($"Caricati {optParRead.Count} parametri opzionali da OPTPAR");
}
catch (Exception exc)
{
//newConfObj.lgError(string.Format("EXCEPTION in fase di lettura OPTPAR: {0}{1}", Environment.NewLine, exc));
}
}
// riordino alfabeticamente
optParRead = optParRead.OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
newConfObj.OptPar = optParRead;
}
catch
{ }
return newConfObj;
}
#region Logging
/// <summary>
/// oggetto logging
/// </summary>
protected Logger Log;// = LogManager.GetCurrentClassLogger();
/// <summary>
/// Effettua logging DEBUG corretto impostanto anche la variabile IOB prima di scrivere...
/// </summary>
/// <param name="txt2log"></param>
protected void lgDebug(string txt2log)
{
Log.Factory.Configuration.Variables["codIOB"] = this.CodIOB;
Log.Debug(txt2log);
}
/// <summary>
/// Restituisce un oggetto di conf leggendo INI ed effettuando conversione
/// Effettua logging ERROR corretto impostanto anche la variabile IOB prima di scrivere...
/// </summary>
/// <param name="iniFilePath"></param>
/// <returns></returns>
protected static IobConfTree ConvertFromINI(IniFile fIni)
/// <param name="txt2log"></param>
protected void lgError(string txt2log)
{
IobConfTree newConfObj = new IobConfTree();
try
if (!string.IsNullOrEmpty(txt2log))
{
// effettuo conversione...
// leggo vendor e modello...
newConfObj.Vendor = fIni.ReadString("MACHINE", "VENDOR", "STEAMWARE");
newConfObj.Model = fIni.ReadString("MACHINE", "MODEL", "NONE");
// tipo adapter
newConfObj.IobType = (AdapterType)Enum.Parse(typeof(AdapterType), fIni.ReadString("IOB", "CNCTYPE", "ND"));
newConfObj.GeneralCom = (ComLayer)Enum.Parse(typeof(ComLayer), fIni.ReadString("IOB", "CNCFAMILY", "ND"));
Log.Factory.Configuration.Variables["codIOB"] = this.CodIOB;
Log.Error(txt2log);
}
catch
{ }
return newConfObj;
}
/// <summary>
/// Effettua logging INFO corretto impostanto anche la variabile IOB prima di scrivere...
/// </summary>
/// <param name="txt2log"></param>
protected void lgInfo(string txt2log)
{
Log.Factory.Configuration.Variables["codIOB"] = this.CodIOB;
Log.Info(txt2log);
}
/// <summary>
/// Effettua logging TRACE corretto impostanto anche la variabile IOB prima di scrivere...
/// </summary>
/// <param name="txt2log"></param>
protected void lgTrace(string txt2log)
{
Log.Factory.Configuration.Variables["codIOB"] = this.CodIOB;
Log.Trace(txt2log);
}
#endregion
/// <summary>
/// Codice Cliente/Installazione
+5 -7
View File
@@ -23,18 +23,16 @@ namespace IobConf.Core
/// </summary>
public string BaseAppUrl { get; set; } = "/MP/IO/";
public CmdUri Commands { get; set; } = new CmdUri();
/// <summary>
/// Dizionario comandi configurati
/// </summary>
public Dictionary<string, string> Commands { get; set; } = new CmdUri("IOB").StdCommands();
//public CmdUri Commands { get; set; } = new CmdUri();
/// <summary>
/// Installazione di riferimento
/// </summary>
public string ClientInstall { get; set; } = "SW";
}
}
+3
View File
@@ -11,6 +11,9 @@
</ItemGroup>
<ItemGroup>
<None Update="logs\.placeholder">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="temp\.placeholder">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
+39
View File
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">
<variable name="logDir" value="${basedir}/logs"/>
<targets>
<target xsi:type="File"
name="f_base"
fileName="${logDir}/${var:codIOB:default=0000}/${shortdate}.log"
layout="${longdate} [${uppercase:${level}}] ${logger:shortName=true}|${message}"
archiveFileName="${logDir}/${var:codIOB:default=0000}/${shortdate}.{###}.log"
archiveNumbering="Sequence"
archiveAboveSize="10240000"
maxArchiveFiles="90"
enableArchiveFileCompression="false"
keepFileOpen="false"
/>
<target xsi:type="File"
name="f_error"
fileName="${logDir}/${var:codIOB:default=0000}/${shortdate}_err.log"
layout="${longdate} [${uppercase:${level}}] ${logger:shortName=true}|${message}${newline}${exception:format=tostring}"
archiveFileName="${logDir}/${var:codIOB:default=0000}/${shortdate}_err.{###}.log"
archiveNumbering="Sequence"
archiveAboveSize="10240000"
maxArchiveFiles="90"
enableArchiveFileCompression="false"
keepFileOpen="false"
/>
</targets>
<rules>
<!-- Logging Levels (Trace, Debug, Info, Warn, Error, Fatal)-->
<logger name="*" minlevel="Trace" maxlevel="Warn" final="true" writeTo="f_base" />
<logger name="*" minlevel="Error" writeTo="f_error" />
</rules>
</nlog>
+1
View File
@@ -0,0 +1 @@