From d1fa1f1a2e26469a6bbb5b82ab614079beffcb52 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 14 Jan 2018 13:19:03 +0200 Subject: Added code comments for: Synchronization. --- .../DataBaseComparisonException.cs | 8 ++++ .../Visual_Studio/Tango.Synchronization/Diff.cs | 20 ++++---- .../Tango.Synchronization/DiffAction.cs | 2 +- .../Tango.Synchronization/IDBComparer.cs | 8 ++++ .../Tango.Synchronization/Local/Constants.cs | 3 ++ .../Local/ExtensionMethods.cs | 3 ++ .../Tango.Synchronization/Local/ILocalDataBase.cs | 5 ++ .../Local/LocalDBSynchronizer.cs | 15 ++++++ .../Tango.Synchronization/Local/SqliteDataBase.cs | 3 ++ .../Remote/RemoteDBComparer.cs | 53 ++++++++++++++++++++++ .../Remote/RemoteDBSynchronizer.cs | 17 +++++++ .../Tango.Synchronization/SyncConfiguration.cs | 9 ++++ 12 files changed, 135 insertions(+), 11 deletions(-) (limited to 'Software/Visual_Studio/Tango.Synchronization') 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 { + /// + /// Represents a database comparison exception. + /// + /// public class DataBaseComparisonException : Exception { + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. 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 { /// - /// Represents an result. + /// Represents an result. /// public class Diff { private Action _action; /// - /// Gets the difference action. + /// Gets the action which will be taken in order to commit this difference. /// public DiffAction Action { get; private set; } @@ -24,27 +24,27 @@ namespace Tango.Synchronization public String Description { get; private set; } /// - /// Gets the command. + /// Gets the SQL command. /// public String Command { get; private set; } /// /// Initializes a new instance of the class. /// - /// The data base action. - /// The description. - /// The action. - /// The command. - public Diff(DiffAction dataBaseAction, String description, Action action, String command) + /// The difference action type. + /// The action description. + /// The action delegate. + /// The SQL command. + public Diff(DiffAction diffAction, String description, Action action, String command) { - Action = dataBaseAction; + Action = diffAction; Description = description; _action = action; Command = command; } /// - /// Commits the difference to the target DB. + /// Commits this difference to the target DB. /// 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 { /// - /// Represents the type of . + /// Represents the available types of actions. /// 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 { + /// + /// Represents a database comparison engine. + /// + /// public interface IDBComparer : IDisposable { + /// + /// Performs a database comparison and returns a set of differences. + /// + /// List 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 { + /// + /// Contains Tango database synchronization convention constants. + /// 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 { + /// + /// Contains Database comparison and synchronization extension methods. + /// internal static class SQLExtensions { /// 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 /// The row. /// String GetUpdateRowCommand(DataTable table, DataRow row); + + /// + /// Clears the data base. + /// + 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 { + /// + /// Represents an SQLite to SQLite file synchronizer. + /// public class LocalDBSynchronizer { + /// + /// Synchronizes the specified master and slave SQLite files. + /// + /// The master SQLite file. + /// The slave SQLite file. + /// public static List Synchronize(String masterSQLiteFile, String slaveSQLiteFile) { using (LocalDBComparer comparer = new LocalDBComparer(new SQLiteDataBase(masterSQLiteFile), new SQLiteDataBase(slaveSQLiteFile))) @@ -22,6 +31,12 @@ namespace Tango.Synchronization.Local } } + /// + /// Synchronizes the specified master and slave SQLite files asynchronously. + /// + /// The master SQLite file. + /// The slave SQLite file. + /// public static Task> SynchronizeAsync(String masterSQLiteFile, String slaveSQLiteFile) { return Task.Factory.StartNew>(() => { 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; } + /// + /// Clears the data base. + /// 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 { + /// + /// Represents a Remote database to SQLite database comparison engine. + /// + /// public class RemoteDBComparer : IDBComparer { private remote.RemoteDB _remoteDB; @@ -18,6 +22,12 @@ namespace Tango.Synchronization.Remote private String _machineSerial; private List _diffs; + /// + /// Initializes a new instance of the class. + /// + /// The remote database. + /// The local database. + /// The machine serial number. public RemoteDBComparer(remote.RemoteDB remoteDB, local.LocalDB localDB, String machineSerial) { _machineSerial = machineSerial; @@ -25,6 +35,11 @@ namespace Tango.Synchronization.Remote _localDB = localDB; } + /// + /// Performs a database comparison and returns a set of differences. + /// + /// + /// Could not locate machine on remote server " + _machineSerial public List Compare() { _diffs = new List(); @@ -164,12 +179,21 @@ namespace Tango.Synchronization.Remote return _diffs; } + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// public void Dispose() { _remoteDB.Dispose(); _localDB.Dispose(); } + /// + /// Copies source entity properties to the destination entity. + /// + /// The source entity. + /// The destination entity. + /// 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 } } + /// + /// Compares a collection of source entities to a collection of destination entities. + /// + /// The type of the aster. + /// The type of the lave. + /// The master collection. + /// The slave collection. + /// The master set. + /// The slave set. private void CompareCollections(List masterCollection, List slaveCollection, DbSet masterSet, DbSet slaveSet) where Master : class where Slave : class { var slaveProp = typeof(Slave).GetProperty("GUID"); @@ -214,6 +247,10 @@ namespace Tango.Synchronization.Remote } } + /// + /// Overrides the table by the specified synchronization configuration. + /// + /// The configuration. 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)); } + /// + /// Compares the specified entities. + /// + /// The type of the master. + /// The type of the slave. + /// The master. + /// The slave. private void CompareEntities(Master master, Slave slave) where Master : class where Slave : class { Diff diff = null; @@ -267,6 +311,15 @@ namespace Tango.Synchronization.Remote } } + /// + /// Compares the entities. + /// + /// The type of the master. + /// The type of the slave. + /// The master. + /// The slave. + /// The master set. + /// The slave set. private void CompareEntities(Master master, Slave slave, DbSet masterSet, DbSet 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 { + /// + /// Represents a remote database to SQLite file synchronizer. + /// public class RemoteDBSynchronizer { + /// + /// Synchronizes the specified SQLite file by a machine serial number. + /// + /// The SQLite database file. + /// The machine serial number. + /// if set to true will erase the SQLite file before performing the synchronization. + /// public static List Synchronize(String sqliteDbFile, String serialNumber, bool overrideLocal = false) { if (overrideLocal) @@ -41,6 +51,13 @@ namespace Tango.Synchronization.Remote } } + /// + /// Synchronizes the specified SQLite file by a machine serial number. + /// + /// The SQLite database file. + /// The machine serial number. + /// if set to true will erase the SQLite file before performing the synchronization. + /// public static Task> SynchronizeAsync(String sqliteDBFile, String serialNumber, bool overrideLocal = false) { return Task.Factory.StartNew>(() => 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 { + /// + /// Represents a table synchronization configuration. + /// public enum SyncConfiguration { + /// + /// Removes all rows in the target DB and inserts all rows from source. + /// OverwriteLocal, + /// + /// Synchronize (Insert, Update) rows by LAST_UPDATED field. + /// Synchronize, } } -- cgit v1.3.1