aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-08-08 17:28:34 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-08-08 17:28:34 +0300
commit9c5f5c1351c78536b54df2c90742efae19f00b59 (patch)
tree53e23d42955ed6c0926995a75305fd61112c5c87 /Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs
parent57ae9d131e898a35061507bc8497bcf648cf00d1 (diff)
downloadTango-9c5f5c1351c78536b54df2c90742efae19f00b59.tar.gz
Tango-9c5f5c1351c78536b54df2c90742efae19f00b59.zip
Working on PPC machine setup !
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
}
}