aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Synchronization/Remote
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/Remote
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/Remote')
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBComparer.cs120
1 files changed, 67 insertions, 53 deletions
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);
+ }
}
}