aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-02-07 14:53:58 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-02-07 14:53:58 +0200
commitbd63d7d2f7769e5534fb9a58d97358564c2cb674 (patch)
treed4c990b02d5b0678e8133a73b30f474dd1b3b428
parent6e082b1d9d7b4c5888e7e7345e148eb944b8c624 (diff)
downloadTango-bd63d7d2f7769e5534fb9a58d97358564c2cb674.tar.gz
Tango-bd63d7d2f7769e5534fb9a58d97358564c2cb674.zip
Implemented progress text on DB Comparers instead of custom logger.
-rw-r--r--Software/DB/Tango.dbbin294912 -> 274432 bytes
-rw-r--r--Software/DB/Tango.mdfbin75497472 -> 75497472 bytes
-rw-r--r--Software/DB/Tango_log.ldfbin8388608 -> 8388608 bytes
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/DirectSynchronizationViewVM.cs19
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/LocalSynchronizationViewVM.cs20
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/MainViewVM.cs61
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/RemoteSynchronizationViewVM.cs18
-rw-r--r--Software/Visual_Studio/Tango.Logging/LogManager.cs10
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/IDBComparer.cs5
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/Local/LocalDBComparer.cs72
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBComparer.cs120
11 files changed, 176 insertions, 149 deletions
diff --git a/Software/DB/Tango.db b/Software/DB/Tango.db
index 14d90fcdf..a6bd7a3ab 100644
--- a/Software/DB/Tango.db
+++ b/Software/DB/Tango.db
Binary files differ
diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf
index a06fe4c09..8b3b3cf21 100644
--- a/Software/DB/Tango.mdf
+++ b/Software/DB/Tango.mdf
Binary files differ
diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf
index 75df2405b..38a0fb324 100644
--- a/Software/DB/Tango_log.ldf
+++ b/Software/DB/Tango_log.ldf
Binary files differ
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/DirectSynchronizationViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/DirectSynchronizationViewVM.cs
index d7dac7fbe..070beefa6 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/DirectSynchronizationViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/DirectSynchronizationViewVM.cs
@@ -1,4 +1,5 @@
using Google.Protobuf;
+using Microsoft.Practices.ServiceLocation;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -35,6 +36,7 @@ namespace Tango.MachineStudio.Synchronization.ViewModels
private LocalDBComparer _comparer;
private INotificationProvider _notification;
private String _comparedSerialNumber;
+ private MainViewVM _mainView;
#region Constructors
@@ -160,6 +162,21 @@ namespace Tango.MachineStudio.Synchronization.ViewModels
#endregion
+ #region Event Handlers
+
+ private void Comparer_Progress(object sender, string e)
+ {
+ if (_mainView == null)
+ {
+ _mainView = ServiceLocator.Current.GetInstance<MainViewVM>();
+ _mainView.Log = String.Empty;
+ }
+
+ _mainView.Log += ("[" + DateTime.Now.ToTimeString() + "] " + e + Environment.NewLine);
+ }
+
+ #endregion
+
#region Private Methods
/// <summary>
@@ -212,6 +229,7 @@ namespace Tango.MachineStudio.Synchronization.ViewModels
using (_notification.PushTaskItem("Comparing database..."))
{
_comparer = new LocalDBComparer(new SQLiteDataBase(_masterDBFile), new SQLiteDataBase(_slaveDBFile));
+ _comparer.Progress += Comparer_Progress;
var diffs = _comparer.Compare();
Differences = new ObservableCollection<Diff>(diffs);
@@ -253,6 +271,7 @@ namespace Tango.MachineStudio.Synchronization.ViewModels
});
}
+
/// <summary>
/// Synchronizes the selected machine with the remote database.
/// </summary>
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/LocalSynchronizationViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/LocalSynchronizationViewVM.cs
index 41cf94b96..2621f622a 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/LocalSynchronizationViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/LocalSynchronizationViewVM.cs
@@ -1,4 +1,5 @@
-using Microsoft.Win32;
+using Microsoft.Practices.ServiceLocation;
+using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -31,6 +32,7 @@ namespace Tango.MachineStudio.Synchronization.ViewModels
private LocalDBComparer _comparer;
private INotificationProvider _notification;
private bool _isWorking;
+ private MainViewVM _mainView;
#region Constructors
@@ -170,6 +172,21 @@ namespace Tango.MachineStudio.Synchronization.ViewModels
#endregion
+ #region Event Handlers
+
+ private void Comparer_Progress(object sender, string e)
+ {
+ if (_mainView == null)
+ {
+ _mainView = ServiceLocator.Current.GetInstance<MainViewVM>();
+ _mainView.Log = String.Empty;
+ }
+
+ _mainView.Log += ("[" + DateTime.Now.ToTimeString() + "] " + e + Environment.NewLine);
+ }
+
+ #endregion
+
#region Private Methods
/// <summary>
@@ -218,6 +235,7 @@ namespace Tango.MachineStudio.Synchronization.ViewModels
private void Compare()
{
_comparer = new LocalDBComparer(new SQLiteDataBase(MasterDBFile), new SQLiteDataBase(SlaveDBFile));
+ _comparer.Progress += Comparer_Progress;
Task.Factory.StartNew(() =>
{
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/MainViewVM.cs
index 21d76d7d7..987b9ac4d 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/MainViewVM.cs
@@ -19,13 +19,7 @@ namespace Tango.MachineStudio.Synchronization.ViewModels
/// </summary>
public MainViewVM()
{
- MainViewLogger logger = new MainViewLogger();
- logger.NewLog += (output) =>
- {
- //Log += output + Environment.NewLine;
- };
-
- LogManager.RegisterLogger(logger);
+ Log = "Synchronization module started...";
}
private String _log;
@@ -37,58 +31,5 @@ namespace Tango.MachineStudio.Synchronization.ViewModels
get { return _log; }
set { _log = value; RaisePropertyChanged(nameof(Log)); }
}
-
- #region Custom Logger
-
- /// <summary>
- /// Represents a custom logger.
- /// </summary>
- /// <seealso cref="Tango.Logging.ILogger" />
- public class MainViewLogger : ILogger
- {
- /// <summary>
- /// Gets or sets a value indicating whether this <see cref="T:Tango.Logging.ILogger" /> is enabled.
- /// </summary>
- public bool Enabled { get; set; }
-
- /// <summary>
- /// Gets or sets a value indicating whether this <see cref="T:Tango.Logging.ILogger" /> will be notified about logs without waiting for the logs queue.
- /// </summary>
- public bool Immediate { get; set; }
-
- /// <summary>
- /// Occurs when a new log item is available.
- /// </summary>
- public event Action<String> NewLog;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="MainViewLogger"/> class.
- /// </summary>
- public MainViewLogger()
- {
- Enabled = true;
- Immediate = true;
- }
-
- /// <summary>
- /// Called when a new library exception is available.
- /// </summary>
- /// <param name="output">The output.</param>
- public void OnError(LogItemBase output)
- {
- NewLog?.Invoke(output.TimeStamp.ToTimeString() + ": " + output.GetMessage());
- }
-
- /// <summary>
- /// Called when a new library trace is available.
- /// </summary>
- /// <param name="output">The output.</param>
- public void OnTrace(LogItemBase output)
- {
- NewLog?.Invoke(output.TimeStamp.ToTimeString() + ": " + output.GetMessage());
- }
- }
-
- #endregion
}
}
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/RemoteSynchronizationViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/RemoteSynchronizationViewVM.cs
index f9f738a26..0f427643f 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/RemoteSynchronizationViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/RemoteSynchronizationViewVM.cs
@@ -21,6 +21,7 @@ using Tango.SharedUI;
using Tango.Synchronization;
using Tango.Synchronization.Local;
using Tango.Synchronization.Remote;
+using Microsoft.Practices.ServiceLocation;
namespace Tango.MachineStudio.Synchronization.ViewModels
{
@@ -38,6 +39,7 @@ namespace Tango.MachineStudio.Synchronization.ViewModels
private RemoteDBComparer _comparer;
private RemoteDB _remoteDB;
private LocalDB _localDB;
+ private MainViewVM _mainView;
#region Constructors
@@ -109,6 +111,21 @@ namespace Tango.MachineStudio.Synchronization.ViewModels
#endregion
+ #region Event Handlers
+
+ private void Comparer_Progress(object sender, string e)
+ {
+ if (_mainView == null)
+ {
+ _mainView = ServiceLocator.Current.GetInstance<MainViewVM>();
+ _mainView.Log = String.Empty;
+ }
+
+ _mainView.Log += ("[" + DateTime.Now.ToTimeString() + "] " + e + Environment.NewLine);
+ }
+
+ #endregion
+
#region Properties
private ObservableCollection<Diff> _differences;
@@ -222,6 +239,7 @@ namespace Tango.MachineStudio.Synchronization.ViewModels
_remoteDB = RemoteDB.CreateDefault();
_localDB = new LocalDB(SlaveDBFile);
_comparer = new RemoteDBComparer(_remoteDB, _localDB, SelectedMachine.SerialNumber);
+ _comparer.Progress += Comparer_Progress;
_isWorking = true;
InvalidateRelayCommands();
Thread.Sleep(1500);
diff --git a/Software/Visual_Studio/Tango.Logging/LogManager.cs b/Software/Visual_Studio/Tango.Logging/LogManager.cs
index 0fe1e11b3..d6750ce0b 100644
--- a/Software/Visual_Studio/Tango.Logging/LogManager.cs
+++ b/Software/Visual_Studio/Tango.Logging/LogManager.cs
@@ -115,18 +115,18 @@ namespace Tango.Logging
/// Add new message log item.
/// </summary>
/// <param name="message">Message.</param>
- public static void Log(String message, [CallerMemberName] string caller = null, [CallerFilePath] string file = null, [CallerLineNumber] int lineNumber = 0)
+ public static String Log(String message, [CallerMemberName] string caller = null, [CallerFilePath] string file = null, [CallerLineNumber] int lineNumber = 0)
{
- Log(message, LogCategory.General, caller, file, lineNumber);
+ return Log(message, LogCategory.General, caller, file, lineNumber);
}
/// <summary>
/// Add new message log item.
/// </summary>
/// <param name="message">Message.</param>
- public static void Log(String message, LogCategory category, [CallerMemberName] string caller = null, [CallerFilePath] string file = null, [CallerLineNumber] int lineNumber = 0)
+ public static String Log(String message, LogCategory category, [CallerMemberName] string caller = null, [CallerFilePath] string file = null, [CallerLineNumber] int lineNumber = 0)
{
- if (!Categories.Contains(category)) return;
+ if (!Categories.Contains(category)) return message;
MessageLogItem log = new MessageLogItem();
log.CallerMethodName = caller;
@@ -144,6 +144,8 @@ namespace Tango.Logging
{
AppendLogInstantly(log);
}
+
+ return message;
}
/// <summary>
diff --git a/Software/Visual_Studio/Tango.Synchronization/IDBComparer.cs b/Software/Visual_Studio/Tango.Synchronization/IDBComparer.cs
index 05a955002..3d0ffc6e0 100644
--- a/Software/Visual_Studio/Tango.Synchronization/IDBComparer.cs
+++ b/Software/Visual_Studio/Tango.Synchronization/IDBComparer.cs
@@ -13,6 +13,11 @@ namespace Tango.Synchronization
public interface IDBComparer : IDisposable
{
/// <summary>
+ /// Used to notify about the comparer progress using text messages.
+ /// </summary>
+ event EventHandler<String> Progress;
+
+ /// <summary>
/// Performs a database comparison and returns a set of differences.
/// </summary>
/// <returns></returns>
diff --git a/Software/Visual_Studio/Tango.Synchronization/Local/LocalDBComparer.cs b/Software/Visual_Studio/Tango.Synchronization/Local/LocalDBComparer.cs
index a279af337..4f19e785f 100644
--- a/Software/Visual_Studio/Tango.Synchronization/Local/LocalDBComparer.cs
+++ b/Software/Visual_Studio/Tango.Synchronization/Local/LocalDBComparer.cs
@@ -16,6 +16,11 @@ namespace Tango.Synchronization.Local
public class LocalDBComparer : IDBComparer
{
/// <summary>
+ /// Used to notify about the comparer progress using text messages.
+ /// </summary>
+ public event EventHandler<string> Progress;
+
+ /// <summary>
/// Gets the master SQL.
/// </summary>
public ILocalDataBase MasterSQL { get; private set; }
@@ -42,12 +47,12 @@ namespace Tango.Synchronization.Local
/// <returns></returns>
public List<Diff> Compare()
{
- LogManager.Log("Comparing databases " + Path.GetFileName(MasterSQL.Source) + " <=> " + Path.GetFileName(SlaveSQL.Source));
+ OnProgress(LogManager.Log("Comparing databases " + Path.GetFileName(MasterSQL.Source) + " <=> " + Path.GetFileName(SlaveSQL.Source)));
- LogManager.Log("Loading master tables...");
+ OnProgress(LogManager.Log("Loading master tables..."));
MasterSQL.LoadTables();
- LogManager.Log("Loading slave tables...");
+ OnProgress(LogManager.Log("Loading slave tables..."));
SlaveSQL.LoadTables();
List<Diff> diffs = new List<Diff>();
@@ -73,13 +78,13 @@ namespace Tango.Synchronization.Local
foreach (var masterTable in overwrite_tables)
{
- LogManager.Log("Generating table overwrite difference for table " + masterTable.TableName);
+ OnProgress(LogManager.Log("Generating table overwrite difference for table " + masterTable.TableName));
var slaveTable = SlaveSQL.Tables.SingleOrDefault(x => x.TableName == masterTable.TableName); //Get matching slave table on slave db.
if (slaveTable == null) //Table not found on slave.
{
- LogManager.Log("Table not found on slave, adding difference.");
+ OnProgress(LogManager.Log("Table not found on slave, adding difference."));
//Clone table from slave db to master db including records!
diffs.Add(new Diff(DiffAction.AddTableToSlave, String.Format("Add table {0} to slave", masterTable.TableName), () => SlaveSQL.CloneTableFrom(MasterSQL, masterTable), SlaveSQL.GetCloneTableFromCommand(MasterSQL, masterTable)));
continue;
@@ -87,18 +92,18 @@ namespace Tango.Synchronization.Local
foreach (DataColumn masterColumn in masterTable.Columns)
{
- LogManager.Log("Searching for column " + masterColumn.ColumnName + " on slave...");
+ OnProgress(LogManager.Log("Searching for column " + masterColumn.ColumnName + " on slave..."));
var slaveColumn = slaveTable.Columns[masterColumn.ColumnName]; //Get matching slave column on slave table.
if (slaveColumn == null) //Slave column not found.
{
- LogManager.Log("Column not found on slave, adding difference.");
+ OnProgress(LogManager.Log("Column not found on slave, adding difference."));
//Add column to slave table.
diffs.Add(new Diff(DiffAction.AddColumnToSlave, String.Format("Add column {0} to slave table", masterColumn.ColumnName), () => SlaveSQL.AddColumn(masterTable, masterColumn), SlaveSQL.GetAddColumnCommand(masterTable, masterColumn)));
}
- LogManager.Log("Column found.");
+ OnProgress(LogManager.Log("Column found."));
}
diffs.Add(new Diff(DiffAction.ReplaceTableDataInSlave, "Replace all rows on slave table " + masterTable.TableName, () =>
@@ -111,35 +116,35 @@ namespace Tango.Synchronization.Local
foreach (var masterTable in sync_tables)
{
- LogManager.Log("Comparing table " + masterTable.TableName);
- LogManager.Log("Searching table " + masterTable.TableName + " on slave...");
+ OnProgress(LogManager.Log("Comparing table " + masterTable.TableName));
+ OnProgress(LogManager.Log("Searching table " + masterTable.TableName + " on slave..."));
var slaveTable = SlaveSQL.Tables.SingleOrDefault(x => x.TableName == masterTable.TableName); //Get matching slave table on slave db.
if (slaveTable == null) //Table not found on slave.
{
- LogManager.Log("Table not found on slave, adding difference.");
+ OnProgress(LogManager.Log("Table not found on slave, adding difference."));
//Clone table from slave db to master db including records!
diffs.Add(new Diff(DiffAction.AddTableToSlave, String.Format("Add table {0} to slave", masterTable.TableName), () => SlaveSQL.CloneTableFrom(MasterSQL, masterTable), SlaveSQL.GetCloneTableFromCommand(MasterSQL, masterTable)));
continue;
}
- LogManager.Log("Table found, comparing columns...");
+ OnProgress(LogManager.Log("Table found, comparing columns..."));
foreach (DataColumn masterColumn in masterTable.Columns)
{
- LogManager.Log("Searching for column " + masterColumn.ColumnName + " on slave...");
+ OnProgress(LogManager.Log("Searching for column " + masterColumn.ColumnName + " on slave..."));
var slaveColumn = slaveTable.Columns[masterColumn.ColumnName]; //Get matching slave column on slave table.
if (slaveColumn == null) //Slave column not found.
{
- LogManager.Log("Column not found on slave, adding difference.");
+ OnProgress(LogManager.Log("Column not found on slave, adding difference."));
//Add column to slave table.
diffs.Add(new Diff(DiffAction.AddColumnToSlave, String.Format("Add column {0} to slave table", masterColumn.ColumnName), () => SlaveSQL.AddColumn(masterTable, masterColumn), SlaveSQL.GetAddColumnCommand(masterTable, masterColumn)));
}
- LogManager.Log("Column found.");
+ OnProgress(LogManager.Log("Column found."));
}
List<DataRow> addToSlave = new List<DataRow>();
@@ -147,75 +152,75 @@ namespace Tango.Synchronization.Local
List<DataRow> addToMaster = new List<DataRow>();
List<DataRow> updateMaster = new List<DataRow>();
- LogManager.Log("Comparing rows...");
+ OnProgress(LogManager.Log("Comparing rows..."));
int count = 0;
foreach (DataRow masterRow in masterTable.Rows)
{
- LogManager.Log("Comparing row " + count++);
+ OnProgress(LogManager.Log("Comparing row " + count++));
String guid = masterRow.Field<String>(Constants.GUID);
- LogManager.Log("Searching for row with GUID " + guid + " on slave table...");
+ OnProgress(LogManager.Log("Searching for row with GUID " + guid + " on slave table..."));
//Get Matching slave row.
DataRow slaveRow = slaveTable.AsEnumerable().SingleOrDefault(x => x.Field<String>(Constants.GUID) == guid);
if (slaveRow != null)
{
- LogManager.Log("Slave row found, comparing dates...");
+ OnProgress(LogManager.Log("Slave row found, comparing dates..."));
DateTime masterDate = masterRow.Field<DateTime>(Constants.LAST_UPDATED);
DateTime slaveDate = slaveRow.Field<DateTime>(Constants.LAST_UPDATED);
if (masterDate > slaveDate)
{
- LogManager.Log("Master => Slave Update " + masterDate.ToSQLiteDateString() + ", adding difference.");
+ OnProgress(LogManager.Log("Master => Slave Update " + masterDate.ToSQLiteDateString() + ", adding difference."));
updateSlave.Add(masterRow);
}
else if (slaveDate > masterDate)
{
- LogManager.Log("Master <= Slave Update " + masterDate.ToSQLiteDateString() + ", adding difference.");
+ OnProgress(LogManager.Log("Master <= Slave Update " + masterDate.ToSQLiteDateString() + ", adding difference."));
updateMaster.Add(slaveRow);
}
else
{
- LogManager.Log("Master <=> Slave No Update.");
+ OnProgress(LogManager.Log("Master <=> Slave No Update."));
}
}
else
{
- LogManager.Log("Slave row not found, adding difference.");
+ OnProgress(LogManager.Log("Slave row not found, adding difference."));
addToSlave.Add(masterRow);
}
}
- LogManager.Log("Done comparing rows...");
+ OnProgress(LogManager.Log("Done comparing rows..."));
- LogManager.Log("Searching for missing rows on master...");
+ OnProgress(LogManager.Log("Searching for missing rows on master..."));
foreach (DataRow slaveRow in slaveTable.Rows)
{
String guid = slaveRow.Field<String>(Constants.GUID);
- LogManager.Log("Searching for row with GUID " + guid + " on master table...");
+ OnProgress(LogManager.Log("Searching for row with GUID " + guid + " on master table..."));
//Get Matching slave row.
DataRow masterRow = masterTable.AsEnumerable().SingleOrDefault(x => x.Field<String>(Constants.GUID) == guid);
if (masterRow == null)
{
- LogManager.Log("Master row not found, adding difference.");
+ OnProgress(LogManager.Log("Master row not found, adding difference."));
addToMaster.Add(slaveRow);
}
else
{
- LogManager.Log("Master row found.");
+ OnProgress(LogManager.Log("Master row found."));
}
}
- LogManager.Log("Done searching for missing rows on master...");
+ OnProgress(LogManager.Log("Done searching for missing rows on master..."));
foreach (var row in addToSlave)
{
@@ -237,14 +242,19 @@ namespace Tango.Synchronization.Local
diffs.Add(new Diff(DiffAction.UpdateRowInMaster, String.Format("Update row in master table {0}", masterTable.TableName), () => MasterSQL.UpdateRow(masterTable, row), MasterSQL.GetUpdateRowCommand(masterTable, row)));
}
- LogManager.Log("Done comparing table " + masterTable.TableName);
+ OnProgress(LogManager.Log("Done comparing table " + masterTable.TableName));
}
- LogManager.Log("Databases comparison completed.");
+ OnProgress(LogManager.Log("Databases comparison completed."));
return diffs;
}
+ protected virtual void OnProgress(String message)
+ {
+ Progress?.Invoke(this, message);
+ }
+
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
diff --git a/Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBComparer.cs b/Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBComparer.cs
index c75f5c003..d91e77cda 100644
--- a/Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBComparer.cs
+++ b/Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBComparer.cs
@@ -23,6 +23,11 @@ namespace Tango.Synchronization.Remote
private List<Diff> _diffs;
/// <summary>
+ /// Used to notify about the comparer progress using text messages.
+ /// </summary>
+ public event EventHandler<string> Progress;
+
+ /// <summary>
/// Initializes a new instance of the <see cref="RemoteDBComparer"/> class.
/// </summary>
/// <param name="remoteDB">The remote database.</param>
@@ -44,46 +49,46 @@ namespace Tango.Synchronization.Remote
{
_diffs = new List<Diff>();
- LogManager.Log("Performing SQL Server <=> SQLite database comparison...");
+ OnProgress(LogManager.Log("Performing SQL Server <=> SQLite database comparison..."));
- LogManager.Log("Loading SQLite database to memory...");
+ OnProgress(LogManager.Log("Loading SQLite database to memory..."));
- LogManager.Log("Querying all local addresses...");
+ OnProgress(LogManager.Log("Querying all local addresses..."));
var local_addresses = _localDB.ADDRESSES.ToList();
- LogManager.Log("Querying all local configurations...");
+ OnProgress(LogManager.Log("Querying all local configurations..."));
var local_configurations = _localDB.CONFIGURATIONS.ToList();
- LogManager.Log("Querying all local configuration dispensers...");
+ OnProgress(LogManager.Log("Querying all local configuration dispensers..."));
var local_ids_packs = _localDB.IDS_PACKS.ToList();
- LogManager.Log("Querying all local contacts...");
+ OnProgress(LogManager.Log("Querying all local contacts..."));
var local_contacts = _localDB.CONTACTS.ToList();
- LogManager.Log("Querying all local machines...");
+ OnProgress(LogManager.Log("Querying all local machines..."));
var local_machines = _localDB.MACHINES.Where(x => x.SERIAL_NUMBER == _machineSerial).ToList();
- LogManager.Log("Querying all local machines configurations...");
+ OnProgress(LogManager.Log("Querying all local machines configurations..."));
var local_machines_configurations = _localDB.MACHINES_CONFIGURATIONS.ToList();
- LogManager.Log("Querying all local machines events...");
+ OnProgress(LogManager.Log("Querying all local machines events..."));
var local_machines_events = _localDB.MACHINES_EVENTS.ToList();
- LogManager.Log("Querying all local organizations...");
+ OnProgress(LogManager.Log("Querying all local organizations..."));
var local_organizations = _localDB.ORGANIZATIONS.ToList();
- LogManager.Log("Querying all local users...");
+ OnProgress(LogManager.Log("Querying all local users..."));
var local_users = _localDB.USERS.ToList();
- LogManager.Log("Querying all local users roles...");
+ OnProgress(LogManager.Log("Querying all local users roles..."));
var local_users_roles = _localDB.USERS_ROLES.ToList();
- LogManager.Log("Querying all local jobs...");
+ OnProgress(LogManager.Log("Querying all local jobs..."));
var local_jobs = _localDB.JOBS.ToList();
- LogManager.Log("Querying all local job runs...");
+ OnProgress(LogManager.Log("Querying all local job runs..."));
var local_job_runs = _localDB.JOB_RUNS.ToList();
- LogManager.Log("Querying all local segments...");
+ OnProgress(LogManager.Log("Querying all local segments..."));
var local_segments = _localDB.SEGMENTS.ToList();
- LogManager.Log("Querying all local brush stops...");
+ OnProgress(LogManager.Log("Querying all local brush stops..."));
var local_brush_stops = _localDB.BRUSH_STOPS.ToList();
//LogManager.Log("Querying all CATS...");
//var local_cats = _localDB.CATS.ToList();
- LogManager.Log("Loading SQL Server database to memory...");
+ OnProgress(LogManager.Log("Loading SQL Server database to memory..."));
List<String> guids = new List<string>();
- LogManager.Log("Querying all remote machines...");
+ OnProgress(LogManager.Log("Querying all remote machines..."));
var remote_machines = _remoteDB.MACHINES.Where(x => x.SERIAL_NUMBER == _machineSerial).ToList();
if (remote_machines.Count == 0)
@@ -91,58 +96,58 @@ namespace Tango.Synchronization.Remote
throw LogManager.Log(new DataBaseComparisonException("Could not locate machine on remote server " + _machineSerial));
}
- LogManager.Log("Querying all remote organizations...");
+ OnProgress(LogManager.Log("Querying all remote organizations..."));
guids = remote_machines.Select(x => x.ORGANIZATION_GUID).ToList();
var remote_organizations = _remoteDB.ORGANIZATIONS.Where(x => guids.Contains(x.GUID)).ToList();
- LogManager.Log("Querying all remote machines configurations...");
+ OnProgress(LogManager.Log("Querying all remote machines configurations..."));
guids = remote_machines.Select(x => x.GUID).ToList();
var remote_machines_configurations = _remoteDB.MACHINES_CONFIGURATIONS.Where(x => guids.Contains(x.MACHINE_GUID)).ToList();
var remote_configurations = remote_machines_configurations.Select(x => x.CONFIGURATION).ToList();
- LogManager.Log("Querying all remote machines events...");
+ OnProgress(LogManager.Log("Querying all remote machines events..."));
var remote_machines_events = _remoteDB.MACHINES_EVENTS.Where(x => guids.Contains(x.MACHINE_GUID)).ToList();
- LogManager.Log("Querying all remote users...");
+ OnProgress(LogManager.Log("Querying all remote users..."));
guids = remote_organizations.Select(x => x.GUID).ToList();
var remote_users = _remoteDB.USERS.Where(x => guids.Contains(x.ORGANIZATION_GUID)).ToList();
- LogManager.Log("Querying all remote users roles...");
+ OnProgress(LogManager.Log("Querying all remote users roles..."));
guids = remote_users.Select(x => x.GUID).ToList();
var remote_users_roles = _remoteDB.USERS_ROLES.Where(x => guids.Contains(x.USER_GUID)).ToList();
- LogManager.Log("Querying all remote addresses...");
+ OnProgress(LogManager.Log("Querying all remote addresses..."));
var remote_addresses = remote_users.Select(x => x.ADDRESS).ToList();
remote_addresses.AddRange(remote_machines.Select(x => x.ORGANIZATION).Select(x => x.ADDRESS));
remote_addresses = remote_addresses.Distinct().ToList();
- LogManager.Log("Querying all remote contacts...");
+ OnProgress(LogManager.Log("Querying all remote contacts..."));
var remote_contacts = remote_users.Select(x => x.CONTACT).ToList();
remote_contacts.AddRange(remote_machines.Select(x => x.ORGANIZATION).Select(x => x.CONTACT));
remote_contacts = remote_contacts.Distinct().ToList();
- LogManager.Log("Querying all remote IDS Packs...");
+ OnProgress(LogManager.Log("Querying all remote IDS Packs..."));
guids = remote_configurations.Select(x => x.GUID).ToList();
var remote_ids_packs = _remoteDB.IDS_PACKS.Where(x => guids.Contains(x.CONFIGURATION_GUID)).ToList();
- LogManager.Log("Querying all remote dispenser types...");
+ OnProgress(LogManager.Log("Querying all remote dispenser types..."));
guids = remote_ids_packs.Select(x => x.DISPENSER_TYPE_GUID).ToList();
var remote_dispensers_types = _remoteDB.DISPENSER_TYPES.Where(x => guids.Contains(x.GUID)).ToList();
- LogManager.Log("Querying all remote cartridge types...");
+ OnProgress(LogManager.Log("Querying all remote cartridge types..."));
guids = remote_ids_packs.Select(x => x.CARTRIDGE_TYPE_GUID).ToList();
var remote_cartridges_types = _remoteDB.CARTRIDGE_TYPES.Where(x => guids.Contains(x.GUID)).ToList();
- LogManager.Log("Querying all remote jobs...");
+ OnProgress(LogManager.Log("Querying all remote jobs..."));
var remote_jobs = remote_machines.SelectMany(x => x.JOBS).ToList();
- LogManager.Log("Querying all remote job runs...");
+ OnProgress(LogManager.Log("Querying all remote job runs..."));
var remote_jobs_runs = remote_jobs.SelectMany(x => x.JOB_RUNS).ToList();
- LogManager.Log("Querying all remote segments...");
+ OnProgress(LogManager.Log("Querying all remote segments..."));
var remote_segments = remote_jobs.SelectMany(x => x.SEGMENTS).ToList();
- LogManager.Log("Querying all remote brush stops...");
+ OnProgress(LogManager.Log("Querying all remote brush stops..."));
var remote_brush_stops = remote_segments.SelectMany(x => x.BRUSH_STOPS).ToList();
//LogManager.Log("Querying all remote CATS...");
@@ -156,52 +161,52 @@ namespace Tango.Synchronization.Remote
}
- LogManager.Log("Comparing addresses");
+ OnProgress(LogManager.Log("Comparing addresses"));
CompareCollections(remote_addresses, local_addresses, _remoteDB.ADDRESSES, _localDB.ADDRESSES);
- LogManager.Log("Comparing configurations");
+ OnProgress(LogManager.Log("Comparing configurations"));
CompareCollections(remote_configurations, local_configurations, _remoteDB.CONFIGURATIONS, _localDB.CONFIGURATIONS);
- LogManager.Log("Comparing configurations dispensers");
+ OnProgress(LogManager.Log("Comparing configurations dispensers"));
CompareCollections(remote_ids_packs, local_ids_packs, _remoteDB.IDS_PACKS, _localDB.IDS_PACKS);
- LogManager.Log("Comparing contacts");
+ OnProgress(LogManager.Log("Comparing contacts"));
CompareCollections(remote_contacts, local_contacts, _remoteDB.CONTACTS, _localDB.CONTACTS);
- LogManager.Log("Comparing machines");
+ OnProgress(LogManager.Log("Comparing machines"));
CompareCollections(remote_machines, local_machines, _remoteDB.MACHINES, _localDB.MACHINES);
- LogManager.Log("Comparing machines configuration");
+ OnProgress(LogManager.Log("Comparing machines configuration"));
CompareCollections(remote_machines_configurations, local_machines_configurations, _remoteDB.MACHINES_CONFIGURATIONS, _localDB.MACHINES_CONFIGURATIONS);
- LogManager.Log("Comparing machines events");
+ OnProgress(LogManager.Log("Comparing machines events"));
CompareCollections(remote_machines_events, local_machines_events, _remoteDB.MACHINES_EVENTS, _localDB.MACHINES_EVENTS);
- LogManager.Log("Comparing organizations");
+ OnProgress(LogManager.Log("Comparing organizations"));
CompareCollections(remote_organizations, local_organizations, _remoteDB.ORGANIZATIONS, _localDB.ORGANIZATIONS);
- LogManager.Log("Comparing users");
+ OnProgress(LogManager.Log("Comparing users"));
CompareCollections(remote_users, local_users, _remoteDB.USERS, _localDB.USERS);
- LogManager.Log("Comparing users roles");
+ OnProgress(LogManager.Log("Comparing users roles"));
CompareCollections(remote_users_roles, local_users_roles, _remoteDB.USERS_ROLES, _localDB.USERS_ROLES);
- LogManager.Log("Comparing jobs");
+ OnProgress(LogManager.Log("Comparing jobs"));
CompareCollections(remote_jobs, local_jobs, _remoteDB.JOBS, _localDB.JOBS);
- LogManager.Log("Comparing job runs");
+ OnProgress(LogManager.Log("Comparing job runs"));
CompareCollections(remote_jobs_runs, local_job_runs, _remoteDB.JOB_RUNS, _localDB.JOB_RUNS);
- LogManager.Log("Comparing segments");
+ OnProgress(LogManager.Log("Comparing segments"));
CompareCollections(remote_segments, local_segments, _remoteDB.SEGMENTS, _localDB.SEGMENTS);
- LogManager.Log("Comparing brush stops");
+ OnProgress(LogManager.Log("Comparing brush stops"));
CompareCollections(remote_brush_stops, local_brush_stops, _remoteDB.BRUSH_STOPS, _localDB.BRUSH_STOPS);
//LogManager.Log("Comparing cats");
//CompareCollections(remote_cats, local_cats, _remoteDB.CATS, _localDB.CATS);
- LogManager.Log("Comparison done!");
+ OnProgress(LogManager.Log("Comparison done!"));
return _diffs;
}
@@ -280,14 +285,14 @@ namespace Tango.Synchronization.Remote
/// <param name="config">The configuration.</param>
private void OverrideTable(remote.SYNC_CONFIGURATIONS config)
{
- LogManager.Log("Generating table override difference for " + config.TABLE_NAME + "...");
+ OnProgress(LogManager.Log("Generating table override difference for " + config.TABLE_NAME + "..."));
var master = _remoteDB.GetType().GetProperty(config.TABLE_NAME).GetValue(_remoteDB) as IEnumerable;
var slave = _localDB.GetType().GetProperty(config.TABLE_NAME).GetValue(_localDB) as IEnumerable;
_diffs.Add(new Diff(DiffAction.ReplaceTableDataInSlave, "Override all rows on slave table " + config.TABLE_NAME, () =>
{
- LogManager.Log("Overwriting slave table " + config.TABLE_NAME + "...");
+ OnProgress(LogManager.Log("Overwriting slave table " + config.TABLE_NAME + "..."));
_localDB.Database.ExecuteSqlCommand("DELETE FROM " + config.TABLE_NAME + ";");
@@ -319,7 +324,7 @@ namespace Tango.Synchronization.Remote
{
diff = new Diff(DiffAction.UpdateRowInSlave, "Update row in slave table " + typeof(Master).Name, () =>
{
- LogManager.Log("Updating row in slave table " + typeof(Master).Name);
+ OnProgress(LogManager.Log("Updating row in slave table " + typeof(Master).Name));
CopyEntity(master, slave);
}, null);
}
@@ -327,7 +332,7 @@ namespace Tango.Synchronization.Remote
{
diff = new Diff(DiffAction.UpdateRowInMaster, "Update row in master table " + typeof(Master).Name, () =>
{
- LogManager.Log("Updating row in master table " + typeof(Master).Name);
+ OnProgress(LogManager.Log("Updating row in master table " + typeof(Master).Name));
CopyEntity(slave, master);
}, null);
}
@@ -360,7 +365,7 @@ namespace Tango.Synchronization.Remote
{
_diffs.Add(new Diff(DiffAction.AddRowToSlave, "Add row to slave table " + typeof(Master).Name, () =>
{
- LogManager.Log("Adding row to slave table " + typeof(Master).Name);
+ OnProgress(LogManager.Log("Adding row to slave table " + typeof(Master).Name));
Slave newRow = slaveSet.Create();
CopyEntity(master, newRow);
slaveSet.Add(newRow);
@@ -374,7 +379,7 @@ namespace Tango.Synchronization.Remote
{
_diffs.Add(new Diff(DiffAction.AddRowToMaster, "Add row to master table " + typeof(Master).Name, () =>
{
- LogManager.Log("Adding row to master table " + typeof(Master).Name);
+ OnProgress(LogManager.Log("Adding row to master table " + typeof(Master).Name));
Master newRow = masterSet.Create();
CopyEntity(slave, newRow);
masterSet.Add(newRow);
@@ -389,5 +394,14 @@ namespace Tango.Synchronization.Remote
CompareEntities(master, slave);
}
}
+
+ /// <summary>
+ /// Raises the <see cref="Progress"/> event.
+ /// </summary>
+ /// <returns></returns>
+ protected virtual void OnProgress(String message)
+ {
+ Progress?.Invoke(this, message);
+ }
}
}