aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBComparer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBComparer.cs')
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBComparer.cs53
1 files changed, 37 insertions, 16 deletions
diff --git a/Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBComparer.cs b/Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBComparer.cs
index 49555f75c..0bd76dbd1 100644
--- a/Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBComparer.cs
+++ b/Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBComparer.cs
@@ -11,7 +11,7 @@ using System.Collections;
namespace Tango.Synchronization.Remote
{
- public class RemoteDBComparer : IDisposable
+ public class RemoteDBComparer : IDBComparer
{
private remote.RemoteDB _remoteDB;
private local.LocalDB _localDB;
@@ -65,6 +65,11 @@ namespace Tango.Synchronization.Remote
LogManager.Log("Querying all remote machines...");
var remote_machines = _remoteDB.MACHINES.Where(x => x.SERIAL_NUMBER == _machineSerial).ToList();
+ if (remote_machines.Count == 0)
+ {
+ throw LogManager.Log(new DataBaseComparisonException("Could not locate machine on remote server " + _machineSerial));
+ }
+
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();
@@ -114,7 +119,7 @@ namespace Tango.Synchronization.Remote
}
- LogManager.Log("Comparing addresses tables");
+ LogManager.Log("Comparing addresses");
CompareCollections(remote_addresses, local_addresses, _remoteDB.ADDRESSES, _localDB.ADDRESSES);
LogManager.Log("Comparing cartridges");
@@ -150,6 +155,8 @@ namespace Tango.Synchronization.Remote
LogManager.Log("Comparing users roles");
CompareCollections(remote_users_roles, local_users_roles, _remoteDB.USERS_ROLES, _localDB.USERS_ROLES);
+ LogManager.Log("Comparison done!");
+
return _diffs;
}
@@ -163,6 +170,12 @@ namespace Tango.Synchronization.Remote
{
foreach (var prop in source.GetType().GetProperties().Where(x => x.PropertyType.IsPrimitive || x.PropertyType == typeof(String) || x.PropertyType == typeof(DateTime)))
{
+ if (destination.GetType().GetProperty(prop.Name) == null)
+ {
+ LogManager.Log(String.Format("Warning: property {0} not found on destination entity {1}!", prop.Name, destination.GetType().Name));
+ continue;
+ }
+
if (prop.PropertyType == typeof(Int64))
{
destination.GetType().GetProperty(prop.Name).SetValue(destination, Convert.ToInt32((Int64)prop.GetValue(source)));
@@ -179,25 +192,25 @@ namespace Tango.Synchronization.Remote
var slaveProp = typeof(Slave).GetProperty("GUID");
var masterProp = typeof(Master).GetProperty("GUID");
+ List<Slave> compared = new List<Slave>();
+
foreach (var masterRow in masterCollection)
{
- CompareEntities(masterRow, slaveCollection.SingleOrDefault(x => slaveProp.GetValue(x).ToString() == masterProp.GetValue(masterRow).ToString()), masterSet, slaveSet);
+ Slave slaveRow = slaveCollection.SingleOrDefault(x => slaveProp.GetValue(x).ToString() == masterProp.GetValue(masterRow).ToString());
+ CompareEntities(masterRow, slaveRow, masterSet, slaveSet);
+
+ if (slaveRow != null)
+ {
+ compared.Add(slaveRow);
+ }
}
- foreach (var slaveRow in slaveCollection)
+ foreach (var slaveRow in slaveCollection.Where(x => !compared.Contains(x)))
{
CompareEntities(masterCollection.SingleOrDefault(x => masterProp.GetValue(x).ToString() == slaveProp.GetValue(slaveRow).ToString()), slaveRow, masterSet, slaveSet);
}
}
- //private Destination TransferEntity<Source, Destination>(Source entity, List<Destination> destinationSet) where Source : class where Destination : class
- //{
- // var cloned = Activator.CreateInstance<Destination>();
- // CopyEntity(entity, cloned);
- // destinationSet.Add(cloned);
- // return cloned;
- //}
-
private void OverrideTable(remote.SYNC_CONFIGURATION config)
{
LogManager.Log("Generating table override difference for " + config.TABLE_NAME + "...");
@@ -230,11 +243,19 @@ namespace Tango.Synchronization.Remote
if (masterDate > slaveDate)
{
- diff = new Diff(DiffAction.UpdateRowInSlave, "Update row in slave table " + typeof(Master).Name, () => CopyEntity(master, slave), null);
+ diff = new Diff(DiffAction.UpdateRowInSlave, "Update row in slave table " + typeof(Master).Name, () =>
+ {
+ LogManager.Log("Updating row in slave table " + typeof(Master).Name);
+ CopyEntity(master, slave);
+ }, null);
}
else if (slaveDate > masterDate)
{
- diff = new Diff(DiffAction.UpdateRowInMaster, "Update row in master table " + typeof(Master).Name, () => CopyEntity(slave, master), null);
+ diff = new Diff(DiffAction.UpdateRowInMaster, "Update row in master table " + typeof(Master).Name, () =>
+ {
+ LogManager.Log("Updating row in master table " + typeof(Master).Name);
+ CopyEntity(slave, master);
+ }, null);
}
if (diff != null)
@@ -249,7 +270,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);
Slave newRow = slaveSet.Create();
CopyEntity(master, newRow);
slaveSet.Add(newRow);
@@ -263,7 +284,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);
Master newRow = masterSet.Create();
CopyEntity(slave, newRow);
masterSet.Add(newRow);