diff options
| author | Roy <roy.mail.net@gmail.com> | 2017-12-02 19:40:22 +0200 |
|---|---|---|
| committer | Roy <roy.mail.net@gmail.com> | 2017-12-02 19:40:22 +0200 |
| commit | c86984f6f012f10649d90b5d7c1786e12526b592 (patch) | |
| tree | 2e78df149406a97cc33fc098b6d05387620b64d8 /Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs | |
| parent | b4f6f50347c758023f4ed86066c78f6d33311052 (diff) | |
| download | Tango-c86984f6f012f10649d90b5d7c1786e12526b592.tar.gz Tango-c86984f6f012f10649d90b5d7c1786e12526b592.zip | |
Working on synchronization...
Diffstat (limited to 'Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs')
| -rw-r--r-- | Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs index ce40e552f..8a4f94159 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs @@ -1,34 +1,44 @@ -using System; +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 async Task<CalculateResponse> Upload(CalculateRequest request) + public SynchronizeDBResponse Synchronize(SynchronizeDBRequest request) { - //if (!Request.Content.IsMimeMultipartContent()) - // throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); + String tempFolder = PathHelper.GetTempFolderPath(); - //var provider = new MultipartMemoryStreamProvider(); - //await Request.Content.ReadAsMultipartAsync(provider); - //foreach (var file in provider.Contents) - //{ - // var filename = file.Headers.ContentDisposition.FileName.Trim('\"'); - // var buffer = await file.ReadAsByteArrayAsync(); - // //Do whatever you want with filename and its binaray data. - //} + String masterSQLiteFile = Path.Combine(tempFolder, "Remote.db"); + String slaveSQLiteFile = Path.Combine(tempFolder, "Local.db"); - //return Ok(); + File.WriteAllBytes(slaveSQLiteFile, request.LocalDB.ToByteArray()); + File.Copy(HostingEnvironment.MapPath(@"~/App_Data/Tango.db"), masterSQLiteFile); - return new CalculateResponse() { Sum = request.A + request.B }; + RemoteDBSynchronizer.Synchronize(masterSQLiteFile, request.SerialNumber); + + LocalDBSynchronizer.Synchronize(masterSQLiteFile, slaveSQLiteFile); + + SynchronizeDBResponse response = new SynchronizeDBResponse(); + response.ResponseDB = ByteString.CopyFrom(File.ReadAllBytes(slaveSQLiteFile)); + + PathHelper.TryDeleteFolder(tempFolder); + + return response; } } } |
