diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2017-12-03 10:29:17 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2017-12-03 10:29:17 +0200 |
| commit | 05c7e42a8ce55a21c94338febad593bfbf638655 (patch) | |
| tree | 5465475f3565da1b724f4cd9bfcc0eb3b67fd167 /Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs | |
| parent | 3a70d596ada24ad6f92f729d564ab29c3e249f06 (diff) | |
| download | Tango-05c7e42a8ce55a21c94338febad593bfbf638655.tar.gz Tango-05c7e42a8ce55a21c94338febad593bfbf638655.zip | |
MERGE
Diffstat (limited to 'Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs')
| -rw-r--r-- | Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs new file mode 100644 index 000000000..fd87815c9 --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs @@ -0,0 +1,47 @@ +using Google.Protobuf; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Threading.Tasks; +using System.Web.Hosting; +using System.Web.Http; +using Tango.Core.Helpers; +using Tango.PMR.Stubs; +using Tango.PMR.Synchronization; +using Tango.Synchronization.Local; +using Tango.Synchronization.Remote; + +namespace Tango.MachineService.Controllers +{ + public class SynchronizationController : ApiController + { + [HttpPost] + public SynchronizeDBResponse Synchronize(SynchronizeDBRequest request) + { + String tempFolder = PathHelper.GetTempFolderPath(); + + String masterSQLiteFile = Path.Combine(tempFolder, "Remote.db"); + String slaveSQLiteFile = Path.Combine(tempFolder, "Local.db"); + + File.WriteAllBytes(slaveSQLiteFile, request.LocalDB.ToByteArray()); + + + + File.Copy(HostingEnvironment.MapPath(@"~/App_Data/Tango.db"), masterSQLiteFile); + + RemoteDBSynchronizer.Synchronize(masterSQLiteFile, request.SerialNumber); + + LocalDBSynchronizer.Synchronize(masterSQLiteFile, slaveSQLiteFile); + + SynchronizeDBResponse response = new SynchronizeDBResponse(); + response.RemoteDB = ByteString.CopyFrom(File.ReadAllBytes(slaveSQLiteFile)); + + PathHelper.TryDeleteFolder(tempFolder); + + return response; + } + } +} |
