completato gestione edit conf e caricamento istanza (x demo)
This commit is contained in:
Binary file not shown.
+181
-182
@@ -6,40 +6,39 @@ using System.Xml.Serialization;
|
||||
|
||||
namespace MTC_Sim
|
||||
{
|
||||
#region -- AdapterConf Class --
|
||||
/// <summary>
|
||||
/// This Configuration class is basically just a set of
|
||||
/// properties with a couple of static methods to manage
|
||||
/// the serialization to and deserialization from a
|
||||
/// simple XML file.
|
||||
///
|
||||
/// ref: http://www.cambiaresearch.com/articles/33/how-can-i-easily-manage-an-xml-configuration-file-in-dotnet
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class AdapterConf
|
||||
{
|
||||
string sNomeAdapt;
|
||||
int nVers;
|
||||
public tipoAdapter etipoAdapt;
|
||||
|
||||
#region -- AdapterConf Class --
|
||||
/// <summary>
|
||||
/// This Configuration class is basically just a set of
|
||||
/// properties with a couple of static methods to manage
|
||||
/// the serialization to and deserialization from a
|
||||
/// simple XML file.
|
||||
///
|
||||
/// ref: http://www.cambiaresearch.com/articles/33/how-can-i-easily-manage-an-xml-configuration-file-in-dotnet
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class AdapterConf
|
||||
{
|
||||
string sNomeAdapt;
|
||||
int nVers;
|
||||
public tipoAdapter etipoAdapt;
|
||||
element[] _VacuumPump;
|
||||
element[] _VacuumAct;
|
||||
element[] _Lubro;
|
||||
element[] _Cooler;
|
||||
element[] _Press;
|
||||
element[] _Temp;
|
||||
element[] _Path;
|
||||
element[] _UnOp;
|
||||
element[] _Axis;
|
||||
|
||||
element[] _VacuumPump;
|
||||
element[] _VacuumAct;
|
||||
element[] _Lubro;
|
||||
element[] _Cooler;
|
||||
element[] _Press;
|
||||
element[] _Temp;
|
||||
element[] _Path;
|
||||
element[] _UnOp;
|
||||
element[] _Axis;
|
||||
|
||||
/// <summary>
|
||||
/// init conf adapter
|
||||
/// </summary>
|
||||
public AdapterConf()
|
||||
{
|
||||
sNomeAdapt = "";
|
||||
etipoAdapt = tipoAdapter.Demo;
|
||||
/// <summary>
|
||||
/// init conf adapter
|
||||
/// </summary>
|
||||
public AdapterConf()
|
||||
{
|
||||
sNomeAdapt = "";
|
||||
etipoAdapt = tipoAdapter.Demo;
|
||||
}
|
||||
public int nVacuumPump
|
||||
{
|
||||
@@ -174,163 +173,163 @@ namespace MTC_Sim
|
||||
/// <param name="file"></param>
|
||||
/// <param name="c"></param>
|
||||
public static void Serialize(string file, AdapterConf c)
|
||||
{
|
||||
System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(c.GetType());
|
||||
StreamWriter writer = File.CreateText(file);
|
||||
xs.Serialize(writer, c);
|
||||
writer.Flush();
|
||||
writer.Close();
|
||||
}
|
||||
/// <summary>
|
||||
/// deserializzazione oggetto conf adapter
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <returns></returns>
|
||||
public static AdapterConf Deserialize(string file)
|
||||
{
|
||||
System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(AdapterConf));
|
||||
StreamReader reader = File.OpenText(file);
|
||||
AdapterConf c = (AdapterConf)xs.Deserialize(reader);
|
||||
reader.Close();
|
||||
return c;
|
||||
}
|
||||
/// <summary>
|
||||
/// restitusice forma XML grezza del file
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <returns></returns>
|
||||
public static string rawXml(string file)
|
||||
{
|
||||
string answ = "";
|
||||
System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(AdapterConf));
|
||||
StreamReader reader = File.OpenText(file);
|
||||
answ = reader.ReadToEnd();
|
||||
reader.Close();
|
||||
return answ;
|
||||
}
|
||||
{
|
||||
System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(c.GetType());
|
||||
StreamWriter writer = File.CreateText(file);
|
||||
xs.Serialize(writer, c);
|
||||
writer.Flush();
|
||||
writer.Close();
|
||||
}
|
||||
/// <summary>
|
||||
/// deserializzazione oggetto conf adapter
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <returns></returns>
|
||||
public static AdapterConf Deserialize(string file)
|
||||
{
|
||||
System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(AdapterConf));
|
||||
StreamReader reader = File.OpenText(file);
|
||||
AdapterConf c = (AdapterConf)xs.Deserialize(reader);
|
||||
reader.Close();
|
||||
return c;
|
||||
}
|
||||
/// <summary>
|
||||
/// restitusice forma XML grezza del file
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <returns></returns>
|
||||
public static string rawXml(string file)
|
||||
{
|
||||
string answ = "";
|
||||
System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(AdapterConf));
|
||||
StreamReader reader = File.OpenText(file);
|
||||
answ = reader.ReadToEnd();
|
||||
reader.Close();
|
||||
return answ;
|
||||
}
|
||||
|
||||
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 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[] 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 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 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[] 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; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Serializable]
|
||||
[XmlType(TypeName = "dataRef")]
|
||||
public struct DataRefItem<K, V>
|
||||
{
|
||||
public K Key { get; set; }
|
||||
public V Value { get; set; }
|
||||
[Serializable]
|
||||
[XmlType(TypeName = "dataRef")]
|
||||
public struct DataRefItem<K, V>
|
||||
{
|
||||
public K Key { get; set; }
|
||||
public V Value { get; set; }
|
||||
|
||||
public DataRefItem(K k, V v) : this() { Key = k; Value = v; }
|
||||
}
|
||||
public DataRefItem(K k, V v) : this() { Key = k; Value = v; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// classe elemento base in cui salvare i dati di conf x recupero dati adapters
|
||||
/// </summary>
|
||||
public class element
|
||||
{
|
||||
/// <summary>
|
||||
/// identificativo univoco x classe di elemento
|
||||
/// </summary>
|
||||
public string ident;
|
||||
/// <summary>
|
||||
/// alias x poterlo riconoscere/riferire in agent
|
||||
/// </summary>
|
||||
public string alias;
|
||||
/// <summary>
|
||||
/// fonte dati
|
||||
/// </summary>
|
||||
public fonteDati fonte;
|
||||
/// <summary>
|
||||
/// Elenco riferimento dati x recupero (es posizioni memoria separate da #)
|
||||
/// </summary>
|
||||
public List<DataRefItem<string, string>> dataRefList;
|
||||
/// <summary>
|
||||
/// classe elemento base in cui salvare i dati di conf x recupero dati adapters
|
||||
/// </summary>
|
||||
public class element
|
||||
{
|
||||
/// <summary>
|
||||
/// identificativo univoco x classe di elemento
|
||||
/// </summary>
|
||||
public string ident;
|
||||
/// <summary>
|
||||
/// alias x poterlo riconoscere/riferire in agent
|
||||
/// </summary>
|
||||
public string alias;
|
||||
/// <summary>
|
||||
/// fonte dati
|
||||
/// </summary>
|
||||
public fonteDati fonte;
|
||||
/// <summary>
|
||||
/// Elenco riferimento dati x recupero (es posizioni memoria separate da #)
|
||||
/// </summary>
|
||||
public List<DataRefItem<string, string>> dataRefList;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// init empty
|
||||
/// </summary>
|
||||
public element()
|
||||
{
|
||||
ident = "";
|
||||
alias = "";
|
||||
fonte = fonteDati.NoData;
|
||||
dataRefList = new List<DataRefItem<string, string>>();
|
||||
}
|
||||
/// <summary>
|
||||
/// init element con dati
|
||||
/// </summary>
|
||||
/// <param name="Idx">Identificativo univoco</param>
|
||||
/// <param name="Alias">Alias/descrizione</param>
|
||||
/// <param name="FonteD">Tipo fonte dati</param>
|
||||
/// <param name="DataRef">Parametri x recupero dati in forma dictionary</param>
|
||||
public element(string Idx, string Alias, fonteDati FonteD, List<DataRefItem<string, string>> DataRef)
|
||||
{
|
||||
ident = Idx;
|
||||
alias = Alias;
|
||||
fonte = FonteD;
|
||||
dataRefList = DataRef;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// init empty
|
||||
/// </summary>
|
||||
public element()
|
||||
{
|
||||
ident = "";
|
||||
alias = "";
|
||||
fonte = fonteDati.NoData;
|
||||
dataRefList = new List<DataRefItem<string, string>>();
|
||||
}
|
||||
/// <summary>
|
||||
/// init element con dati
|
||||
/// </summary>
|
||||
/// <param name="Idx">Identificativo univoco</param>
|
||||
/// <param name="Alias">Alias/descrizione</param>
|
||||
/// <param name="FonteD">Tipo fonte dati</param>
|
||||
/// <param name="DataRef">Parametri x recupero dati in forma dictionary</param>
|
||||
public element(string Idx, string Alias, fonteDati FonteD, List<DataRefItem<string, string>> DataRef)
|
||||
{
|
||||
ident = Idx;
|
||||
alias = Alias;
|
||||
fonte = FonteD;
|
||||
dataRefList = DataRef;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -16,6 +16,17 @@
|
||||
</dataRef>
|
||||
</dataRefList>
|
||||
</element>
|
||||
<element>
|
||||
<ident>VacPump_02</ident>
|
||||
<alias>Pompa 2</alias>
|
||||
<fonte>Random</fonte>
|
||||
<dataRefList>
|
||||
<dataRef>
|
||||
<Key>VacPump_02_Status</Key>
|
||||
<Value>0#7</Value>
|
||||
</dataRef>
|
||||
</dataRefList>
|
||||
</element>
|
||||
</VacuumPump>
|
||||
<VacuumAct>
|
||||
<element>
|
||||
@@ -53,6 +64,17 @@
|
||||
</dataRef>
|
||||
</dataRefList>
|
||||
</element>
|
||||
<element>
|
||||
<ident>Lubro_02</ident>
|
||||
<alias>Lubrorefrigerante 2</alias>
|
||||
<fonte>Random</fonte>
|
||||
<dataRefList>
|
||||
<dataRef>
|
||||
<Key>Lubro_02_Num</Key>
|
||||
<Value>0#15</Value>
|
||||
</dataRef>
|
||||
</dataRefList>
|
||||
</element>
|
||||
</Lubro>
|
||||
<Cooler>
|
||||
<element>
|
||||
|
||||
@@ -40,6 +40,10 @@ namespace MTC_Sim
|
||||
{ }
|
||||
return answ;
|
||||
}
|
||||
set
|
||||
{
|
||||
nVacPump.Text = value.ToString();
|
||||
}
|
||||
}
|
||||
protected int numVacAct
|
||||
{
|
||||
@@ -54,6 +58,10 @@ namespace MTC_Sim
|
||||
{ }
|
||||
return answ;
|
||||
}
|
||||
set
|
||||
{
|
||||
nVacAct.Text = value.ToString();
|
||||
}
|
||||
}
|
||||
protected int numLubro
|
||||
{
|
||||
@@ -68,6 +76,10 @@ namespace MTC_Sim
|
||||
{ }
|
||||
return answ;
|
||||
}
|
||||
set
|
||||
{
|
||||
nLubro.Text = value.ToString();
|
||||
}
|
||||
}
|
||||
protected int numCooler
|
||||
{
|
||||
@@ -82,6 +94,10 @@ namespace MTC_Sim
|
||||
{ }
|
||||
return answ;
|
||||
}
|
||||
set
|
||||
{
|
||||
nCooler.Text = value.ToString();
|
||||
}
|
||||
}
|
||||
protected int numPress
|
||||
{
|
||||
@@ -96,6 +112,10 @@ namespace MTC_Sim
|
||||
{ }
|
||||
return answ;
|
||||
}
|
||||
set
|
||||
{
|
||||
nPress.Text = value.ToString();
|
||||
}
|
||||
}
|
||||
protected int numTemp
|
||||
{
|
||||
@@ -110,6 +130,10 @@ namespace MTC_Sim
|
||||
{ }
|
||||
return answ;
|
||||
}
|
||||
set
|
||||
{
|
||||
nTempe.Text = value.ToString();
|
||||
}
|
||||
}
|
||||
protected int numPath
|
||||
{
|
||||
@@ -124,6 +148,10 @@ namespace MTC_Sim
|
||||
{ }
|
||||
return answ;
|
||||
}
|
||||
set
|
||||
{
|
||||
nPath.Text = value.ToString();
|
||||
}
|
||||
}
|
||||
protected int numUnOp
|
||||
{
|
||||
@@ -138,6 +166,10 @@ namespace MTC_Sim
|
||||
{ }
|
||||
return answ;
|
||||
}
|
||||
set
|
||||
{
|
||||
nUnOp.Text = value.ToString();
|
||||
}
|
||||
}
|
||||
protected int numAxis
|
||||
{
|
||||
@@ -152,6 +184,10 @@ namespace MTC_Sim
|
||||
{ }
|
||||
return answ;
|
||||
}
|
||||
set
|
||||
{
|
||||
nAssi.Text = value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private void btnCreateFile_Click(object sender, EventArgs e)
|
||||
@@ -370,6 +406,15 @@ namespace MTC_Sim
|
||||
AdapterConf c2 = AdapterConf.Deserialize(filePath);
|
||||
|
||||
txtAdapter.Text = c2.NomeAdapt;
|
||||
numVacPump = c2.nVacuumPump;
|
||||
numVacAct = c2.nVacuumAct;
|
||||
numLubro = c2.nLubro;
|
||||
numCooler = c2.nCooler;
|
||||
numPress = c2.nPress;
|
||||
numTemp = c2.nTemp;
|
||||
numPath = c2.nPath;
|
||||
numUnOp = c2.nUnOp;
|
||||
numAxis = c2.nAxis;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user