From 9c5f5c1351c78536b54df2c90742efae19f00b59 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 8 Aug 2018 17:28:34 +0300 Subject: Working on PPC machine setup ! --- .../Controllers/SynchronizationController.cs | 80 ++++++++++++++++++++++ 1 file changed, 80 insertions(+) (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 index 28d0cd3f1..aed78f1a6 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs @@ -1,6 +1,7 @@ using Google.Protobuf; using System; using System.Collections.Generic; +using System.Configuration; using System.IO; using System.Linq; using System.Net; @@ -8,6 +9,7 @@ using System.Net.Http; using System.Threading.Tasks; using System.Web.Hosting; using System.Web.Http; +using Tango.BL; using Tango.Core.Helpers; using Tango.Core.IO; using Tango.PMR.Stubs; @@ -64,5 +66,83 @@ namespace Tango.MachineService.Controllers tempFolder.Delete(); } } + + [HttpPost] + public MachineSetupResponse MachineSetup(MachineSetupRequest request) + { + MachineSetupResponse response = new MachineSetupResponse(); + + try + { + using (ObservablesContext db = ObservablesContext.CreateDefault(GetLocalServerAddress())) + { + db.Configuration.LazyLoadingEnabled = false; + String serial_number = request.SerialNumber; + + var machine = db.Machines.SingleOrDefault(x => x.SerialNumber == serial_number); + + if (machine == null) + { + OnError(HttpStatusCode.NotFound, "The specified serial number could not be found."); + } + + var configuration = db.Configurations.SingleOrDefault(x => x.Guid == machine.ConfigurationGuid); + + var appVersion = db.ApplicationVersions.SingleOrDefault(x => x.Guid == configuration.ApplicationVersionGuid); + var embeddedVersion = db.EmbeddedSoftwareVersions.SingleOrDefault(x => x.Guid == configuration.EmbeddedSoftwareVersionGuid); + + response.ApplicationVersion = appVersion.Version; + response.ApplicationFtpFilePath = appVersion.FtpFilePath; + + response.EmbeddedVersion = embeddedVersion.Version; + response.EmbeddedFtpFilePath = embeddedVersion.FtpFilePath; + + response.DbAddress = GetRemoteServerAddress(); + response.FtpAddress = GetFtpAddress(); + response.UserName = GetFtpUserName(); + response.Password = GetFtpPassword(); + } + } + catch (Exception ex) + { + OnError(HttpStatusCode.InternalServerError, ex.Message); + } + + return response; + } + + #region Helpers + + private void OnError(HttpStatusCode code, String message) + { + throw new HttpResponseException(Request.CreateErrorResponse(code, message)); + } + + private String GetLocalServerAddress() + { + return ConfigurationManager.AppSettings["LocalServerAddress"].ToString(); + } + + private String GetRemoteServerAddress() + { + return ConfigurationManager.AppSettings["RemoteServerAddress"].ToString(); + } + + private String GetFtpAddress() + { + return ConfigurationManager.AppSettings["FtpAddress"].ToString(); + } + + private String GetFtpUserName() + { + return ConfigurationManager.AppSettings["FtpUserName"].ToString(); + } + + private String GetFtpPassword() + { + return ConfigurationManager.AppSettings["FtpPassword"].ToString(); + } + + #endregion } } -- cgit v1.3.1