using System; using System.IO; using System.Xml.Serialization; namespace SCMA { #region -- ModelDesign Class -- /// /// Classe per serializzazione / deserializzazione del datamodel x le informazioni necessarie x ADAPTER OPC-UA 2.1+ /// /// ref: http://www.cambiaresearch.com/articles/33/how-can-i-easily-manage-an-xml-configuration-file-in-dotnet /// [Serializable] [XmlRoot("ModelDesign")] public class ModelDesign { cMachine mMachine; #if false string sNomeAdapt; int nVers; double tContOreMaccOn; double tContOreMaccLav; double tContSlittaTast; int[] _ContGiriElettrom; float[] _ContKmMovAssi; tipoAdapter etipoAdapt; element[] _VacuumPump; element[] _VacuumAct; element[] _Lubro; element[] _SlittaMag; element[] _ProtMag; element[] _Cooler; element[] _Press; element[] _Temp; element[] _Path; element[] _UnOp; element[] _Axis; element[] _MemArea; #endif /// /// init conf adapter /// public ModelDesign() { #if false sNomeAdapt = ""; etipoAdapt = tipoAdapter.DEMO; #endif } /// /// Classe di base oggetti OPC-UA in Datamodel da deserializzare /// public class ouBaseObj { //[XmlAttribute("SymbolicName")] [XmlAttribute] public string SymbolicName { get; set; } [XmlAttribute("BrowseName")] public string BrowseName { get; set; } [XmlAttribute("DataType")] public string DataType { get; set; } [XmlAttribute("ValueRank")] public string ValueRank { get; set; } } public class Property : ouBaseObj { [XmlAttribute("Value")] public string Value { get; set; } } public class ouVariable : ouBaseObj { [XmlAttribute("Units")] public string Units { get; set; } } /// /// Oggetto più esterno Machine /// [Serializable] public class cMachine { public Property Model { get; set; } } public cMachine Machine { get { return mMachine; } set { mMachine = value; } } #if false public int nVacuumPump { get { int answ = 0; if (VacuumPump != null) { try { answ = Convert.ToInt32(VacuumPump.Length); } catch { } } return answ; } } public int nVacuumAct { get { int answ = 0; if (VacuumAct != null) { try { answ = Convert.ToInt32(VacuumAct.Length); } catch { } } return answ; } } public int nLubro { get { int answ = 0; if (Lubro != null) { try { answ = Convert.ToInt32(Lubro.Length); } catch { } } return answ; } } public int nSlittaMag { get { int answ = 0; if (SlittaMag != null) { try { answ = Convert.ToInt32(SlittaMag.Length); } catch { } } return answ; } } public int nProtMag { get { int answ = 0; if (ProtMag != null) { try { answ = Convert.ToInt32(ProtMag.Length); } catch { } } return answ; } } public int nCooler { get { int answ = 0; if (Cooler != null) { try { answ = Convert.ToInt32(Cooler.Length); } catch { } } return answ; } } public int nPress { get { int answ = 0; if (Press != null) { try { answ = Convert.ToInt32(Press.Length); } catch { } } return answ; } } public int nTemp { get { int answ = 0; if (Temp != null) { try { answ = Convert.ToInt32(Temp.Length); } catch { } } return answ; } } public int nPath { get { int answ = 0; if (Path != null) { try { answ = Convert.ToInt32(Path.Length); } catch { } } return answ; } } public int nUnOp { get { int answ = 0; if (UnOp != null) { try { answ = Convert.ToInt32(UnOp.Length); } catch { } } return answ; } } public int nAxis { get { int answ = 0; if (Axis != null) { try { answ = Convert.ToInt32(Axis.Length); } catch { } } return answ; } } public int nMemArea { get { int answ = 0; if (MemArea != null) { try { answ = Convert.ToInt32(MemArea.Length); } catch { } } return answ; } } #endif /// /// Serializzazione XML dell'oggetto conf dell'adapter /// /// /// public static void Serialize(string file, ModelDesign c) { // prima provo a creare il file vuoto... if (!File.Exists(file)) { string dirPath = file.Substring(0, file.LastIndexOf('\\')); // verifico directory if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } } // salvo effettivamente file... XmlSerializer xs = new XmlSerializer(c.GetType()); StreamWriter writer = File.CreateText(file); xs.Serialize(writer, c); writer.Flush(); writer.Close(); } /// /// deserializzazione oggetto conf adapter /// /// /// public static ModelDesign Deserialize(string file) { XmlSerializer xs = new XmlSerializer(typeof(ModelDesign)); StreamReader reader = File.OpenText(file); ModelDesign c = (ModelDesign)xs.Deserialize(reader); reader.Close(); return c; } /// /// restitusice forma XML grezza del file /// /// /// public static string rawXml(string file) { string answ = ""; XmlSerializer xs = new XmlSerializer(typeof(ModelDesign)); StreamReader reader = File.OpenText(file); answ = reader.ReadToEnd(); reader.Close(); return answ; } #if false public int Version { get { return nVers; } set { nVers = value; } } public string NomeAdapt { get { return sNomeAdapt; } set { sNomeAdapt = value; } } public tipoAdapter TipoAdapt { get { return etipoAdapt; } set { etipoAdapt = value; } } public double ContOreMaccOn { get { return tContOreMaccOn; } set { tContOreMaccOn = value; } } public double ContOreMaccLav { get { return tContOreMaccLav; } set { tContOreMaccLav = value; } } public double ContSlittaTast { get { return tContSlittaTast; } set { tContSlittaTast = value; } } public int[] ContGiriElettrom { get { return _ContGiriElettrom; } set { _ContGiriElettrom = value; } } public float[] ContKmMovAssi { get { return _ContKmMovAssi; } set { _ContKmMovAssi = value; } } public element[] VacuumPump { get { return _VacuumPump; } set { _VacuumPump = value; } } public element[] VacuumAct { get { return _VacuumAct; } set { _VacuumAct = value; } } public element[] Lubro { get { return _Lubro; } set { _Lubro = value; } } public element[] SlittaMag { get { return _SlittaMag; } set { _SlittaMag = value; } } public element[] ProtMag { get { return _ProtMag; } set { _ProtMag = value; } } public element[] Cooler { get { return _Cooler; } set { _Cooler = value; } } public element[] Press { get { return _Press; } set { _Press = value; } } public element[] Temp { get { return _Temp; } set { _Temp = value; } } public element[] Path { get { return _Path; } set { _Path = value; } } public element[] UnOp { get { return _UnOp; } set { _UnOp = value; } } public element[] Axis { get { return _Axis; } set { _Axis = value; } } public element[] MemArea { get { return _MemArea; } set { _MemArea = value; } } #endif } #if false [Serializable] [XmlType(TypeName = "dataRef")] public struct DataRefItem { public K Key { get; set; } public V Value { get; set; } public DataRefItem(K k, V v) : this() { Key = k; Value = v; } } /// /// classe elemento base in cui salvare i dati di conf x recupero dati adapters /// public class element { /// /// identificativo univoco x classe di elemento /// public string ident; /// /// Elenco riferimento dati x recupero (es posizioni memoria separate da #) /// public List> dataRefList; /// /// init empty /// public element() { ident = ""; dataRefList = new List>(); } /// /// init element con dati /// /// Identificativo univoco /// Parametri x recupero dati in forma dictionary public element(string Idx, List> DataRef) { ident = Idx; dataRefList = DataRef; } } #endif #endregion }