From 52930ae0d5b7b4f2be36be2fa3174a5bd67ecb27 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Wed, 20 Jul 2016 09:04:03 +0200 Subject: [PATCH] completata riscrittura da bin a plain text (.mtc) --- MTC_Sim/MTC_Sim/AdapterConf/PersistData.bin | Bin 162 -> 0 bytes MTC_Sim/MTC_Sim/AdapterConf/PersistData.mtc | 0 MTC_Sim/MTC_Sim/App.config | 2 +- MTC_Sim/MTC_Sim/MTC-Adapter.csproj | 2 +- MTC_Sim/MTC_Sim/MainForm.cs | 7 ++-- MTC_Sim/MTC_Sim/utils.cs | 37 ++++++++++++++++++-- 6 files changed, 40 insertions(+), 8 deletions(-) delete mode 100644 MTC_Sim/MTC_Sim/AdapterConf/PersistData.bin create mode 100644 MTC_Sim/MTC_Sim/AdapterConf/PersistData.mtc diff --git a/MTC_Sim/MTC_Sim/AdapterConf/PersistData.bin b/MTC_Sim/MTC_Sim/AdapterConf/PersistData.bin deleted file mode 100644 index 6bac0fa7aacd677a6e1578b54e81e8c343894552..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 162 zcmY+*s|tWH6adhHV$}~Z+{e6gQP?Ng7skSZ8Z`L%f?O5rfzudcy6G%?1dO5VN7&X} zqXTFkol=_1l3VD32eD!SS@h6*DzQ!rMJ?T32)rM?@TiBsLxOtve}o((J0g+`IP)xq diff --git a/MTC_Sim/MTC_Sim/AdapterConf/PersistData.mtc b/MTC_Sim/MTC_Sim/AdapterConf/PersistData.mtc new file mode 100644 index 0000000..e69de29 diff --git a/MTC_Sim/MTC_Sim/App.config b/MTC_Sim/MTC_Sim/App.config index 2e339c3..8e648c4 100644 --- a/MTC_Sim/MTC_Sim/App.config +++ b/MTC_Sim/MTC_Sim/App.config @@ -39,7 +39,7 @@ - + diff --git a/MTC_Sim/MTC_Sim/MTC-Adapter.csproj b/MTC_Sim/MTC_Sim/MTC-Adapter.csproj index 094448b..0ce4dfb 100644 --- a/MTC_Sim/MTC_Sim/MTC-Adapter.csproj +++ b/MTC_Sim/MTC_Sim/MTC-Adapter.csproj @@ -175,7 +175,7 @@ App.config - + PreserveNewest diff --git a/MTC_Sim/MTC_Sim/MainForm.cs b/MTC_Sim/MTC_Sim/MainForm.cs index 544665f..4db296a 100644 --- a/MTC_Sim/MTC_Sim/MainForm.cs +++ b/MTC_Sim/MTC_Sim/MainForm.cs @@ -393,7 +393,7 @@ namespace MTC_Adapter { get { - return string.Format(@"{0}\{1:yyyy}\{1:yyyy-MM-dd}.bin", utils.CRS("XmlHistFilePath"), DateTime.Now); + return string.Format(@"{0}\{1:yyyy}\{1:yyyy-MM-dd}.mtc", utils.CRS("XmlHistFilePath"), DateTime.Now); } } /// @@ -953,7 +953,7 @@ namespace MTC_Adapter /// public void savePersistLayer(string filePath) { - utils.Write(agObj.persistenceLayer, filePath); + utils.WritePlain(agObj.persistenceLayer, filePath); } /// /// Carica da file l'oggetto di persistenza dati @@ -963,7 +963,8 @@ namespace MTC_Adapter { // inizializzo prima di leggere... agObj.persistenceLayer = new Dictionary(); - agObj.persistenceLayer = utils.Read(filePath); + agObj.persistenceLayer = utils.ReadPlain(filePath); + //agObj.persistenceLayer = utils.ReadBin(filePath); } #endregion diff --git a/MTC_Sim/MTC_Sim/utils.cs b/MTC_Sim/MTC_Sim/utils.cs index f24c104..928bfdc 100644 --- a/MTC_Sim/MTC_Sim/utils.cs +++ b/MTC_Sim/MTC_Sim/utils.cs @@ -209,7 +209,7 @@ namespace MTC_Adapter /// /// /// - public static void Write(Dictionary dictionary, string file) + public static void WriteBin(Dictionary dictionary, string file) { using (FileStream fs = File.OpenWrite(file)) using (BinaryWriter writer = new BinaryWriter(fs)) @@ -229,11 +229,11 @@ namespace MTC_Adapter /// /// /// - public static Dictionary Read(string file) + public static Dictionary ReadBin(string file) { var result = new Dictionary(); // verifico file esista... - if(!File.Exists(file)) + if (!File.Exists(file)) { FileStream fs = File.Create(file); fs.Close(); @@ -259,6 +259,37 @@ namespace MTC_Adapter } return result; } + + /// + /// Scrittura dictionary su file + /// + /// + /// + public static void WritePlain(Dictionary dictionary, string file) + { + string[] lines = dictionary.OrderBy(i => i.Key).Select(kvp => kvp.Key + ":" + kvp.Value).ToArray(); + File.WriteAllLines(file, lines); + } + /// + /// Lettura dictionary da file + /// + /// + /// + public static Dictionary ReadPlain(string file) + { + var result = new Dictionary(); + // verifico file esista... + if (!File.Exists(file)) + { + FileStream fs = File.Create(file); + fs.Close(); + } + + string[] lines = File.ReadAllLines(file); + result = lines.Select(l => l.Split(':')).ToDictionary(a => a[0], a => a[1]); + + return result; + } } /// /// Oggetto timing x archiviazione dati perfomances