From ee3adc7fbda8a7d313197211fc1d3131bcc7b15d Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 23 Dec 2022 15:10:19 +0100 Subject: [PATCH] Ancora update gestione conf --- IobConf.Core/CmdUri.cs | 86 ++++++++++++++++--- IobConf.Core/CncConf.cs | 4 +- IobConf.Core/IobConf.Core.csproj | 1 + IobConf.Core/IobConfTree.cs | 139 ++++++++++++++++++++++++++----- IobConf.Core/ServerMapo.cs | 12 ++- IobConf.UI/IobConf.UI.csproj | 3 + IobConf.UI/NLog.config | 39 +++++++++ IobConf.UI/logs/.placeholder | 1 + 8 files changed, 244 insertions(+), 41 deletions(-) create mode 100644 IobConf.UI/NLog.config create mode 100644 IobConf.UI/logs/.placeholder diff --git a/IobConf.Core/CmdUri.cs b/IobConf.Core/CmdUri.cs index 0635324f..48c85957 100644 --- a/IobConf.Core/CmdUri.cs +++ b/IobConf.Core/CmdUri.cs @@ -5,8 +5,81 @@ /// public class CmdUri { + #region Public Constructors + + /// + /// Init classe gestione comandi + /// + /// + public CmdUri(string baseURI) + { + BaseUri = baseURI; + } + + #endregion Public Constructors + #region Public Properties + /// + /// comando base x USER LOG - salvataggio parametri extra sistema MAPO + /// + public string ULog { get; set; } = "IOB/ulog/"; + + /// + /// comando base x USER LOG - salvataggio parametri extra sistema MAPO in modalità JSON + /// payload come lista + /// + public string ULogJson { get; set; } = "IOB/ulogJson/"; + + #endregion Public Properties + + #region Public Methods + + /// + /// Recupera path/URI comando richiesto (SE disponibile) + /// + /// + /// + public string GetCommand(string key) + { + // default ad implicito... + string answ = $"{BaseUri}/{key}/"; + if (CurrSetup.ContainsKey(key)) + { + answ = CurrSetup[key]; + } + return answ; + } + + public Dictionary StdCommands() + { + CurrSetup = new Dictionary(); + 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 CurrSetup { get; set; } = new Dictionary(); + + #endregion Protected Properties + +#if false /// /// comando base x check ALIVE /// @@ -64,17 +137,6 @@ /// public string Reboot { get; set; } = "sendReboot.aspx?idxMacchina="; - /// - /// comando base x USER LOG - salvataggio parametri extra sistema MAPO - /// - public string ULog { get; set; } = "IOB/ulog/"; - - /// - /// comando base x USER LOG - salvataggio parametri extra sistema MAPO in modalità JSON - /// payload come lista - /// - public string ULogJson { get; set; } = "IOB/ulogJson/"; - - #endregion Public Properties +#endif } } \ No newline at end of file diff --git a/IobConf.Core/CncConf.cs b/IobConf.Core/CncConf.cs index 2234c9b6..90a7e2b1 100644 --- a/IobConf.Core/CncConf.cs +++ b/IobConf.Core/CncConf.cs @@ -37,11 +37,11 @@ namespace IobConf.Core /// /// Rack (Siemens S7) /// - public short rack { get; set; } = 0; + public short Rack { get; set; } = 0; /// /// Slot (Siemens S7) /// - public short slot { get; set; } = 0; + public short Slot { get; set; } = 0; } } diff --git a/IobConf.Core/IobConf.Core.csproj b/IobConf.Core/IobConf.Core.csproj index 3e3eec0e..7361855e 100644 --- a/IobConf.Core/IobConf.Core.csproj +++ b/IobConf.Core/IobConf.Core.csproj @@ -8,6 +8,7 @@ + diff --git a/IobConf.Core/IobConfTree.cs b/IobConf.Core/IobConfTree.cs index de54e4b6..7c76ca94 100644 --- a/IobConf.Core/IobConfTree.cs +++ b/IobConf.Core/IobConfTree.cs @@ -2,6 +2,7 @@ using YamlDotNet.Serialization.NamingConventions; using YamlDotNet.Serialization; using static IobConf.Core.EnumConf; +using NLog; // // 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 optParRead = new Dictionary(); + 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 + + /// + /// oggetto logging + /// + protected Logger Log;// = LogManager.GetCurrentClassLogger(); + + /// + /// Effettua logging DEBUG corretto impostanto anche la variabile IOB prima di scrivere... + /// + /// + protected void lgDebug(string txt2log) + { + Log.Factory.Configuration.Variables["codIOB"] = this.CodIOB; + Log.Debug(txt2log); + } + /// - /// Restituisce un oggetto di conf leggendo INI ed effettuando conversione + /// Effettua logging ERROR corretto impostanto anche la variabile IOB prima di scrivere... /// - /// - /// - protected static IobConfTree ConvertFromINI(IniFile fIni) + /// + 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; } + /// + /// Effettua logging INFO corretto impostanto anche la variabile IOB prima di scrivere... + /// + /// + protected void lgInfo(string txt2log) + { + Log.Factory.Configuration.Variables["codIOB"] = this.CodIOB; + Log.Info(txt2log); + } + + /// + /// Effettua logging TRACE corretto impostanto anche la variabile IOB prima di scrivere... + /// + /// + protected void lgTrace(string txt2log) + { + Log.Factory.Configuration.Variables["codIOB"] = this.CodIOB; + Log.Trace(txt2log); + } + + #endregion /// /// Codice Cliente/Installazione diff --git a/IobConf.Core/ServerMapo.cs b/IobConf.Core/ServerMapo.cs index c766d44a..62f34a7c 100644 --- a/IobConf.Core/ServerMapo.cs +++ b/IobConf.Core/ServerMapo.cs @@ -23,18 +23,16 @@ namespace IobConf.Core /// public string BaseAppUrl { get; set; } = "/MP/IO/"; - public CmdUri Commands { get; set; } = new CmdUri(); + /// + /// Dizionario comandi configurati + /// + public Dictionary Commands { get; set; } = new CmdUri("IOB").StdCommands(); + //public CmdUri Commands { get; set; } = new CmdUri(); /// /// Installazione di riferimento /// public string ClientInstall { get; set; } = "SW"; - - - - - - } } diff --git a/IobConf.UI/IobConf.UI.csproj b/IobConf.UI/IobConf.UI.csproj index eafa16f1..f1d084c0 100644 --- a/IobConf.UI/IobConf.UI.csproj +++ b/IobConf.UI/IobConf.UI.csproj @@ -11,6 +11,9 @@ + + Always + Always diff --git a/IobConf.UI/NLog.config b/IobConf.UI/NLog.config new file mode 100644 index 00000000..154a5706 --- /dev/null +++ b/IobConf.UI/NLog.config @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + diff --git a/IobConf.UI/logs/.placeholder b/IobConf.UI/logs/.placeholder new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/IobConf.UI/logs/.placeholder @@ -0,0 +1 @@ + \ No newline at end of file