diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2017-12-03 18:00:19 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2017-12-03 18:00:19 +0200 |
| commit | f637e76b2557021217424c2944321029b6c50513 (patch) | |
| tree | bb359cada5cb0b6ef9c3deda3a5762f9a474c989 /Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs | |
| parent | 57b770f73356e27a5f9189faf2f1953f6340430d (diff) | |
| download | Tango-f637e76b2557021217424c2944321029b6c50513.tar.gz Tango-f637e76b2557021217424c2944321029b6c50513.zip | |
Added code documentation to android project.
Removed all test modules except for UnitTesting module.
Remote <-> Local DB synchronization works from android to WebAPI !
Diffstat (limited to 'Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs')
| -rw-r--r-- | Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs index fd87815c9..8540863c0 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs @@ -23,25 +23,40 @@ namespace Tango.MachineService.Controllers { String tempFolder = PathHelper.GetTempFolderPath(); - String masterSQLiteFile = Path.Combine(tempFolder, "Remote.db"); - String slaveSQLiteFile = Path.Combine(tempFolder, "Local.db"); + try + { + //File path for the reflected remote data base SQLite. + String masterSQLiteFile = Path.Combine(tempFolder, "Remote.db"); + //File path for the received machine SQLite db. + String slaveSQLiteFile = Path.Combine(tempFolder, "Local.db"); - File.WriteAllBytes(slaveSQLiteFile, request.LocalDB.ToByteArray()); + //Save the machine db to file. + File.WriteAllBytes(slaveSQLiteFile, request.LocalDB.ToByteArray()); - + //Copy an SQLite db template. + File.Copy(HostingEnvironment.MapPath(@"~/App_Data/Tango.db"), masterSQLiteFile); - File.Copy(HostingEnvironment.MapPath(@"~/App_Data/Tango.db"), masterSQLiteFile); + //Synchronize the SQL Server db with the new SQLite template. (Overwrite basically) + RemoteDBSynchronizer.Synchronize(masterSQLiteFile, request.SerialNumber); - RemoteDBSynchronizer.Synchronize(masterSQLiteFile, request.SerialNumber); + //Synchronize the received machine db with the filled template. + LocalDBSynchronizer.Synchronize(masterSQLiteFile, slaveSQLiteFile); - LocalDBSynchronizer.Synchronize(masterSQLiteFile, slaveSQLiteFile); + //Send the synchronized machine db to the machine to the machine. + SynchronizeDBResponse response = new SynchronizeDBResponse(); + response.RemoteDB = ByteString.CopyFrom(File.ReadAllBytes(slaveSQLiteFile)); - SynchronizeDBResponse response = new SynchronizeDBResponse(); - response.RemoteDB = ByteString.CopyFrom(File.ReadAllBytes(slaveSQLiteFile)); - - PathHelper.TryDeleteFolder(tempFolder); - - return response; + return response; + } + catch (Exception) + { + throw; + } + finally + { + //Remove all temporary files and folder. + PathHelper.TryDeleteFolder(tempFolder); + } } } } |
