aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2017-11-29 20:37:05 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2017-11-29 20:37:05 +0200
commitcfb92ea5e80b1af847829a76ab3c9ed7f52ae2c4 (patch)
tree10aae33b609f8adc654f00597fcd902faeee8fd9
parent1348ceabdd5d93b78f7f0d9295a5b3424ae93962 (diff)
downloadTango-cfb92ea5e80b1af847829a76ab3c9ed7f52ae2c4.tar.gz
Tango-cfb92ea5e80b1af847829a76ab3c9ed7f52ae2c4.zip
Fixed an issue with boolean values on local DB sync.
Added support for SYNC_CONFIGURATION table on for local DB sync. Fixed an issue with multiple row updates on remote DB sync. Added warning for missing destination property on remote DB sync. Throw exception when no remote machine found on remote DB sync.
-rw-r--r--Software/DB/Tango - Copy.dbbin0 -> 516096 bytes
-rw-r--r--Software/DB/Tango.dbbin516096 -> 516096 bytes
-rw-r--r--Software/DB/Tango.mdfbin8388608 -> 8388608 bytes
-rw-r--r--Software/DB/Tango_log.ldfbin8388608 -> 8388608 bytes
-rw-r--r--Software/Visual_Studio/Tango.DAL.Local/DB/LocalADO.Context.cs1
-rw-r--r--Software/Visual_Studio/Tango.DAL.Local/DB/LocalADO.edmx27
-rw-r--r--Software/Visual_Studio/Tango.DAL.Local/DB/LocalADO.edmx.diagram5
-rw-r--r--Software/Visual_Studio/Tango.DAL.Local/DB/SYNC_CONFIGURATION.cs21
-rw-r--r--Software/Visual_Studio/Tango.DAL.Local/Tango.DAL.Local.csproj3
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/IDBComparer.cs13
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/Local/Constants.cs3
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/Local/ILocalDataBase.cs12
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/Local/LocalDBComparer.cs32
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/Local/SqliteDataBase.cs58
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBComparer.cs53
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/SyncConfiguration.cs (renamed from Software/Visual_Studio/Tango.Synchronization/Remote/SyncConfiguration.cs)2
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/Tango.Synchronization.csproj3
-rw-r--r--Software/Visual_Studio/Tango.UnitTesting/Synchronization_TST.cs4
18 files changed, 215 insertions, 22 deletions
diff --git a/Software/DB/Tango - Copy.db b/Software/DB/Tango - Copy.db
new file mode 100644
index 000000000..a48169790
--- /dev/null
+++ b/Software/DB/Tango - Copy.db
Binary files differ
diff --git a/Software/DB/Tango.db b/Software/DB/Tango.db
index 55feb695e..68ca3633d 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 58a37adb5..0a414f667 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 9157cf6bc..61af9018e 100644
--- a/Software/DB/Tango_log.ldf
+++ b/Software/DB/Tango_log.ldf
Binary files differ
diff --git a/Software/Visual_Studio/Tango.DAL.Local/DB/LocalADO.Context.cs b/Software/Visual_Studio/Tango.DAL.Local/DB/LocalADO.Context.cs
index 272713cc6..f27e0af4d 100644
--- a/Software/Visual_Studio/Tango.DAL.Local/DB/LocalADO.Context.cs
+++ b/Software/Visual_Studio/Tango.DAL.Local/DB/LocalADO.Context.cs
@@ -60,6 +60,7 @@ namespace Tango.DAL.Local.DB
public virtual DbSet<RML> RMLS { get; set; }
public virtual DbSet<ROLE> ROLES { get; set; }
public virtual DbSet<ROLES_PERMISSIONS> ROLES_PERMISSIONS { get; set; }
+ public virtual DbSet<SYNC_CONFIGURATION> SYNC_CONFIGURATION { get; set; }
public virtual DbSet<USER> USERS { get; set; }
public virtual DbSet<USERS_ROLES> USERS_ROLES { get; set; }
}
diff --git a/Software/Visual_Studio/Tango.DAL.Local/DB/LocalADO.edmx b/Software/Visual_Studio/Tango.DAL.Local/DB/LocalADO.edmx
index 87d14f58b..1bd77ac1d 100644
--- a/Software/Visual_Studio/Tango.DAL.Local/DB/LocalADO.edmx
+++ b/Software/Visual_Studio/Tango.DAL.Local/DB/LocalADO.edmx
@@ -401,6 +401,14 @@
<Property Name="ROLE_GUID" Type="nvarchar" MaxLength="2147483647" Nullable="false" />
<Property Name="PERMISSION_GUID" Type="nvarchar" MaxLength="2147483647" Nullable="false" />
</EntityType>
+ <EntityType Name="SYNC_CONFIGURATION">
+ <Key>
+ <PropertyRef Name="ID" />
+ </Key>
+ <Property Name="ID" Type="integer" Nullable="false" />
+ <Property Name="TABLE_NAME" Type="varchar" MaxLength="2147483647" Nullable="false" />
+ <Property Name="SYNC_TYPE" Type="integer" Nullable="false" />
+ </EntityType>
<EntityType Name="USERS">
<Key>
<PropertyRef Name="ID" />
@@ -462,6 +470,7 @@
<EntitySet Name="RMLS" EntityType="Self.RMLS" store:Type="Tables" />
<EntitySet Name="ROLES" EntityType="Self.ROLES" store:Type="Tables" />
<EntitySet Name="ROLES_PERMISSIONS" EntityType="Self.ROLES_PERMISSIONS" store:Type="Tables" />
+ <EntitySet Name="SYNC_CONFIGURATION" EntityType="Self.SYNC_CONFIGURATION" store:Type="Tables" />
<EntitySet Name="USERS" EntityType="Self.USERS" store:Type="Tables" />
<EntitySet Name="USERS_ROLES" EntityType="Self.USERS_ROLES" store:Type="Tables" />
</EntityContainer>
@@ -505,6 +514,7 @@
<EntitySet Name="RMLS" EntityType="LocalModel.RML" />
<EntitySet Name="ROLES" EntityType="LocalModel.ROLE" />
<EntitySet Name="ROLES_PERMISSIONS" EntityType="LocalModel.ROLES_PERMISSIONS" />
+ <EntitySet Name="SYNC_CONFIGURATION" EntityType="LocalModel.SYNC_CONFIGURATION" />
<EntitySet Name="USERS" EntityType="LocalModel.USER" />
<EntitySet Name="USERS_ROLES" EntityType="LocalModel.USERS_ROLES" />
</EntityContainer>
@@ -904,6 +914,14 @@
<Property Name="ROLE_GUID" Type="String" Nullable="false" MaxLength="2147483647" FixedLength="false" Unicode="true" />
<Property Name="PERMISSION_GUID" Type="String" Nullable="false" MaxLength="2147483647" FixedLength="false" Unicode="true" />
</EntityType>
+ <EntityType Name="SYNC_CONFIGURATION">
+ <Key>
+ <PropertyRef Name="ID" />
+ </Key>
+ <Property Name="ID" Type="Int64" Nullable="false" />
+ <Property Name="TABLE_NAME" Type="String" Nullable="false" MaxLength="2147483647" FixedLength="false" Unicode="false" />
+ <Property Name="SYNC_TYPE" Type="Int64" Nullable="false" />
+ </EntityType>
<EntityType Name="USER">
<Key>
<PropertyRef Name="ID" />
@@ -1366,6 +1384,15 @@
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
+ <EntitySetMapping Name="SYNC_CONFIGURATION">
+ <EntityTypeMapping TypeName="LocalModel.SYNC_CONFIGURATION">
+ <MappingFragment StoreEntitySet="SYNC_CONFIGURATION">
+ <ScalarProperty Name="SYNC_TYPE" ColumnName="SYNC_TYPE" />
+ <ScalarProperty Name="TABLE_NAME" ColumnName="TABLE_NAME" />
+ <ScalarProperty Name="ID" ColumnName="ID" />
+ </MappingFragment>
+ </EntityTypeMapping>
+ </EntitySetMapping>
<EntitySetMapping Name="USERS">
<EntityTypeMapping TypeName="LocalModel.USER">
<MappingFragment StoreEntitySet="USERS">
diff --git a/Software/Visual_Studio/Tango.DAL.Local/DB/LocalADO.edmx.diagram b/Software/Visual_Studio/Tango.DAL.Local/DB/LocalADO.edmx.diagram
index b814cf058..1062722a0 100644
--- a/Software/Visual_Studio/Tango.DAL.Local/DB/LocalADO.edmx.diagram
+++ b/Software/Visual_Studio/Tango.DAL.Local/DB/LocalADO.edmx.diagram
@@ -40,8 +40,9 @@
<EntityTypeShape EntityType="LocalModel.RML" Width="1.5" PointX="14.75" PointY="6.75" />
<EntityTypeShape EntityType="LocalModel.ROLE" Width="1.5" PointX="10.75" PointY="14.75" />
<EntityTypeShape EntityType="LocalModel.ROLES_PERMISSIONS" Width="1.5" PointX="14.75" PointY="12.75" />
- <EntityTypeShape EntityType="LocalModel.USER" Width="1.5" PointX="2.75" PointY="15.75" />
- <EntityTypeShape EntityType="LocalModel.USERS_ROLES" Width="1.5" PointX="12.75" PointY="15.75" />
+ <EntityTypeShape EntityType="LocalModel.SYNC_CONFIGURATION" Width="1.5" PointX="2.75" PointY="15.75" />
+ <EntityTypeShape EntityType="LocalModel.USER" Width="1.5" PointX="12.75" PointY="15.75" />
+ <EntityTypeShape EntityType="LocalModel.USERS_ROLES" Width="1.5" PointX="14.75" PointY="15.75" />
</Diagram>
</edmx:Diagrams>
</edmx:Designer>
diff --git a/Software/Visual_Studio/Tango.DAL.Local/DB/SYNC_CONFIGURATION.cs b/Software/Visual_Studio/Tango.DAL.Local/DB/SYNC_CONFIGURATION.cs
new file mode 100644
index 000000000..ab7b23673
--- /dev/null
+++ b/Software/Visual_Studio/Tango.DAL.Local/DB/SYNC_CONFIGURATION.cs
@@ -0,0 +1,21 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated from a template.
+//
+// Manual changes to this file may cause unexpected behavior in your application.
+// Manual changes to this file will be overwritten if the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace Tango.DAL.Local.DB
+{
+ using System;
+ using System.Collections.Generic;
+
+ public partial class SYNC_CONFIGURATION
+ {
+ public long ID { get; set; }
+ public string TABLE_NAME { get; set; }
+ public long SYNC_TYPE { get; set; }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.DAL.Local/Tango.DAL.Local.csproj b/Software/Visual_Studio/Tango.DAL.Local/Tango.DAL.Local.csproj
index 0fced991d..6ffbbc37b 100644
--- a/Software/Visual_Studio/Tango.DAL.Local/Tango.DAL.Local.csproj
+++ b/Software/Visual_Studio/Tango.DAL.Local/Tango.DAL.Local.csproj
@@ -185,6 +185,9 @@
<Compile Include="DB\ROLES_PERMISSIONS.cs">
<DependentUpon>LocalADO.tt</DependentUpon>
</Compile>
+ <Compile Include="DB\SYNC_CONFIGURATION.cs">
+ <DependentUpon>LocalADO.tt</DependentUpon>
+ </Compile>
<Compile Include="DB\USER.cs">
<DependentUpon>LocalADO.tt</DependentUpon>
</Compile>
diff --git a/Software/Visual_Studio/Tango.Synchronization/IDBComparer.cs b/Software/Visual_Studio/Tango.Synchronization/IDBComparer.cs
new file mode 100644
index 000000000..7d7ae4af9
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Synchronization/IDBComparer.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.Synchronization
+{
+ public interface IDBComparer : IDisposable
+ {
+ List<Diff> Compare();
+ }
+}
diff --git a/Software/Visual_Studio/Tango.Synchronization/Local/Constants.cs b/Software/Visual_Studio/Tango.Synchronization/Local/Constants.cs
index ed8084301..5557c43c8 100644
--- a/Software/Visual_Studio/Tango.Synchronization/Local/Constants.cs
+++ b/Software/Visual_Studio/Tango.Synchronization/Local/Constants.cs
@@ -14,6 +14,9 @@ namespace Tango.Synchronization.Local
public const String COLUMN_TYPE = "type";
public const String IS_NOT_NULL = "notnull";
public const String DEFAULT_VALUE = "dflt_value";
+ public const String SYNC_CONFIGURATIONS_TABLE_NAME = "SYNC_CONFIGURATION";
+ public const String SYNC_CONFIGURATION_TABLE_NAME_COLUMN = "TABLE_NAME";
+ public const String SYNC_CONFIGURATION_SYNC_TYPE_COLUMN = "SYNC_TYPE";
//Must Column Names.
diff --git a/Software/Visual_Studio/Tango.Synchronization/Local/ILocalDataBase.cs b/Software/Visual_Studio/Tango.Synchronization/Local/ILocalDataBase.cs
index 7e53aeb1c..66b111467 100644
--- a/Software/Visual_Studio/Tango.Synchronization/Local/ILocalDataBase.cs
+++ b/Software/Visual_Studio/Tango.Synchronization/Local/ILocalDataBase.cs
@@ -37,6 +37,18 @@ namespace Tango.Synchronization.Local
DataTable CloneTableFrom(ILocalDataBase otherDB, DataTable otherTable);
/// <summary>
+ /// Replaces the table data with the data from another table.
+ /// </summary>
+ /// <param name="otherTable">The other table.</param>
+ void ReplaceTableData(ILocalDataBase otherDB, DataTable otherTable);
+
+ /// <summary>
+ /// Replaces the table data with the data from another table.
+ /// </summary>
+ /// <param name="otherTable">The other table.</param>
+ String GetReplaceTableDataCommand(ILocalDataBase otherDB, DataTable otherTable);
+
+ /// <summary>
/// Gets the SQL command for <see cref="CloneTableFrom(ILocalDataBase, DataTable)"/>.
/// </summary>
/// <param name="otherDB">The other database.</param>
diff --git a/Software/Visual_Studio/Tango.Synchronization/Local/LocalDBComparer.cs b/Software/Visual_Studio/Tango.Synchronization/Local/LocalDBComparer.cs
index 63f2ecfaa..7883f9cc8 100644
--- a/Software/Visual_Studio/Tango.Synchronization/Local/LocalDBComparer.cs
+++ b/Software/Visual_Studio/Tango.Synchronization/Local/LocalDBComparer.cs
@@ -13,7 +13,7 @@ namespace Tango.Synchronization.Local
/// Represents an <see cref="ILocalDataBase"/> synchronization engine.
/// </summary>
/// <seealso cref="System.IDisposable" />
- public class LocalDBComparer : IDisposable
+ public class LocalDBComparer : IDBComparer
{
/// <summary>
/// Gets the master SQL.
@@ -52,7 +52,35 @@ namespace Tango.Synchronization.Local
List<Diff> diffs = new List<Diff>();
- foreach (var masterTable in MasterSQL.Tables)
+ DataTable sync_table = MasterSQL.Tables.Single(x => x.TableName == Constants.SYNC_CONFIGURATIONS_TABLE_NAME);
+
+ List<DataTable> sync_tables = new List<DataTable>();
+ List<DataTable> overwrite_tables = new List<DataTable>();
+
+ foreach (var row in sync_table.AsEnumerable())
+ {
+ if ((SyncConfiguration)row.Field<Int64>(Constants.SYNC_CONFIGURATION_SYNC_TYPE_COLUMN) == SyncConfiguration.Synchronize)
+ {
+ sync_tables.Add(MasterSQL.Tables.Single(x => x.TableName == row.Field<String>(Constants.SYNC_CONFIGURATION_TABLE_NAME_COLUMN)));
+ }
+ else
+ {
+ overwrite_tables.Add(MasterSQL.Tables.Single(x => x.TableName == row.Field<String>(Constants.SYNC_CONFIGURATION_TABLE_NAME_COLUMN)));
+ }
+ }
+
+ foreach (var masterTable in overwrite_tables)
+ {
+ LogManager.Log("Generating table overwrite difference for table " + masterTable.TableName);
+ diffs.Add(new Diff(DiffAction.ReplaceTableDataInSlave, "Replace all rows on slave table " + masterTable.TableName, () =>
+ {
+
+ SlaveSQL.ReplaceTableData(MasterSQL, masterTable);
+
+ }, SlaveSQL.GetReplaceTableDataCommand(MasterSQL, masterTable)));
+ }
+
+ foreach (var masterTable in sync_tables)
{
LogManager.Log("Comparing table " + masterTable.TableName);
LogManager.Log("Searching table " + masterTable.TableName + " on slave...");
diff --git a/Software/Visual_Studio/Tango.Synchronization/Local/SqliteDataBase.cs b/Software/Visual_Studio/Tango.Synchronization/Local/SqliteDataBase.cs
index 35e54c66a..83a14b493 100644
--- a/Software/Visual_Studio/Tango.Synchronization/Local/SqliteDataBase.cs
+++ b/Software/Visual_Studio/Tango.Synchronization/Local/SqliteDataBase.cs
@@ -148,6 +148,44 @@ namespace Tango.Synchronization.Local
}
/// <summary>
+ /// Replaces the table data with the data from another table.
+ /// </summary>
+ /// <param name="otherTable">The other table.</param>
+ public void ReplaceTableData(ILocalDataBase otherDB, DataTable otherTable)
+ {
+ var dropCommand = _connection.CreateCommand();
+ dropCommand.CommandText = String.Format("DELETE FROM {0};", otherTable.TableName);
+ dropCommand.ExecuteNonQuery();
+
+ var attacheCommand = _connection.CreateCommand();
+ attacheCommand.CommandText = String.Format("ATTACH DATABASE '{0}' AS other;", otherDB.Source);
+ attacheCommand.ExecuteNonQuery();
+
+ var copyCommand = _connection.CreateCommand();
+ copyCommand.CommandText = String.Format("INSERT INTO main.{0} SELECT * FROM {1}.{0};", otherTable.TableName, "other");
+ copyCommand.ExecuteNonQuery();
+
+ var detacheCommand = _connection.CreateCommand();
+ detacheCommand.CommandText = "DETACH other;";
+ detacheCommand.ExecuteNonQuery();
+ }
+
+ /// <summary>
+ /// Gets the SQL command for <see cref="ReplaceTableData(ILocalDataBase, DataTable)"/>.
+ /// </summary>
+ /// <param name="otherDB"></param>
+ /// <param name="otherTable">The other table.</param>
+ /// <returns></returns>
+ public string GetReplaceTableDataCommand(ILocalDataBase otherDB, DataTable otherTable)
+ {
+ String cmd = String.Format("DELETE FROM {0};", otherTable.TableName) + Environment.NewLine;
+ cmd += String.Format("ATTACH DATABASE '{0}' AS other;", otherDB.Source) + Environment.NewLine;
+ cmd += String.Format("INSERT INTO main.{0} SELECT * FROM {1}.{0};", otherTable.TableName, "other") + Environment.NewLine;
+ cmd += "DETACH other;" + Environment.NewLine;
+ return cmd;
+ }
+
+ /// <summary>
/// Gets the SQL command for <see cref="CloneTableFrom(ILocalDataBase, DataTable)" />.
/// </summary>
/// <param name="otherDB">The other database.</param>
@@ -252,6 +290,11 @@ namespace Tango.Synchronization.Local
double num = 0;
+ if (row.ItemArray[i].GetType() == typeof(bool))
+ {
+ value = ((bool)row.ItemArray[i]) ? 1.ToString() : 0.ToString();
+ }
+
if (row.ItemArray[i].GetType() == typeof(DateTime))
{
value = ((DateTime)row.ItemArray[i]).ToSQLiteDateString();
@@ -288,6 +331,11 @@ namespace Tango.Synchronization.Local
double num = 0;
+ if (row.ItemArray[i].GetType() == typeof(bool))
+ {
+ value = ((bool)row.ItemArray[i]) ? 1.ToString() : 0.ToString();
+ }
+
if (row.ItemArray[i].GetType() == typeof(DateTime))
{
value = ((DateTime)row.ItemArray[i]).ToSQLiteDateString();
@@ -322,6 +370,11 @@ namespace Tango.Synchronization.Local
double num = 0;
+ if (row.ItemArray[i].GetType() == typeof(bool))
+ {
+ value = ((bool)row.ItemArray[i]) ? 1.ToString() : 0.ToString();
+ }
+
if (row.ItemArray[i].GetType() == typeof(DateTime))
{
value = ((DateTime)row.ItemArray[i]).ToSQLiteDateString();
@@ -382,6 +435,11 @@ namespace Tango.Synchronization.Local
double num = 0;
+ if (row.ItemArray[i].GetType() == typeof(bool))
+ {
+ value = ((bool)row.ItemArray[i]) ? 1.ToString() : 0.ToString();
+ }
+
if (row.ItemArray[i].GetType() == typeof(DateTime))
{
value = ((DateTime)row.ItemArray[i]).ToSQLiteDateString();
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);
diff --git a/Software/Visual_Studio/Tango.Synchronization/Remote/SyncConfiguration.cs b/Software/Visual_Studio/Tango.Synchronization/SyncConfiguration.cs
index 7e5a60f07..6082db15b 100644
--- a/Software/Visual_Studio/Tango.Synchronization/Remote/SyncConfiguration.cs
+++ b/Software/Visual_Studio/Tango.Synchronization/SyncConfiguration.cs
@@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
-namespace Tango.Synchronization.Remote
+namespace Tango.Synchronization
{
public enum SyncConfiguration
{
diff --git a/Software/Visual_Studio/Tango.Synchronization/Tango.Synchronization.csproj b/Software/Visual_Studio/Tango.Synchronization/Tango.Synchronization.csproj
index 97227a183..36719516a 100644
--- a/Software/Visual_Studio/Tango.Synchronization/Tango.Synchronization.csproj
+++ b/Software/Visual_Studio/Tango.Synchronization/Tango.Synchronization.csproj
@@ -65,6 +65,7 @@
<Link>GlobalVersionInfo.cs</Link>
</Compile>
<Compile Include="DataBaseComparisonException.cs" />
+ <Compile Include="IDBComparer.cs" />
<Compile Include="Local\Constants.cs" />
<Compile Include="Local\ExtensionMethods.cs" />
<Compile Include="Local\ILocalDataBase.cs" />
@@ -74,7 +75,7 @@
<Compile Include="DiffAction.cs" />
<Compile Include="Local\SQLiteDataBase.cs" />
<Compile Include="Remote\RemoteDBComparer.cs" />
- <Compile Include="Remote\SyncConfiguration.cs" />
+ <Compile Include="SyncConfiguration.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
diff --git a/Software/Visual_Studio/Tango.UnitTesting/Synchronization_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/Synchronization_TST.cs
index bf8360258..a5b29b413 100644
--- a/Software/Visual_Studio/Tango.UnitTesting/Synchronization_TST.cs
+++ b/Software/Visual_Studio/Tango.UnitTesting/Synchronization_TST.cs
@@ -17,6 +17,8 @@ namespace Tango.UnitTesting
[TestMethod]
public void Compare_Remote_And_Local()
{
+ var console = Helper.InitializeLogging(true);
+
using (var remoteDB = new remote.RemoteDB("LOCALHOST\\SQLEXPRESS", false))
{
using (var localDB = new local.LocalDB(Helper.GetSQLiteFilePath()))
@@ -33,6 +35,8 @@ namespace Tango.UnitTesting
localDB.SaveChanges();
}
}
+
+ console.WaitForConsoleExit().Wait();
}
[TestMethod]