aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Synchronization
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-01-14 13:19:03 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-01-14 13:19:03 +0200
commitd1fa1f1a2e26469a6bbb5b82ab614079beffcb52 (patch)
tree5823e82075a6bd9c932457f79a6269395d45fe23 /Software/Visual_Studio/Tango.Synchronization
parentdd4560b79e305772debf48cc76c9ba67af61f259 (diff)
downloadTango-d1fa1f1a2e26469a6bbb5b82ab614079beffcb52.tar.gz
Tango-d1fa1f1a2e26469a6bbb5b82ab614079beffcb52.zip
Added code comments for:
Synchronization.
Diffstat (limited to 'Software/Visual_Studio/Tango.Synchronization')
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/DataBaseComparisonException.cs8
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/Diff.cs20
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/DiffAction.cs2
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/IDBComparer.cs8
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/Local/Constants.cs3
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/Local/ExtensionMethods.cs3
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/Local/ILocalDataBase.cs5
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/Local/LocalDBSynchronizer.cs15
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/Local/SqliteDataBase.cs3
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBComparer.cs53
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBSynchronizer.cs17
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/SyncConfiguration.cs9
12 files changed, 135 insertions, 11 deletions
diff --git a/Software/Visual_Studio/Tango.Synchronization/DataBaseComparisonException.cs b/Software/Visual_Studio/Tango.Synchronization/DataBaseComparisonException.cs
index 1606c3aaa..5ffaeb36b 100644
--- a/Software/Visual_Studio/Tango.Synchronization/DataBaseComparisonException.cs
+++ b/Software/Visual_Studio/Tango.Synchronization/DataBaseComparisonException.cs
@@ -6,8 +6,16 @@ using System.Threading.Tasks;
namespace Tango.Synchronization
{
+ /// <summary>
+ /// Represents a database comparison exception.
+ /// </summary>
+ /// <seealso cref="System.Exception" />
public class DataBaseComparisonException : Exception
{
+ /// <summary>
+ /// Initializes a new instance of the <see cref="DataBaseComparisonException"/> class.
+ /// </summary>
+ /// <param name="message">The message that describes the error.</param>
public DataBaseComparisonException(String message) : base(message)
{
diff --git a/Software/Visual_Studio/Tango.Synchronization/Diff.cs b/Software/Visual_Studio/Tango.Synchronization/Diff.cs
index 45bd1581c..1ae3541e8 100644
--- a/Software/Visual_Studio/Tango.Synchronization/Diff.cs
+++ b/Software/Visual_Studio/Tango.Synchronization/Diff.cs
@@ -7,14 +7,14 @@ using System.Threading.Tasks;
namespace Tango.Synchronization
{
/// <summary>
- /// Represents an <see cref="LocalDBComparer.Compare"/> result.
+ /// Represents an <see cref="IDBComparer.Compare"/> result.
/// </summary>
public class Diff
{
private Action _action;
/// <summary>
- /// Gets the difference action.
+ /// Gets the action which will be taken in order to commit this difference.
/// </summary>
public DiffAction Action { get; private set; }
@@ -24,27 +24,27 @@ namespace Tango.Synchronization
public String Description { get; private set; }
/// <summary>
- /// Gets the <see cref="Commit"/> command.
+ /// Gets the <see cref="Commit"/> SQL command.
/// </summary>
public String Command { get; private set; }
/// <summary>
/// Initializes a new instance of the <see cref="Diff"/> class.
/// </summary>
- /// <param name="dataBaseAction">The data base action.</param>
- /// <param name="description">The description.</param>
- /// <param name="action">The action.</param>
- /// <param name="command">The command.</param>
- public Diff(DiffAction dataBaseAction, String description, Action action, String command)
+ /// <param name="diffAction">The difference action type.</param>
+ /// <param name="description">The action description.</param>
+ /// <param name="action">The action delegate.</param>
+ /// <param name="command">The SQL command.</param>
+ public Diff(DiffAction diffAction, String description, Action action, String command)
{
- Action = dataBaseAction;
+ Action = diffAction;
Description = description;
_action = action;
Command = command;
}
/// <summary>
- /// Commits the difference to the target DB.
+ /// Commits this difference to the target DB.
/// </summary>
public void Commit()
{
diff --git a/Software/Visual_Studio/Tango.Synchronization/DiffAction.cs b/Software/Visual_Studio/Tango.Synchronization/DiffAction.cs
index 087cbfa79..41991eecb 100644
--- a/Software/Visual_Studio/Tango.Synchronization/DiffAction.cs
+++ b/Software/Visual_Studio/Tango.Synchronization/DiffAction.cs
@@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace Tango.Synchronization
{
/// <summary>
- /// Represents the type of <see cref="Diff"/>.
+ /// Represents the available types of <see cref="Diff"/> actions.
/// </summary>
public enum DiffAction
{
diff --git a/Software/Visual_Studio/Tango.Synchronization/IDBComparer.cs b/Software/Visual_Studio/Tango.Synchronization/IDBComparer.cs
index 7d7ae4af9..05a955002 100644
--- a/Software/Visual_Studio/Tango.Synchronization/IDBComparer.cs
+++ b/Software/Visual_Studio/Tango.Synchronization/IDBComparer.cs
@@ -6,8 +6,16 @@ using System.Threading.Tasks;
namespace Tango.Synchronization
{
+ /// <summary>
+ /// Represents a database comparison engine.
+ /// </summary>
+ /// <seealso cref="System.IDisposable" />
public interface IDBComparer : IDisposable
{
+ /// <summary>
+ /// Performs a database comparison and returns a set of differences.
+ /// </summary>
+ /// <returns></returns>
List<Diff> Compare();
}
}
diff --git a/Software/Visual_Studio/Tango.Synchronization/Local/Constants.cs b/Software/Visual_Studio/Tango.Synchronization/Local/Constants.cs
index a1494243c..c5e974be3 100644
--- a/Software/Visual_Studio/Tango.Synchronization/Local/Constants.cs
+++ b/Software/Visual_Studio/Tango.Synchronization/Local/Constants.cs
@@ -6,6 +6,9 @@ using System.Threading.Tasks;
namespace Tango.Synchronization.Local
{
+ /// <summary>
+ /// Contains Tango database synchronization convention constants.
+ /// </summary>
internal static class Constants
{
//SQLite Internal Constants
diff --git a/Software/Visual_Studio/Tango.Synchronization/Local/ExtensionMethods.cs b/Software/Visual_Studio/Tango.Synchronization/Local/ExtensionMethods.cs
index 89b3969e4..f2e0e9b00 100644
--- a/Software/Visual_Studio/Tango.Synchronization/Local/ExtensionMethods.cs
+++ b/Software/Visual_Studio/Tango.Synchronization/Local/ExtensionMethods.cs
@@ -8,6 +8,9 @@ using System.Threading.Tasks;
namespace Tango.Synchronization.Local
{
+ /// <summary>
+ /// Contains Database comparison and synchronization extension methods.
+ /// </summary>
internal static class SQLExtensions
{
/// <summary>
diff --git a/Software/Visual_Studio/Tango.Synchronization/Local/ILocalDataBase.cs b/Software/Visual_Studio/Tango.Synchronization/Local/ILocalDataBase.cs
index 66b111467..a435bea97 100644
--- a/Software/Visual_Studio/Tango.Synchronization/Local/ILocalDataBase.cs
+++ b/Software/Visual_Studio/Tango.Synchronization/Local/ILocalDataBase.cs
@@ -101,5 +101,10 @@ namespace Tango.Synchronization.Local
/// <param name="row">The row.</param>
/// <returns></returns>
String GetUpdateRowCommand(DataTable table, DataRow row);
+
+ /// <summary>
+ /// Clears the data base.
+ /// </summary>
+ void ClearDataBase();
}
}
diff --git a/Software/Visual_Studio/Tango.Synchronization/Local/LocalDBSynchronizer.cs b/Software/Visual_Studio/Tango.Synchronization/Local/LocalDBSynchronizer.cs
index c7b6900d6..7e654c161 100644
--- a/Software/Visual_Studio/Tango.Synchronization/Local/LocalDBSynchronizer.cs
+++ b/Software/Visual_Studio/Tango.Synchronization/Local/LocalDBSynchronizer.cs
@@ -6,8 +6,17 @@ using System.Threading.Tasks;
namespace Tango.Synchronization.Local
{
+ /// <summary>
+ /// Represents an SQLite to SQLite file synchronizer.
+ /// </summary>
public class LocalDBSynchronizer
{
+ /// <summary>
+ /// Synchronizes the specified master and slave SQLite files.
+ /// </summary>
+ /// <param name="masterSQLiteFile">The master SQLite file.</param>
+ /// <param name="slaveSQLiteFile">The slave SQLite file.</param>
+ /// <returns></returns>
public static List<Diff> Synchronize(String masterSQLiteFile, String slaveSQLiteFile)
{
using (LocalDBComparer comparer = new LocalDBComparer(new SQLiteDataBase(masterSQLiteFile), new SQLiteDataBase(slaveSQLiteFile)))
@@ -22,6 +31,12 @@ namespace Tango.Synchronization.Local
}
}
+ /// <summary>
+ /// Synchronizes the specified master and slave SQLite files asynchronously.
+ /// </summary>
+ /// <param name="masterSQLiteFile">The master SQLite file.</param>
+ /// <param name="slaveSQLiteFile">The slave SQLite file.</param>
+ /// <returns></returns>
public static Task<List<Diff>> SynchronizeAsync(String masterSQLiteFile, String slaveSQLiteFile)
{
return Task.Factory.StartNew<List<Diff>>(() => { return Synchronize(masterSQLiteFile, slaveSQLiteFile); });
diff --git a/Software/Visual_Studio/Tango.Synchronization/Local/SqliteDataBase.cs b/Software/Visual_Studio/Tango.Synchronization/Local/SqliteDataBase.cs
index 2596853c6..8e2656a98 100644
--- a/Software/Visual_Studio/Tango.Synchronization/Local/SqliteDataBase.cs
+++ b/Software/Visual_Studio/Tango.Synchronization/Local/SqliteDataBase.cs
@@ -100,6 +100,9 @@ namespace Tango.Synchronization.Local
return table;
}
+ /// <summary>
+ /// Clears the data base.
+ /// </summary>
public void ClearDataBase()
{
foreach (var table in Tables)
diff --git a/Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBComparer.cs b/Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBComparer.cs
index 5985eb393..3d9667676 100644
--- a/Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBComparer.cs
+++ b/Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBComparer.cs
@@ -11,6 +11,10 @@ using System.Collections;
namespace Tango.Synchronization.Remote
{
+ /// <summary>
+ /// Represents a Remote database to SQLite database comparison engine.
+ /// </summary>
+ /// <seealso cref="Tango.Synchronization.IDBComparer" />
public class RemoteDBComparer : IDBComparer
{
private remote.RemoteDB _remoteDB;
@@ -18,6 +22,12 @@ namespace Tango.Synchronization.Remote
private String _machineSerial;
private List<Diff> _diffs;
+ /// <summary>
+ /// Initializes a new instance of the <see cref="RemoteDBComparer"/> class.
+ /// </summary>
+ /// <param name="remoteDB">The remote database.</param>
+ /// <param name="localDB">The local database.</param>
+ /// <param name="machineSerial">The machine serial number.</param>
public RemoteDBComparer(remote.RemoteDB remoteDB, local.LocalDB localDB, String machineSerial)
{
_machineSerial = machineSerial;
@@ -25,6 +35,11 @@ namespace Tango.Synchronization.Remote
_localDB = localDB;
}
+ /// <summary>
+ /// Performs a database comparison and returns a set of differences.
+ /// </summary>
+ /// <returns></returns>
+ /// <exception cref="Tango.Synchronization.DataBaseComparisonException">Could not locate machine on remote server " + _machineSerial</exception>
public List<Diff> Compare()
{
_diffs = new List<Diff>();
@@ -164,12 +179,21 @@ namespace Tango.Synchronization.Remote
return _diffs;
}
+ /// <summary>
+ /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ /// </summary>
public void Dispose()
{
_remoteDB.Dispose();
_localDB.Dispose();
}
+ /// <summary>
+ /// Copies source entity properties to the destination entity.
+ /// </summary>
+ /// <param name="source">The source entity.</param>
+ /// <param name="destination">The destination entity.</param>
+ /// <exception cref="InvalidOperationException"></exception>
private void CopyEntity(Object source, Object destination)
{
foreach (var prop in source.GetType().GetProperties().Where(x => x.PropertyType.IsPrimitive || x.PropertyType == typeof(String) || x.PropertyType == typeof(DateTime) || x.PropertyType == typeof(byte[])))
@@ -190,6 +214,15 @@ namespace Tango.Synchronization.Remote
}
}
+ /// <summary>
+ /// Compares a collection of source entities to a collection of destination entities.
+ /// </summary>
+ /// <typeparam name="Master">The type of the aster.</typeparam>
+ /// <typeparam name="Slave">The type of the lave.</typeparam>
+ /// <param name="masterCollection">The master collection.</param>
+ /// <param name="slaveCollection">The slave collection.</param>
+ /// <param name="masterSet">The master set.</param>
+ /// <param name="slaveSet">The slave set.</param>
private void CompareCollections<Master, Slave>(List<Master> masterCollection, List<Slave> slaveCollection, DbSet<Master> masterSet, DbSet<Slave> slaveSet) where Master : class where Slave : class
{
var slaveProp = typeof(Slave).GetProperty("GUID");
@@ -214,6 +247,10 @@ namespace Tango.Synchronization.Remote
}
}
+ /// <summary>
+ /// Overrides the table by the specified synchronization configuration.
+ /// </summary>
+ /// <param name="config">The configuration.</param>
private void OverrideTable(remote.SYNC_CONFIGURATIONS config)
{
LogManager.Log("Generating table override difference for " + config.TABLE_NAME + "...");
@@ -237,6 +274,13 @@ namespace Tango.Synchronization.Remote
}, null));
}
+ /// <summary>
+ /// Compares the specified entities.
+ /// </summary>
+ /// <typeparam name="Master">The type of the master.</typeparam>
+ /// <typeparam name="Slave">The type of the slave.</typeparam>
+ /// <param name="master">The master.</param>
+ /// <param name="slave">The slave.</param>
private void CompareEntities<Master, Slave>(Master master, Slave slave) where Master : class where Slave : class
{
Diff diff = null;
@@ -267,6 +311,15 @@ namespace Tango.Synchronization.Remote
}
}
+ /// <summary>
+ /// Compares the entities.
+ /// </summary>
+ /// <typeparam name="Master">The type of the master.</typeparam>
+ /// <typeparam name="Slave">The type of the slave.</typeparam>
+ /// <param name="master">The master.</param>
+ /// <param name="slave">The slave.</param>
+ /// <param name="masterSet">The master set.</param>
+ /// <param name="slaveSet">The slave set.</param>
private void CompareEntities<Master, Slave>(Master master, Slave slave, DbSet<Master> masterSet, DbSet<Slave> slaveSet) where Master : class where Slave : class
{
if (slave == null)
diff --git a/Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBSynchronizer.cs b/Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBSynchronizer.cs
index 7abd8ad7e..75d28af5b 100644
--- a/Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBSynchronizer.cs
+++ b/Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBSynchronizer.cs
@@ -10,8 +10,18 @@ using Tango.Synchronization.Local;
namespace Tango.Synchronization.Remote
{
+ /// <summary>
+ /// Represents a remote database to SQLite file synchronizer.
+ /// </summary>
public class RemoteDBSynchronizer
{
+ /// <summary>
+ /// Synchronizes the specified SQLite file by a machine serial number.
+ /// </summary>
+ /// <param name="sqliteDbFile">The SQLite database file.</param>
+ /// <param name="serialNumber">The machine serial number.</param>
+ /// <param name="overrideLocal">if set to <c>true</c> will erase the SQLite file before performing the synchronization.</param>
+ /// <returns></returns>
public static List<Diff> Synchronize(String sqliteDbFile, String serialNumber, bool overrideLocal = false)
{
if (overrideLocal)
@@ -41,6 +51,13 @@ namespace Tango.Synchronization.Remote
}
}
+ /// <summary>
+ /// Synchronizes the specified SQLite file by a machine serial number.
+ /// </summary>
+ /// <param name="sqliteDbFile">The SQLite database file.</param>
+ /// <param name="serialNumber">The machine serial number.</param>
+ /// <param name="overrideLocal">if set to <c>true</c> will erase the SQLite file before performing the synchronization.</param>
+ /// <returns></returns>
public static Task<List<Diff>> SynchronizeAsync(String sqliteDBFile, String serialNumber, bool overrideLocal = false)
{
return Task.Factory.StartNew<List<Diff>>(() =>
diff --git a/Software/Visual_Studio/Tango.Synchronization/SyncConfiguration.cs b/Software/Visual_Studio/Tango.Synchronization/SyncConfiguration.cs
index 6082db15b..2262796b9 100644
--- a/Software/Visual_Studio/Tango.Synchronization/SyncConfiguration.cs
+++ b/Software/Visual_Studio/Tango.Synchronization/SyncConfiguration.cs
@@ -6,9 +6,18 @@ using System.Threading.Tasks;
namespace Tango.Synchronization
{
+ /// <summary>
+ /// Represents a table synchronization configuration.
+ /// </summary>
public enum SyncConfiguration
{
+ /// <summary>
+ /// Removes all rows in the target DB and inserts all rows from source.
+ /// </summary>
OverwriteLocal,
+ /// <summary>
+ /// Synchronize (Insert, Update) rows by LAST_UPDATED field.
+ /// </summary>
Synchronize,
}
}