From 05c7e42a8ce55a21c94338febad593bfbf638655 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 3 Dec 2017 10:29:17 +0200 Subject: MERGE --- .../Controllers/SynchronizationController.cs | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs (limited to 'Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs') 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; + } + } +} -- cgit v1.3.1