inizio ad aggiungere metodi x persistenza layer dati produzione...
This commit is contained in:
@@ -185,7 +185,7 @@ namespace MTC_Adapter
|
||||
|
||||
|
||||
// salvo se necessario!
|
||||
if (needSave) parentForm.persistXmlData();
|
||||
if (needSave) parentForm.persistData();
|
||||
// -------------------------------------------
|
||||
|
||||
|
||||
|
||||
@@ -891,7 +891,7 @@ namespace MTC_Adapter
|
||||
needSave = procLubro(needSave);
|
||||
|
||||
// salvo se necessario!
|
||||
if (needSave) parentForm.persistXmlData();
|
||||
if (needSave) parentForm.persistData();
|
||||
// -------------------------------------------
|
||||
|
||||
}
|
||||
|
||||
@@ -714,8 +714,7 @@ namespace MTC_Adapter
|
||||
public allarme[] elencoAllarmi;
|
||||
|
||||
public Dictionary<string, string> elencoSubMode;
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Prima word di strobe da array flag completo
|
||||
/// </summary>
|
||||
@@ -1251,8 +1250,8 @@ namespace MTC_Adapter
|
||||
contOreMaccLav = currAdpConf.ContOreMaccLav;
|
||||
contGiriElettrom = new uint[currAdpConf.nUnOp];
|
||||
istGiriElettrom = new uint[currAdpConf.nUnOp];
|
||||
currNumCambiUt= new uint[currAdpConf.nUnOp];
|
||||
istNumCambiUt= new uint[currAdpConf.nUnOp];
|
||||
currNumCambiUt = new uint[currAdpConf.nUnOp];
|
||||
istNumCambiUt = new uint[currAdpConf.nUnOp];
|
||||
for (int i = 0; i < currAdpConf.nUnOp; i++)
|
||||
{
|
||||
// leggo tutti i dati...
|
||||
@@ -2399,5 +2398,54 @@ namespace MTC_Adapter
|
||||
|
||||
#endregion
|
||||
|
||||
#region layer persistenza dati
|
||||
|
||||
/// <summary>
|
||||
/// Dizionario di persistenza per i valori da salvare da/su file
|
||||
/// </summary>
|
||||
public Dictionary<string, string> persistenceLayer;
|
||||
|
||||
/// <summary>
|
||||
/// Aggiorna un valore del dizionario in INCREMENTO e lo restituisce
|
||||
/// </summary>
|
||||
/// <param name="i"></param>
|
||||
/// <param name="delta"></param>
|
||||
/// <param name="searchString"></param>
|
||||
/// <returns>Nuovo valore incrementato</returns>
|
||||
private uint updateValUIntByIncr(int i, uint delta, string searchString)
|
||||
{
|
||||
// stringa da cercare..
|
||||
string keyVal = string.Format(searchString, i + 1);
|
||||
// recupero valore precedente...
|
||||
uint contAct = Convert.ToUInt32(persistenceLayer[keyVal]);
|
||||
// nuovo valore...
|
||||
contAct += delta;
|
||||
// salvo in ram!
|
||||
persistenceLayer[keyVal] = contAct.ToString();
|
||||
// rendo il valore!
|
||||
return contAct;
|
||||
}
|
||||
/// <summary>
|
||||
/// Aggiorna un valore del dizionario in INCREMENTO e lo restituisce
|
||||
/// </summary>
|
||||
/// <param name="i"></param>
|
||||
/// <param name="delta"></param>
|
||||
/// <param name="searchString"></param>
|
||||
/// <returns>Nuovo valore incrementato</returns>
|
||||
private double updateValDoubleByIncr(int i, double delta, string searchString)
|
||||
{
|
||||
// stringa da cercare..
|
||||
string keyVal = string.Format(searchString, i + 1);
|
||||
// recupero valore precedente...
|
||||
double contAct = Convert.ToDouble(persistenceLayer[keyVal]);
|
||||
// nuovo valore...
|
||||
contAct += delta;
|
||||
// salvo in ram!
|
||||
persistenceLayer[keyVal] = contAct.ToString();
|
||||
// rendo il valore!
|
||||
return contAct;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
+276
-1025
File diff suppressed because it is too large
Load Diff
@@ -39,6 +39,7 @@
|
||||
|
||||
<add key="autoLoadConf" value="false" />
|
||||
<add key="defaultConfFile" value="CMS_FANUC.xml" />
|
||||
<add key="defaultPersLayerFile" value="PersistData.txt" />
|
||||
<add key="defaultEsaFile" value="EsaKvara.ini" />
|
||||
<add key="autoStartOnLoad" value="true" />
|
||||
<add key="openDumpOnStart" value="true" />
|
||||
|
||||
@@ -175,6 +175,7 @@
|
||||
<None Include="App.SCM.config">
|
||||
<DependentUpon>App.config</DependentUpon>
|
||||
</None>
|
||||
<Content Include="PersistData.txt" />
|
||||
<None Include="Resources\SCM\app.msg" />
|
||||
<None Include="Resources\SCM\convertScmAlarm.ps1" />
|
||||
<None Include="Resources\SCM\KvaraDb.doc" />
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 148 KiB After Width: | Height: | Size: 145 KiB |
@@ -110,6 +110,7 @@ namespace MTC_Adapter
|
||||
if (utils.CRB("autoLoadConf"))
|
||||
{
|
||||
loadXmlFile(defConfFilePath);
|
||||
loadPersistLayer(defPersLayerFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -129,6 +130,13 @@ namespace MTC_Adapter
|
||||
return string.Format(@"{0}\{1}\{2}", Application.StartupPath, utils.CRS("adapterConfPath"), utils.CRS("defaultConfFile"));
|
||||
}
|
||||
}
|
||||
protected string defPersLayerFile
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.Format(@"{0}\{1}\{2}", Application.StartupPath, utils.CRS("adapterConfPath"), utils.CRS("defaultPersLayerFile"));
|
||||
}
|
||||
}
|
||||
protected string defIconFilePath
|
||||
{
|
||||
get
|
||||
@@ -333,7 +341,7 @@ namespace MTC_Adapter
|
||||
|
||||
// check esecuzione SlowTask
|
||||
checkSlowTask();
|
||||
|
||||
|
||||
// check esecuzione AlarmSync
|
||||
checkAlarmSync();
|
||||
|
||||
@@ -371,7 +379,7 @@ namespace MTC_Adapter
|
||||
refreshCodeMST();
|
||||
|
||||
// effettua salvataggio del file di conf con i valori ATTUALI dei parametri ove applicabile/aggiornati (es ore utilizzo, KM assi percorsi...) --> sia file corrente che file "history"
|
||||
persistXmlData();
|
||||
persistData();
|
||||
}
|
||||
}
|
||||
protected string histFilePath
|
||||
@@ -381,16 +389,25 @@ namespace MTC_Adapter
|
||||
return string.Format(@"{0}\{1:yyyy}\{1:yyyy-MM-dd}.xml", utils.CRS("XmlHistFilePath"), DateTime.Now);
|
||||
}
|
||||
}
|
||||
protected string histPersLayerFile
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.Format(@"{0}\{1:yyyy}\{1:yyyy-MM-dd}.csv", utils.CRS("XmlHistFilePath"), DateTime.Now);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// salva i valori attuali del file di conf sia in file corrente che in cartella valori storici
|
||||
/// </summary>
|
||||
public void persistXmlData()
|
||||
public void persistData()
|
||||
{
|
||||
// salvo il file "corrente"
|
||||
saveXmlFile(defConfFilePath);
|
||||
//// salvo il file "corrente"
|
||||
//saveXmlFile(defConfFilePath);
|
||||
//// salvo anche file in cartella storicizzazione in formato XML
|
||||
//saveXmlFile(histFilePath);
|
||||
|
||||
// salvo anche file in cartella storicizzazione
|
||||
saveXmlFile(histFilePath);
|
||||
savePersistLayer(defPersLayerFile);
|
||||
savePersistLayer(histPersLayerFile);
|
||||
}
|
||||
|
||||
private void checkNormTask()
|
||||
@@ -901,7 +918,7 @@ namespace MTC_Adapter
|
||||
// carico file XML in web browser...
|
||||
wbXmlConf.DocumentText = AdapterConf.rawXml(XmlConfFile);
|
||||
displayTaskAndWait("XML loaded");
|
||||
|
||||
|
||||
// avvio macchina con adapter specificato...
|
||||
if (utils.CRB("autoStartOnLoad"))
|
||||
{
|
||||
@@ -919,6 +936,22 @@ namespace MTC_Adapter
|
||||
{
|
||||
AdapterConf.Serialize(XmlConfFile, agObj.currAdpConf);
|
||||
}
|
||||
/// <summary>
|
||||
/// Salva su file l'oggetto di persistenza dati
|
||||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
public void savePersistLayer(string filePath)
|
||||
{
|
||||
utils.Write(agObj.persistenceLayer, filePath);
|
||||
}
|
||||
/// <summary>
|
||||
/// Carica da file l'oggetto di persistenza dati
|
||||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
public void loadPersistLayer(string filePath)
|
||||
{
|
||||
agObj.persistenceLayer = utils.Read(filePath);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -202,6 +203,50 @@ namespace MTC_Adapter
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scrittura dictionary su file
|
||||
/// </summary>
|
||||
/// <param name="dictionary"></param>
|
||||
/// <param name="file"></param>
|
||||
public static void Write(Dictionary<string, string> dictionary, string file)
|
||||
{
|
||||
using (FileStream fs = File.OpenWrite(file))
|
||||
using (BinaryWriter writer = new BinaryWriter(fs))
|
||||
{
|
||||
// Put count.
|
||||
writer.Write(dictionary.Count);
|
||||
// Write pairs.
|
||||
foreach (var pair in dictionary)
|
||||
{
|
||||
writer.Write(pair.Key);
|
||||
writer.Write(pair.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Lettura dictionary da file
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <returns></returns>
|
||||
public static Dictionary<string, string> Read(string file)
|
||||
{
|
||||
var result = new Dictionary<string, string>();
|
||||
using (FileStream fs = File.OpenRead(file))
|
||||
using (BinaryReader reader = new BinaryReader(fs))
|
||||
{
|
||||
// Get count.
|
||||
int count = reader.ReadInt32();
|
||||
// Read in all pairs.
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
string key = reader.ReadString();
|
||||
string value = reader.ReadString();
|
||||
result[key] = value;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Oggetto timing x archiviazione dati perfomances
|
||||
|
||||
Reference in New Issue
Block a user