using Newtonsoft.Json; using YamlDotNet.Serialization.NamingConventions; using YamlDotNet.Serialization; using static IobConf.Core.Enum; // // This is here so CodeMaid doesn't reorganize this document // namespace IobConf.Core { /// /// Albero configurazione globale IOB /// [Serializable] public class IobConfTree { /// /// Init classe configurazione /// public IobConfTree() { } /// /// Codice Cliente/Installazione /// public string Customer { get; set; } = "SteamWare"; /// /// Codice univoco IOB /// public string CodIOB { get; set; } = "ND"; /// /// Costruttore /// public string Vendor { get; set; } = "ACME"; /// /// Codice modello /// public string Model { get; set; } = "NONE"; /// /// Nome file di configurazione /// public string ConfFileName { get; set; } = ""; /// /// TIpologia generale dell'adapter /// public ComLayer GeneralCom { get; set; } = ComLayer.ND; /// /// Tipo Adapter specifico (implementazione) /// public AdapterType IobType { get; set; } = AdapterType.ND; /// /// Setup server MP da chiamare /// public ServerMapo ServerMES { get; set; } = new ServerMapo(); /// /// Setup info verso IOB-MAN /// public RedisPub IobManConf { get; set; } = new RedisPub(); /// /// Dati configurazione CNC /// public CncConf CncData { get; set; } = new CncConf(); /// /// Setup processing dati in ingresso (es: blink segnali) /// public InputSignalProcess InputDataProc { get; set; } = new InputSignalProcess(); /// /// Dati relativi ai parametri gestione tempo ciclo /// public TCData TempoCiclo { get; set; } = new TCData(); /// /// Dizionario dei parametri opzionali /// public Dictionary OptPar { get; set; } = new Dictionary(); /// /// Versione software IOB /// public string ReleaseVers { get; set; } = "0.0.0.0"; #region Metodi Serializzazione /// /// Restituisce conf serializzata in formato JSON /// /// /// public string getJson() { string rawdata = JsonConvert.SerializeObject(this, Formatting.Indented); return rawdata; } /// /// Restituisce conf serializzata in formato YAML /// /// /// public string getYaml() { var serializer = new SerializerBuilder() .WithNamingConvention(CamelCaseNamingConvention.Instance) .Build(); var rawdata = serializer.Serialize(this); return rawdata; } #endregion #region Metodi Load/Save /// /// Scrive conf serializzata in formato JSON /// /// /// public bool SaveJson(string filePath) { bool answ = false; try { string rawdata = getJson(); File.WriteAllText(filePath, rawdata); answ = true; } catch { } return answ; } /// /// Scrive conf serializzata in formato YAML /// /// /// public bool SaveYaml(string filePath) { bool answ = false; try { var rawdata = getYaml(); File.WriteAllText(filePath, rawdata); answ = true; } catch { } return answ; } #endregion } }