aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Synchronization/Local
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 /Software/Visual_Studio/Tango.Synchronization/Local
parent6e082b1d9d7b4c5888e7e7345e148eb944b8c624 (diff)
downloadTango-bd63d7d2f7769e5534fb9a58d97358564c2cb674.tar.gz
Tango-bd63d7d2f7769e5534fb9a58d97358564c2cb674.zip
Implemented progress text on DB Comparers instead of custom logger.
Diffstat (limited to 'Software/Visual_Studio/Tango.Synchronization/Local')
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/Local/LocalDBComparer.cs72
1 files changed, 41 insertions, 31 deletions
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>