diff options
Diffstat (limited to 'Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs')
| -rw-r--r-- | Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs | 96 |
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) |
