diff --git a/EgwProxy.Icoel.DataLayer/App.config b/EgwProxy.Icoel.DataLayer/App.config
index 597ea21a..f68bb013 100644
--- a/EgwProxy.Icoel.DataLayer/App.config
+++ b/EgwProxy.Icoel.DataLayer/App.config
@@ -13,5 +13,6 @@
+
\ No newline at end of file
diff --git a/EgwProxy.Icoel.DataLayer/Controllers/DbController.cs b/EgwProxy.Icoel.DataLayer/Controllers/DbController.cs
index d536d988..48d25a99 100644
--- a/EgwProxy.Icoel.DataLayer/Controllers/DbController.cs
+++ b/EgwProxy.Icoel.DataLayer/Controllers/DbController.cs
@@ -26,6 +26,7 @@ namespace EgwProxy.Icoel.DataLayer.Controllers
private static EntrataDbContext dbEntrataCtx;
private static ExportDbContext dbExportCtx;
private static TrackerDbContext dbTrackerCtx;
+ private static SyncStateDbContext dbSyncStateCtx;
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
#endregion Private Fields
@@ -38,7 +39,8 @@ namespace EgwProxy.Icoel.DataLayer.Controllers
/// Connesisone Db frontiera Entrata Merce
/// Connessione DB Tracker
/// Connessione DB IcoelExport
- public DbController(string connEntrata, string connTracker, string connExport)
+ /// Connessione DB locale di SYNC
+ public DbController(string connEntrata, string connTracker, string connExport, string connSyncState)
{
dbEntrataCtx = new EntrataDbContext(connEntrata);
Log.Info("Avviata classe EntrataDbContext");
@@ -46,6 +48,8 @@ namespace EgwProxy.Icoel.DataLayer.Controllers
Log.Info("Avviata classe ExportDbContext");
dbTrackerCtx = new TrackerDbContext(connTracker);
Log.Info("Avviata classe dbTrackerCtx");
+ dbSyncStateCtx = new SyncStateDbContext(connSyncState);
+ Log.Info("Avviata classe dbSyncStateCtx");
}
#endregion Public Constructors
@@ -62,6 +66,7 @@ namespace EgwProxy.Icoel.DataLayer.Controllers
dbEntrataCtx.Dispose();
dbExportCtx.Dispose();
dbTrackerCtx.Dispose();
+ dbSyncStateCtx.Dispose();
}
///
@@ -133,6 +138,52 @@ namespace EgwProxy.Icoel.DataLayer.Controllers
return dbResult;
}
+ ///
+ /// Esegue una volta la stored di ImportAll (x recupero dati da DB esterni) e poi restitusice in output la tab di SyncState x verificare lo stato
+ ///
+ ///
+ public List SyncStateDoImportAll()
+ {
+ List dbResult = new List();
+
+ dbResult = dbSyncStateCtx
+ .Database
+ .SqlQuery("EXEC stp_ImportAll")
+ .ToList();
+
+ return dbResult;
+ }
+
+ ///
+ /// Esegue una volta la stored di ImportAll (x recupero dati da DB esterni) e poi restitusice in output la tab di SyncState x verificare lo stato
+ ///
+ ///
+ public List SyncStateDoExportAll()
+ {
+ List dbResult = new List();
+
+ dbResult = dbSyncStateCtx
+ .Database
+ .SqlQuery("EXEC stp_ExportAll")
+ .ToList();
+
+ return dbResult;
+ }
+
+ ///
+ /// recupera la tab di SyncState corrente
+ ///
+ ///
+ public List SyncStateGetAll()
+ {
+ List dbResult = new List();
+
+ dbResult = dbSyncStateCtx
+ .DbSetSyncState
+ .ToList();
+
+ return dbResult;
+ }
///
/// Elenco record DettConfezioni (da Icoel TrackerLotti)
///
diff --git a/EgwProxy.Icoel.DataLayer/DatabaseModels/SyncStateModel.cs b/EgwProxy.Icoel.DataLayer/DatabaseModels/SyncStateModel.cs
new file mode 100644
index 00000000..477c3fc5
--- /dev/null
+++ b/EgwProxy.Icoel.DataLayer/DatabaseModels/SyncStateModel.cs
@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.Data.Entity.Spatial;
+
+namespace EgwProxy.Icoel.DataLayer.DatabaseModels
+{
+
+ [Table("SyncState")]
+ public partial class SyncStateModel
+ {
+ [Key]
+ [StringLength(50)]
+ public string TableName { get; set; }
+
+ public long LastIdx { get; set; }
+
+ public long LastIdxIn { get; set; }
+
+ public long LastIdxOut { get; set; }
+
+ public long NumRec { get; set; }
+
+ public long NumRecIn { get; set; }
+
+ public long NumRecOut { get; set; }
+ }
+}
diff --git a/EgwProxy.Icoel.DataLayer/EgwProxy.Icoel.DataLayer.csproj b/EgwProxy.Icoel.DataLayer/EgwProxy.Icoel.DataLayer.csproj
index 15e885cf..c1aaa5c3 100644
--- a/EgwProxy.Icoel.DataLayer/EgwProxy.Icoel.DataLayer.csproj
+++ b/EgwProxy.Icoel.DataLayer/EgwProxy.Icoel.DataLayer.csproj
@@ -69,6 +69,8 @@
+
+
diff --git a/EgwProxy.Icoel.DataLayer/SyncStateDbContext.cs b/EgwProxy.Icoel.DataLayer/SyncStateDbContext.cs
new file mode 100644
index 00000000..1e811380
--- /dev/null
+++ b/EgwProxy.Icoel.DataLayer/SyncStateDbContext.cs
@@ -0,0 +1,43 @@
+using EgwProxy.Icoel.DataLayer.DatabaseModels;
+using NLog;
+using System;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.Data.Entity;
+using System.Linq;
+
+namespace EgwProxy.Icoel.DataLayer
+{
+ ///
+ /// Classe per accesso dati SyncState del DB
+ ///
+ public partial class SyncStateDbContext : DbContext
+ {
+ private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
+
+ ///
+ /// Costruttore implicito
+ ///
+ public SyncStateDbContext() : base("name=SyncState")
+ {
+ Log.Info("Init 01 SyncStateDbContext - DONE");
+ }
+
+ ///
+ /// Costruttore da connectionString
+ ///
+ ///
+ public SyncStateDbContext(string connectionString) : base(connectionString)
+ {
+ Log.Info("Init 02 SyncStateDbContext - DONE");
+ }
+
+ ///
+ /// DbSet dai dati stato sync DB esterni <--> locale
+ ///
+ public virtual DbSet DbSetSyncState { get; set; }
+
+ protected override void OnModelCreating(DbModelBuilder modelBuilder)
+ {
+ }
+ }
+}
diff --git a/EgwProxy.Icoel.DataLayer/TrackerDbContext.cs b/EgwProxy.Icoel.DataLayer/TrackerDbContext.cs
index 8c5c3f72..c8800f54 100644
--- a/EgwProxy.Icoel.DataLayer/TrackerDbContext.cs
+++ b/EgwProxy.Icoel.DataLayer/TrackerDbContext.cs
@@ -36,6 +36,7 @@ namespace EgwProxy.Icoel.DataLayer
/// DbSet dai dati conferimento <--> pack di uscita
///
public virtual DbSet DbSetConferimento { get; set; }
+
///
/// DbSet dai dati conferimento <--> confezioni
///
diff --git a/EgwProxy.Icoel.Test/App.config b/EgwProxy.Icoel.Test/App.config
index c24d36b6..f7429e47 100644
--- a/EgwProxy.Icoel.Test/App.config
+++ b/EgwProxy.Icoel.Test/App.config
@@ -15,9 +15,10 @@
-
-
-
+
+
+
+
@@ -39,9 +40,10 @@
diff --git a/EgwProxy.Icoel.Test/Program.cs b/EgwProxy.Icoel.Test/Program.cs
index 0fd445fc..07e069cf 100644
--- a/EgwProxy.Icoel.Test/Program.cs
+++ b/EgwProxy.Icoel.Test/Program.cs
@@ -1,9 +1,10 @@
-using EgwProxy.Icoel.SizerService;
+using EgwProxy.Icoel.DataLayer.DatabaseModels;
+using EgwProxy.Icoel.SizerService;
//using EgwProxy.Icoel.Test.INI;
using System;
using System.Collections.Generic;
using System.Configuration;
-
+using System.Diagnostics;
namespace EgwProxy.Icoel.Test
{
@@ -225,8 +226,46 @@ namespace EgwProxy.Icoel.Test
string userInput = "";
Console.WriteLine("------------ Test DB ------------");
- EgwProxy.Icoel.DbProxy dbProxy = new DbProxy(ReadSetting("EntrataFrontiera"), ReadSetting("TrackerLotti"), ReadSetting("ExportIcoel"));
+ EgwProxy.Icoel.DbProxy dbProxy = new DbProxy(ReadSetting("EntrataFrontiera"), ReadSetting("TrackerLotti"), ReadSetting("ExportIcoel"), ReadSetting("SyncState"));
Console.WriteLine();
+ Console.WriteLine("--- SyncState ---");
+ bool needRedo = true;
+ var elencoSyncState = dbProxy.DataController.SyncStateGetAll();
+ while (needRedo)
+ {
+ Console.WriteLine(" --- PRE --- ");
+ if (elencoSyncState != null)
+ {
+ foreach (var item in elencoSyncState)
+ {
+ Console.WriteLine($"TAB: {item.TableName} | IdxIN / IdxLocal {item.LastIdxIn} / {item.LastIdx} | NumIn / NumLocal {item.NumRecIn} / {item.NumRec}");
+ // verifico se serva redo..
+ }
+ }
+ Console.WriteLine();
+ Console.WriteLine("Premere un tasto x continuare...");
+ Console.ReadKey();
+ Stopwatch sw = new Stopwatch();
+ sw.Start();
+ elencoSyncState = dbProxy.DataController.SyncStateDoImportAll();
+ sw.Stop();
+ Console.WriteLine($" process time: {sw.ElapsedMilliseconds} ms ");
+ Console.WriteLine(" --- POST --- ");
+ if (elencoSyncState != null)
+ {
+ foreach (var item in elencoSyncState)
+ {
+ Console.WriteLine($"TAB: {item.TableName} | IdxIN / IdxLocal {item.LastIdxIn} / {item.LastIdx} | NumIn / NumLocal {item.NumRecIn} / {item.NumRec}");
+ // verifico se serva redo..
+ }
+ }
+ // processo
+ needRedo = testNeedRedo(elencoSyncState);
+ }
+ Console.WriteLine();
+ Console.WriteLine("Premere un tasto x continuare...");
+ Console.ReadKey();
+
Console.WriteLine("--- Entrata Frontiera ---");
var elencoBarcode = dbProxy.DataController.EntrateGetLast(10);
if (elencoBarcode != null)
@@ -357,6 +396,21 @@ namespace EgwProxy.Icoel.Test
Console.ReadKey();
}
}
+ ///
+ /// Verifico necessità di rifare sync
+ ///
+ ///
+ ///
+ ///
+ private static bool testNeedRedo(List elencoSyncState)
+ {
+ bool answ = false;
+ foreach (var item in elencoSyncState)
+ {
+ answ = answ || (item.NumRecIn > item.NumRec || item.LastIdxIn > item.LastIdx);
+ }
+ return answ;
+ }
#endregion Private Methods
diff --git a/EgwProxy.Icoel/DbProxy.cs b/EgwProxy.Icoel/DbProxy.cs
index a0337dfa..772b6536 100644
--- a/EgwProxy.Icoel/DbProxy.cs
+++ b/EgwProxy.Icoel/DbProxy.cs
@@ -23,9 +23,10 @@ namespace EgwProxy.Icoel
/// stringa connesisone DB Entrata
/// stringa connesisone DB Tracker
/// stringa connesisone DB Export
- public DbProxy(string connEntrata, string connTracker, string connExport)
+ /// Connessione DB locale di SYNC
+ public DbProxy(string connEntrata, string connTracker, string connExport, string connSyncState)
{
- DataController = new DbController(connEntrata, connTracker, connExport);
+ DataController = new DbController(connEntrata, connTracker, connExport, connSyncState);
}
}
}