From e4f0ffbaeef8b8f574b71a10d22e49e39d4dc50b Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Sat, 23 Nov 2019 16:17:01 +0100 Subject: [PATCH] Aggiunto oggetti x salvare dataItems da MTC --- MP-ADM/Web.config | 4 + MP-IO/Controllers/IOBController.cs | 14 +- MP-IO/Web.config | 430 +++++++++++++++-------------- MP-LAND/Web.config | 4 + MP-MON/Web.config | 4 + MP-Site/Web.config | 4 + MP-TAB/Web.config | 4 + MapoDb/AlarmsArchive.cs | 19 +- MapoDb/FluxArchive.cs | 14 +- MapoDb/MapoDb.csproj | 1 + MapoDb/MtcDataModelArchive.cs | 57 ++++ MapoDb/packages.config | 1 + MapoSDK/Enums.cs | 6 + MapoSDK/Objects.cs | 109 +++++++- 14 files changed, 445 insertions(+), 226 deletions(-) create mode 100644 MapoDb/MtcDataModelArchive.cs diff --git a/MP-ADM/Web.config b/MP-ADM/Web.config index bbace0f0..041a7094 100644 --- a/MP-ADM/Web.config +++ b/MP-ADM/Web.config @@ -325,6 +325,10 @@ + + + + diff --git a/MP-IO/Controllers/IOBController.cs b/MP-IO/Controllers/IOBController.cs index 144aec8b..42697b31 100644 --- a/MP-IO/Controllers/IOBController.cs +++ b/MP-IO/Controllers/IOBController.cs @@ -413,24 +413,22 @@ namespace MP_IO.Controllers // Rest System.Web.HttpContext.Current.Request.InputStream.Position = 0; - -#if false // procedo a deserializzare in blocco l'oggetto... - plcMemMap currMemMap = null; + List dataItems = null; try { // deserializzo. - currMemMap = JsonConvert.DeserializeObject(content); + dataItems = JsonConvert.DeserializeObject>(content); // se != null --> salvo! - if (currMemMap != null) + if (dataItems != null) { - DataLayer.setIobMemMap(id, currMemMap); + // chiamo metodo update direttamente! + MtcDataModelArchive.man.saveMachineDataItems(id, dataItems); answ = "OK"; } } catch - { } -#endif + { } } return answ; } diff --git a/MP-IO/Web.config b/MP-IO/Web.config index ddb66fdd..67ce31a4 100644 --- a/MP-IO/Web.config +++ b/MP-IO/Web.config @@ -18,6 +18,8 @@ + + @@ -43,218 +45,218 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -307,6 +309,10 @@ + + + + diff --git a/MP-LAND/Web.config b/MP-LAND/Web.config index b63064ba..9619a59c 100644 --- a/MP-LAND/Web.config +++ b/MP-LAND/Web.config @@ -326,6 +326,10 @@ + + + + diff --git a/MP-MON/Web.config b/MP-MON/Web.config index 22d7674f..122cc939 100644 --- a/MP-MON/Web.config +++ b/MP-MON/Web.config @@ -317,6 +317,10 @@ + + + + diff --git a/MP-Site/Web.config b/MP-Site/Web.config index d0184caa..5fe00903 100644 --- a/MP-Site/Web.config +++ b/MP-Site/Web.config @@ -334,6 +334,10 @@ + + + + diff --git a/MP-TAB/Web.config b/MP-TAB/Web.config index 52fddae0..2c1898b4 100644 --- a/MP-TAB/Web.config +++ b/MP-TAB/Web.config @@ -325,6 +325,10 @@ + + + + diff --git a/MapoDb/AlarmsArchive.cs b/MapoDb/AlarmsArchive.cs index 2e2fae5a..d3c5ecf5 100644 --- a/MapoDb/AlarmsArchive.cs +++ b/MapoDb/AlarmsArchive.cs @@ -1,5 +1,6 @@ using MapoSDK; using MongoDB.Driver; +using SteamWare; using System; using System.Collections.Generic; @@ -10,15 +11,27 @@ namespace MapoDb /// public class AlarmsArchive { +#if false string mdbConnString = "mongodb://W2019-MONGODB:27017"; //string mdbConnString = "mongodb://localhost:27017"; - MongoClient client; + MongoClient client; +#endif + /// + /// Database corrente MongoDB + /// IMongoDatabase database; + /// + /// Classe gestione archivio allarmi + /// public AlarmsArchive() { +#if false // rifare avvio con lettura da web.config... client = new MongoClient(mdbConnString); - database = client.GetDatabase("MAPO"); + database = client.GetDatabase("MAPO"); +#endif + + database = memLayer.ML.getMongoDatabase("MAPO"); } /// @@ -32,7 +45,7 @@ namespace MapoDb /// /// numero di minuti precedenti di dati FluxLog da includere /// - public int createIncident(string idxMacchina, List elencoAllarmi, int lastMinutes) + public int createAlarmEvent(string idxMacchina, List elencoAllarmi, int lastMinutes) { int answ = 0; string currDateStr = ""; diff --git a/MapoDb/FluxArchive.cs b/MapoDb/FluxArchive.cs index 5e91d4ba..b81bc853 100644 --- a/MapoDb/FluxArchive.cs +++ b/MapoDb/FluxArchive.cs @@ -1,5 +1,6 @@ using MapoSDK; using MongoDB.Driver; +using SteamWare; using System; using System.Collections.Generic; using System.Diagnostics; @@ -44,16 +45,27 @@ namespace MapoDb /// public class FluxArchive { +#if false string mdbConnString = "mongodb://W2019-MONGODB:27017"; //string mdbConnString = "mongodb://localhost:27017"; - MongoClient client; + MongoClient client; +#endif + /// + /// Database corrente MongoDB + /// IMongoDatabase database; + /// + /// Classe gestione archivio allarmi + /// public FluxArchive() { +#if false // rifare avvio con lettura da web.config... client = new MongoClient(mdbConnString); database = client.GetDatabase("MAPO"); +#endif + database = memLayer.ML.getMongoDatabase("MAPO"); } public static FluxArchive man = new FluxArchive(); /// diff --git a/MapoDb/MapoDb.csproj b/MapoDb/MapoDb.csproj index c1fb0fa8..49aa14d8 100644 --- a/MapoDb/MapoDb.csproj +++ b/MapoDb/MapoDb.csproj @@ -159,6 +159,7 @@ + True diff --git a/MapoDb/MtcDataModelArchive.cs b/MapoDb/MtcDataModelArchive.cs new file mode 100644 index 00000000..ced619d9 --- /dev/null +++ b/MapoDb/MtcDataModelArchive.cs @@ -0,0 +1,57 @@ +using MapoSDK; +using MongoDB.Driver; +using SteamWare; +using System.Collections.Generic; + +namespace MapoDb +{ + /// + /// Classe gestione archivio modelli MTC dei vari IOB + /// + public class MtcDataModelArchive + { + /// + /// Database corrente MongoDB + /// + IMongoDatabase database; + /// + /// Dizionario conf macchine + /// + public Dictionary> machineDataItems = new Dictionary>(); + + /// + /// Classe gestione archivio allarmi + /// + public MtcDataModelArchive() + { + database = memLayer.ML.getMongoDatabase("MAPO"); + } + /// + /// Singleton gestione istanza AlarmsManager + /// + public static MtcDataModelArchive man = new MtcDataModelArchive(); + /// + /// Salva il DataModel XML della macchina indicata + /// + /// + /// + /// + public bool saveMachineDataItems(string idxMacchina, List dataItems) + { + bool answ = false; + try + { + var collMtcSetup = database.GetCollection("MtcSetup"); + // compongo filtro ricerca e metodo update + var filter = Builders.Filter.Eq(u => u.idxMacchina, idxMacchina); + var update = Builders.Update.Set(u => u.dataItems, dataItems); + // chiamo update: cerco riga, se c'è aggiorno sennò creo + collMtcSetup.UpdateOne(filter, update); + answ = true; + } + catch + { } + return answ; + } + } +} diff --git a/MapoDb/packages.config b/MapoDb/packages.config index f0cb93ca..20a39ad6 100644 --- a/MapoDb/packages.config +++ b/MapoDb/packages.config @@ -12,6 +12,7 @@ + \ No newline at end of file diff --git a/MapoSDK/Enums.cs b/MapoSDK/Enums.cs index 1c49c2f6..08005c68 100644 --- a/MapoSDK/Enums.cs +++ b/MapoSDK/Enums.cs @@ -180,6 +180,12 @@ /// delete } + public enum DataItemCategory + { + CONDITION = 0, + EVENT = 1, + SAMPLE = 2 + } public enum tipoBarcode { diff --git a/MapoSDK/Objects.cs b/MapoSDK/Objects.cs index 0c4a1f2d..3eb75d54 100644 --- a/MapoSDK/Objects.cs +++ b/MapoSDK/Objects.cs @@ -2,6 +2,7 @@ using Newtonsoft.Json.Converters; using System; using System.Collections.Generic; +using System.Xml.Serialization; namespace MapoSDK { @@ -322,6 +323,8 @@ namespace MapoSDK } + #region gestione dati FluxLog + /// /// Classe oggetto statistiche sui dati /// @@ -362,7 +365,6 @@ namespace MapoSDK /// public string value { get; set; } = ""; } - /// /// Raccolta dati di storici sintetici per Macchina e Variabile /// @@ -423,7 +425,6 @@ namespace MapoSDK /// public List samples { get; set; } = null; } - /// /// Classe x inviare messaggi di tipo esecuzione di una generica esecuzione /// @@ -439,6 +440,11 @@ namespace MapoSDK /// public string message { get; set; } = ""; } + + #endregion + + #region gestione ALARMS / CONDITIONS + /// /// Definizione classe evento allarme /// @@ -529,6 +535,105 @@ namespace MapoSDK #endregion + #region gestione oggetti conf MNTConnect + + /// + /// Configurazione delle macchine MTC + /// + public class MtcSetup + { + /// + /// IdxMacchina cui ci riferiamo + /// + public string idxMacchina { get; set; } = ""; + /// + /// Setup della macchina + /// + public List dataItems { get; set; } + } + + public class MTConnDataItem + { + public MTConnDataItem() + { } + + [XmlAttribute("significantDigits")] + public int SignificantDigits { get; set; } + [XmlAttribute("respresentation")] + public string Representation { get; set; } + [XmlAttribute("sampleRate")] + public double SampleRate { get; set; } + [XmlAttribute("units")] + public string Units { get; set; } + [XmlAttribute("statistic")] + public string Statistic { get; set; } + [XmlAttribute("subType")] + public string SubType { get; set; } + [XmlAttribute("nativeUnits")] + public string NativeUnits { get; set; } + [XmlAttribute("nativeScale")] + public string NativeScale { get; set; } + [XmlAttribute("name")] + public string Name { get; set; } + [XmlAttribute("coordinateSystem")] + public string CoordinateSystem { get; set; } + [XmlAttribute("type")] + public string Type { get; set; } + [XmlAttribute("id")] + public string Id { get; set; } + [XmlAttribute("category")] + public DataItemCategory Category { get; set; } + [XmlIgnore] + public string TypePath { get; set; } + [XmlIgnore] + public string XPath { get; set; } + [XmlElement("Source")] + public Source Source { get; set; } + [XmlElement("Constraints")] + public Constraints Constraints { get; set; } + } + + public class Source + { + public Source() + { } + + [XmlAttribute("componentId")] + public string ComponentID { get; set; } + [XmlAttribute("dataItemId")] + public string DataItemID { get; set; } + [XmlText] + public string CDATA { get; set; } + } + + public class Constraints + { + [XmlElement("Filter")] + public Filter Filter; + + public Constraints() + { } + + [XmlElement("Maximum")] + public string Maximum { get; set; } + [XmlElement("Minimum")] + public string Minimum { get; set; } + [XmlElement("Value")] + public string Value { get; set; } + } + public class Filter + { + public Filter() + { } + + [XmlAttribute("type")] + public string Type { get; set; } + } + + #endregion + + #endregion + #if false ///