diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2018-08-13 15:47:59 +0300 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2018-08-13 15:47:59 +0300 |
| commit | c6864d03caa002d590dbe2abc43a931b26fc7b27 (patch) | |
| tree | b066b7307aab9af7fd76de4bf26795434fd0ee5e /Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs | |
| parent | ba3d7e34700be27d5eed1c2a58f6cd146296fd95 (diff) | |
| parent | fe8111ccce920b73b47b6af657f1ee4bcac11120 (diff) | |
| download | Tango-c6864d03caa002d590dbe2abc43a931b26fc7b27.tar.gz Tango-c6864d03caa002d590dbe2abc43a931b26fc7b27.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_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.cs | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs index aed78f1a6..8054aae8c 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using System.Web.Hosting; using System.Web.Http; using Tango.BL; +using Tango.Core.DB; using Tango.Core.Helpers; using Tango.Core.IO; using Tango.PMR.Stubs; @@ -80,27 +81,40 @@ namespace Tango.MachineService.Controllers String serial_number = request.SerialNumber; var machine = db.Machines.SingleOrDefault(x => x.SerialNumber == serial_number); + var machine_version = db.MachineVersions.SingleOrDefault(x => x.Guid == machine.MachineVersionGuid); 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 latest_machine_version = db.TangoVersions.Where(x => x.MachineVersionGuid == machine_version.Guid).ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); - var appVersion = db.ApplicationVersions.SingleOrDefault(x => x.Guid == configuration.ApplicationVersionGuid); - var embeddedVersion = db.EmbeddedSoftwareVersions.SingleOrDefault(x => x.Guid == configuration.EmbeddedSoftwareVersionGuid); + response.Version = latest_machine_version.Version; - response.ApplicationVersion = appVersion.Version; - response.ApplicationFtpFilePath = appVersion.FtpFilePath; + response.FtpAddress = GetFtpAddress(); + response.FtpFilePath = latest_machine_version.FtpFilePath; + response.FtpUserName = GetFtpUserName(); + response.FtpPassword = GetFtpPassword(); - response.EmbeddedVersion = embeddedVersion.Version; - response.EmbeddedFtpFilePath = embeddedVersion.FtpFilePath; + DbCredentials credentials = new DbCredentials(); - response.DbAddress = GetRemoteServerAddress(); - response.FtpAddress = GetFtpAddress(); - response.UserName = GetFtpUserName(); - response.Password = GetFtpPassword(); + 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) @@ -123,9 +137,9 @@ namespace Tango.MachineService.Controllers return ConfigurationManager.AppSettings["LocalServerAddress"].ToString(); } - private String GetRemoteServerAddress() + private String GetDbAddress() { - return ConfigurationManager.AppSettings["RemoteServerAddress"].ToString(); + return ConfigurationManager.AppSettings["DbAddress"].ToString(); } private String GetFtpAddress() @@ -141,7 +155,7 @@ namespace Tango.MachineService.Controllers private String GetFtpPassword() { return ConfigurationManager.AppSettings["FtpPassword"].ToString(); - } + } #endregion } |
