aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs
diff options
context:
space:
mode:
authorShlomo Hecht <shlomo@twine-s.com>2018-08-08 18:45:09 +0300
committerShlomo Hecht <shlomo@twine-s.com>2018-08-08 18:45:09 +0300
commit965a7bd752315653d710d16651f34d66d4d80d0a (patch)
tree957a2a8844f1ce848c98df987c3911bae9bb0d52 /Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs
parent6456de92a4f6d2f9e6367e92ebefd9b49d578952 (diff)
parenta5f9c99d51f7e096ff612da6605ab4d4f5067009 (diff)
downloadTango-965a7bd752315653d710d16651f34d66d4d80d0a.tar.gz
Tango-965a7bd752315653d710d16651f34d66d4d80d0a.zip
Merge branch 'master' of https://twinetfs.visualstudio.com/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs')
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs80
1 files changed, 80 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
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
}
}