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 db25d901..a9a9103d 100644
--- a/MP-IO/Controllers/IOBController.cs
+++ b/MP-IO/Controllers/IOBController.cs
@@ -346,7 +346,7 @@ namespace MP_IO.Controllers
}
///
/// Processa una chiamata POST per l'invio di un array Json di oggetti plcMemConf
- /// PUT: IOB/flogJson/SIMUL_03
+ /// PUT: IOB/saveConf/SIMUL_03
///
/// ID dell'IOB
///
@@ -388,6 +388,51 @@ namespace MP_IO.Controllers
return answ;
}
///
+ /// Processa una chiamata POST per l'invio di un array Json di oggetti di conf DataItems (es per MTC)
+ /// PUT: IOB/saveDataItems/SIMUL_03
+ ///
+ /// ID dell'IOB
+ ///
+ [HttpPost]
+ public string saveDataItems(string id)
+ {
+ string answ = "";
+ if (string.IsNullOrWhiteSpace(id))
+ {
+ answ = "Missing IOB";
+ }
+ else
+ {
+ // questa classe è derivata da Controller.Response... x cui recupero lo stream in altro modo...
+ string content = "";
+ System.Web.HttpContext.Current.Request.InputStream.Position = 0;
+ using (var reader = new StreamReader(Request.InputStream, System.Text.Encoding.UTF8, true, 4096, true))
+ {
+ content = reader.ReadToEnd();
+ }
+ // Rest
+ System.Web.HttpContext.Current.Request.InputStream.Position = 0;
+
+ // procedo a deserializzare in blocco l'oggetto...
+ List dataItems = null;
+ try
+ {
+ // deserializzo.
+ dataItems = JsonConvert.DeserializeObject>(content);
+ // se != null --> salvo!
+ if (dataItems != null)
+ {
+ // chiamo metodo update direttamente!
+ MtcDataModelArchive.man.saveMachineDataItems(id, dataItems);
+ answ = "OK";
+ }
+ }
+ catch
+ { }
+ }
+ return answ;
+ }
+ ///
/// restituisce elenco parametri correnti come una List Json di oggetti objItem
/// GET: IOB/getObjItems/SIMUL_03
///
diff --git a/MP-I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--- 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
new file mode 100644
index 00000000..d3c5ecf5
--- /dev/null
+++ b/MapoDb/AlarmsArchive.cs
@@ -0,0 +1,87 @@
+using MapoSDK;
+using MongoDB.Driver;
+using SteamWare;
+using System;
+using System.Collections.Generic;
+
+namespace MapoDb
+{
+ ///
+ /// Classe gestione ALLARMI coem eventi speciali (documenti registrati su MongoDb)
+ ///
+ public class AlarmsArchive
+ {
+#if false
+ string mdbConnString = "mongodb://W2019-MONGODB:27017";
+ //string mdbConnString = "mongodb://localhost:27017";
+ 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");
+#endif
+
+ database = memLayer.ML.getMongoDatabase("MAPO");
+
+ }
+ ///
+ /// Singleton gestione istanza AlarmsManager
+ ///
+ public static AlarmsArchive man = new AlarmsArchive();
+ ///
+ /// Crea una registrazione incidente su MongoDB
+ ///
+ ///
+ ///
+ /// numero di minuti precedenti di dati FluxLog da includere
+ ///
+ public int createAlarmEvent(string idxMacchina, List elencoAllarmi, int lastMinutes)
+ {
+ int answ = 0;
+ string currDateStr = "";
+ int startYMD = 0;
+ DateTime adesso = DateTime.Now;
+ int anno = adesso.Year;
+ currDateStr = adesso.ToString("yyyyMMdd");
+ int.TryParse(currDateStr, out startYMD);
+ // in primis recupero contatore allarmi correnti, lo incremento salvandolo e genero nuovo documento...
+ var collAlarmStats = database.GetCollection("AlarmStats");
+ var builderAlarmStat = Builders.Filter;
+ var filtThisYear = builderAlarmStat.Eq(u => u.year, anno);
+
+ var datiCorrenti = collAlarmStats.Find(filtThisYear);
+ var collAlarmEvents = database.GetCollection("AlarmEvents");
+
+ List lastFluxLog = new List();
+ DS_applicazione.FluxLogDataTable tabDati = DataLayer.obj.taFL.getFiltOrd(idxMacchina, adesso.AddMinutes(-lastMinutes), adesso, true);
+ if (tabDati.Count > 0)
+ {
+ // chiamo procedura x conversione
+ lastFluxLog = FluxArchive.man.convertTable(tabDati, adesso, timeWindow.free);
+ }
+ alarmEvent nuovoAllarme = new alarmEvent()
+ {
+ yCurr = anno,
+ yCounter = answ,
+ dateYMD = startYMD,
+ started = DateTime.Now,
+ blackBoxData = lastFluxLog,
+ activeConditions = elencoAllarmi
+ };
+
+ collAlarmEvents.InsertOne(nuovoAllarme);
+
+ return answ;
+ }
+ }
+}
diff --git a/MapoDb/FluxArchive.cs b/MapoDb/FluxArchive.cs
index 351a78a7..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();
///
@@ -138,7 +150,7 @@ namespace MapoDb
/// Tabelal dei dati RAW registrati
/// Data di riferimento
/// Periodo del campionamento desiderato (e passato coi dati che sono relativi a tale periodo...)
- protected List convertTable(DS_applicazione.FluxLogDataTable tabDati, DateTime tStamp, timeWindow periodo)
+ public List convertTable(DS_applicazione.FluxLogDataTable tabDati, DateTime tStamp, timeWindow periodo)
{
// init oggetti
List listaRecords = new List();
diff --git a/MapoDb/MapoDb.csproj b/MapoDb/MapoDb.csproj
index 150ef558..49aa14d8 100644
--- a/MapoDb/MapoDb.csproj
+++ b/MapoDb/MapoDb.csproj
@@ -120,6 +120,7 @@
+
DS_applicazione.xsd
@@ -158,6 +159,7 @@
+
True
diff --git a/MapoDb/MtcDataModelArchive.cs b/MapoDb/MtcDataModelArchive.cs
new file mode 100644
index 00000000..b4b5b13e
--- /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/.editorconfig b/MapoSDK/.editorconfig
new file mode 100644
index 00000000..f07b59b1
--- /dev/null
+++ b/MapoSDK/.editorconfig
@@ -0,0 +1,4 @@
+[*.cs]
+
+# CA2227: Le proprietà delle raccolte devono essere di sola lettura
+dotnet_diagnostic.CA2227.severity = none
diff --git a/MapoSDK/Enums.cs b/MapoSDK/Enums.cs
index 17def9d2..08005c68 100644
--- a/MapoSDK/Enums.cs
+++ b/MapoSDK/Enums.cs
@@ -62,6 +62,7 @@
///
public enum timeWindow
{
+ free,
hour,
day,
week,
@@ -179,6 +180,12 @@
///
delete
}
+ public enum DataItemCategory
+ {
+ CONDITION = 0,
+ EVENT = 1,
+ SAMPLE = 2
+ }
public enum tipoBarcode
{
diff --git a/MapoSDK/MapoSDK.csproj b/MapoSDK/MapoSDK.csproj
index af77f46a..7d1bba26 100644
--- a/MapoSDK/MapoSDK.csproj
+++ b/MapoSDK/MapoSDK.csproj
@@ -58,6 +58,7 @@
+
diff --git a/MapoSDK/Objects.cs b/MapoSDK/Objects.cs
index 3ea9750f..c2555e18 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
///
@@ -442,6 +443,151 @@ namespace MapoSDK
#endregion
+ #region gestione ALARMS / CONDITIONS
+
+ ///
+ /// Definizione classe evento allarme
+ ///
+ public class alarmEvent
+ {
+ ///
+ /// Anno di riferimento allarme (per chiave yyyy.n)
+ ///
+ public int yCurr { get; set; } = 0;
+ ///
+ /// Contatore incrementale univoco annuale (per chiave yyyy.n)
+ ///
+ public int yCounter { get; set; } = 0;
+ ///
+ /// Data riferimento campione in formato YMD = yyyyMMdd
+ ///
+ public int dateYMD { get; set; } = 0;
+ ///
+ /// Data-Ora inizio evento
+ ///
+ public DateTime started { get; set; } = DateTime.Now;
+ ///
+ /// Data-Ora inizio evento
+ ///
+ public DateTime ended { get; set; } = DateTime.Now;
+ ///
+ /// Lista delle condizioni di allarme attive ad inizio evento
+ ///
+ public List activeConditions { get; set; } = null;
+ ///
+ /// Elenco dei dati di tipo FluxLog nei minuti antecedenti l'evento
+ ///
+ public List blackBoxData { get; set; } = null;
+ }
+ ///
+ /// Definizione classe evento allarme
+ ///
+ public class alarmStats
+ {
+ ///
+ /// Anno riferimento
+ ///
+ public int year { get; set; } = 0;
+ ///
+ /// Valore Contatore univoco annuale raggiunto yyyy.n
+ ///
+ public int yCounter { get; set; } = 1;
+ ///
+ /// Valore cumulato complessivo degli allarmi registrati
+ ///
+ public double totalDuration { get; set; } = 0;
+ ///
+ /// Durata media annuale allarmi
+ ///
+ public double avgDuration
+ {
+ get
+ {
+ double answ = 0;
+ try
+ {
+ answ = totalDuration / yCounter;
+ }
+ catch
+ { }
+ return answ;
+ }
+ }
+ }
+ ///
+ /// Definizione allarme
+ ///
+ public class alarmData
+ {
+ ///
+ /// Codice univoco
+ ///
+ public string code { get; set; } = "";
+ ///
+ /// Descrizione
+ ///
+ public string description { get; set; } = "";
+ ///
+ /// Severity (0....1000, minimo...massimo)
+ ///
+ public int severity { get; set; } = 0;
+ }
+
+ #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; }
+ }
+ ///
+ /// Descrittore oggetto DataItem generico
+ ///
+ public class machDataItem
+ {
+ public machDataItem()
+ { }
+ ///
+ /// ID generico
+ ///
+ public string uuid { get; set; }
+ ///
+ /// Categoria oggetto
+ ///
+ public DataItemCategory Category { get; set; }
+ ///
+ /// Nome / descrizione
+ ///
+ public string Name { get; set; }
+ ///
+ /// Tipologia principale
+ ///
+ public string Type { get; set; }
+ ///
+ /// Tipologia specifica
+ ///
+ public string SubType { get; set; }
+ ///
+ /// Unità di misura
+ ///
+ public string Units { get; set; }
+ }
+
+ #endregion
+
+ #endregion
+
#if false
///