aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs')
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs46
1 files changed, 46 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 d713be97b..b817d5dcd 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs
+++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs
@@ -221,7 +221,53 @@ namespace Tango.MachineService.Controllers
return response;
}
+ [HttpPost]
+ public UpdateDBResponse UpdateDB(UpdateDBRequest request)
+ {
+ UpdateDBResponse response = new UpdateDBResponse();
+
+ 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.");
+ }
+
+ 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;
+ }
+
#region Helpers
private void OnError(HttpStatusCode code, String message)