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-30 19:04:18 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-08-30 19:04:18 +0300
commit37e5138e6acac4a9b93e018087fe9c50d36c4b34 (patch)
tree4acec95a8e5362c67f0e0fc5444c40c23791776d /Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs
parent3d9beda13daccac78fb05dc94d1430a0a47e9db6 (diff)
downloadTango-37e5138e6acac4a9b93e018087fe9c50d36c4b34.tar.gz
Tango-37e5138e6acac4a9b93e018087fe9c50d36c4b34.zip
Implemented machine update on PPC !!!
Need to verify update scripts...
Diffstat (limited to 'Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs')
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs96
1 files changed, 96 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 8054aae8c..e4e01e7d1 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs
+++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs
@@ -125,6 +125,102 @@ namespace Tango.MachineService.Controllers
return response;
}
+ [HttpPost]
+ public DownloadUpdateResponse MachineUpdate(DownloadUpdateRequest request)
+ {
+ DownloadUpdateResponse response = new DownloadUpdateResponse();
+
+ 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 machine_version = db.MachineVersions.SingleOrDefault(x => x.Guid == machine.MachineVersionGuid);
+
+ var latest_machine_version = db.TangoVersions.Where(x => x.MachineVersionGuid == machine_version.Guid).ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault();
+
+ response.Version = latest_machine_version.Version;
+
+ response.FtpAddress = GetFtpAddress();
+ response.FtpFilePath = latest_machine_version.FtpFilePath;
+ response.FtpUserName = GetFtpUserName();
+ response.FtpPassword = GetFtpPassword();
+
+ DbCredentials credentials = new DbCredentials();
+
+ using (DbManager manager = DbManager.FromAddressAndName(GetDbAddress(), "Tango"))
+ {
+ credentials = manager.CreateRandomLoginAndUser("Tango");
+
+ Task.Delay(TimeSpan.FromMinutes(10)).ContinueWith((x) =>
+ {
+ using (DbManager m = DbManager.FromAddressAndName(GetDbAddress(), "Tango"))
+ {
+ m.DeleteLoginAndUser(credentials.UserName, "Tango");
+ }
+ });
+ }
+
+ response.DbAddress = GetDbAddress();
+ response.DbUserName = credentials.UserName;
+ response.DbPassword = credentials.Password;
+ }
+ }
+ catch (Exception ex)
+ {
+ OnError(HttpStatusCode.InternalServerError, ex.Message);
+ }
+
+ return response;
+ }
+
+ [HttpPost]
+ public CheckForUpdateResponse CheckForUpdate(CheckForUpdateRequest request)
+ {
+ CheckForUpdateResponse response = new CheckForUpdateResponse();
+
+ try
+ {
+ using (ObservablesContext db = ObservablesContext.CreateDefault(GetLocalServerAddress()))
+ {
+ db.Configuration.LazyLoadingEnabled = false;
+
+ var machine = db.Machines.SingleOrDefault(x => x.SerialNumber == request.SerialNumber);
+
+ if (machine == null)
+ {
+ OnError(HttpStatusCode.NotFound, "The specified serial number could not be found.");
+ }
+
+ var machine_version = db.MachineVersions.SingleOrDefault(x => x.Guid == machine.MachineVersionGuid);
+
+ var latest_machine_version = db.TangoVersions.Where(x => x.MachineVersionGuid == machine_version.Guid).ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault();
+
+ if (Version.Parse(latest_machine_version.Version) > Version.Parse(request.Version))
+ {
+ response.IsUpdateAvailable = true;
+ }
+
+ response.Version = latest_machine_version.Version;
+ }
+ }
+ catch (Exception ex)
+ {
+ OnError(HttpStatusCode.InternalServerError, ex.Message);
+ }
+
+ return response;
+ }
+
#region Helpers
private void OnError(HttpStatusCode code, String message)