aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Web/Tango.MachineService
diff options
context:
space:
mode:
authorAvi Levkovich <avi@twine-s.com>2019-12-17 14:37:38 +0200
committerAvi Levkovich <avi@twine-s.com>2019-12-17 14:37:38 +0200
commit8a7e65715ef393a08cc39d1b5d4a3da22799c852 (patch)
treef71065b4c0000aafad1356ff2ab6b17f8287476b /Software/Visual_Studio/Web/Tango.MachineService
parentc653fa2077b6118c2ace3b7bcc8bc91c9a9ed4f5 (diff)
parent3ed7e9cc55e10888d84aa53abcb5e765a317ddb1 (diff)
downloadTango-8a7e65715ef393a08cc39d1b5d4a3da22799c852.tar.gz
Tango-8a7e65715ef393a08cc39d1b5d4a3da22799c852.zip
merge conflicts
Diffstat (limited to 'Software/Visual_Studio/Web/Tango.MachineService')
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs86
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs440
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs1
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Models/PPCPendingUpdate.cs13
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj3
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Web.config8
6 files changed, 543 insertions, 8 deletions
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs
index dd8401570..da5ce16f7 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs
+++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs
@@ -23,6 +23,10 @@ using Tango.Web.ActiveDirectory;
using Tango.MachineService.Filters;
using Tango.MachineService.Security;
using Tango.Web.SQLServer;
+using Tango.Core;
+using Tango.Web.SMO;
+using Tango.Core.DB;
+using System.Threading.Tasks;
namespace Tango.MachineService.Controllers
{
@@ -99,6 +103,11 @@ namespace Tango.MachineService.Controllers
response.BlobAddress = blob.GenerateReadSignature(TimeSpan.FromMinutes(60));
+ if (!String.IsNullOrWhiteSpace(MachineServiceConfig.CDN_ENDPOINT))
+ {
+ response.CdnAddress = MachineServiceConfig.CDN_ENDPOINT + blob.Uri.AbsolutePath;
+ }
+
response.IsUpdateAvailable = true;
response.Version = latestVersion.Version;
response.Comments = latestVersion.Comments;
@@ -133,6 +142,11 @@ namespace Tango.MachineService.Controllers
var container = manager.GetContainer(MachineServiceConfig.MACHINE_STUDIO_VERSIONS_CONTAINER);
var blob = container.GetBlockBlobReference(latestVersion.BlobName);
+ if (!String.IsNullOrWhiteSpace(MachineServiceConfig.CDN_ENDPOINT))
+ {
+ response.CdnAddress = MachineServiceConfig.CDN_ENDPOINT + blob.Uri.AbsolutePath;
+ }
+
response.BlobAddress = blob.GenerateReadSignature(TimeSpan.FromMinutes(60));
response.Version = latestVersion.Version;
}
@@ -271,7 +285,16 @@ namespace Tango.MachineService.Controllers
[HttpPost]
public LoginResponse Login(LoginRequest request)
{
- var authResult = _ad_manager.ValidateUserCredentials(request.Email, request.Password);
+ AuthenticationResult authResult = null;
+
+ try
+ {
+ authResult = _ad_manager.ValidateUserCredentials(request.Email, request.Password);
+ }
+ catch (Exception ex)
+ {
+ throw new AuthenticationException(ex.FlattenMessage());
+ }
if (!_ad_manager.CanUserAccessCurrentEnvironment(request.Email))
{
@@ -415,6 +438,67 @@ namespace Tango.MachineService.Controllers
};
}
+ [HttpPost]
+ [JwtTokenFilter]
+ public DownloadLatestPPCVersionResponse DownloadLatestPPCVersion(DownloadLatestPPCVersionRequest request)
+ {
+ DownloadLatestPPCVersionResponse response = new DownloadLatestPPCVersionResponse();
+
+ using (ObservablesContext db = ObservablesContextHelper.CreateContext())
+ {
+ var machine = db.Machines.SingleOrDefault(x => x.SerialNumber == request.SerialNumber);
+
+ if (machine == null)
+ {
+ throw new AuthenticationException("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;
+
+ var manager = new BlobStorageManager();
+ var container = manager.GetContainer(MachineServiceConfig.TANGO_VERSIONS_CONTAINER);
+ var blob = container.GetBlockBlobReference(latest_machine_version.BlobName);
+
+ response.BlobAddress = blob.GenerateReadSignature(TimeSpan.FromMinutes(60));
+
+ if (!String.IsNullOrWhiteSpace(MachineServiceConfig.CDN_ENDPOINT))
+ {
+ response.CdnAddress = MachineServiceConfig.CDN_ENDPOINT + blob.Uri.AbsolutePath;
+ }
+
+ DbCredentials credentials = new DbCredentials();
+
+ using (SmoManager smo = new SmoManager())
+ {
+ credentials = smo.CreateRandomLoginAndUser();
+
+ Task.Delay(TimeSpan.FromMinutes(PPCController.SQL_TEMP_CREDENTIALS_EXP_MINUTS)).ContinueWith((x) =>
+ {
+ using (SmoManager m = new SmoManager())
+ {
+ m.DeleteLoginAndUser(credentials.UserName);
+ }
+ });
+ }
+
+ response.DataSource = new DataSource()
+ {
+ Address = MachineServiceConfig.DB_ADDRESS,
+ Catalog = MachineServiceConfig.DB_CATALOG,
+ UserName = credentials.UserName,
+ Password = credentials.Password,
+ IntegratedSecurity = false,
+ Type = DataSourceType.SQLServer,
+ };
+ }
+
+ return response;
+ }
+
#endregion
}
}
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs
index a77212787..10a732221 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs
+++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs
@@ -30,7 +30,9 @@ namespace Tango.MachineService.Controllers
public class PPCController : TangoController<PPCController.TokenObject>
{
private static List<PPCPendingUpload> _pendingUploads;
+ private static List<PPCPendingUpdate> _pendingUpdates;
private ActiveDirectoryManager _ad_manager;
+ public const int SQL_TEMP_CREDENTIALS_EXP_MINUTS = 20;
public class TokenObject
{
@@ -44,6 +46,7 @@ namespace Tango.MachineService.Controllers
static PPCController()
{
_pendingUploads = new List<PPCPendingUpload>();
+ _pendingUpdates = new List<PPCPendingUpdate>();
}
public PPCController()
@@ -60,6 +63,7 @@ namespace Tango.MachineService.Controllers
public MachineSetupResponse MachineSetup(MachineSetupRequest request)
{
MachineSetupResponse response = new MachineSetupResponse();
+ response.NotifyCompletedToken = Guid.NewGuid().ToString();
LogManager.Log("Setup request received: " + request.ToString());
@@ -98,13 +102,12 @@ namespace Tango.MachineService.Controllers
machine.DeviceId = request.DeviceID;
machine.IsDeviceRegistered = true;
- db.SaveChanges();
-
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.FirmwareVersion = latest_machine_version.FirmwareVersion;
var manager = new BlobStorageManager();
var container = manager.GetContainer(MachineServiceConfig.TANGO_VERSIONS_CONTAINER);
@@ -112,13 +115,18 @@ namespace Tango.MachineService.Controllers
response.BlobAddress = blob.GenerateReadSignature(TimeSpan.FromMinutes(60));
+ if (!String.IsNullOrWhiteSpace(MachineServiceConfig.CDN_ENDPOINT))
+ {
+ response.CdnAddress = MachineServiceConfig.CDN_ENDPOINT + blob.Uri.AbsolutePath;
+ }
+
DbCredentials credentials = new DbCredentials();
using (SmoManager smo = new SmoManager())
{
credentials = smo.CreateRandomLoginAndUser();
- Task.Delay(TimeSpan.FromMinutes(10)).ContinueWith((x) =>
+ Task.Delay(TimeSpan.FromMinutes(SQL_TEMP_CREDENTIALS_EXP_MINUTS)).ContinueWith((x) =>
{
using (SmoManager m = new SmoManager())
{
@@ -143,6 +151,22 @@ namespace Tango.MachineService.Controllers
response.SetupUWF = machine.SetupUwf;
response.SetupFirmware = machine.SetupFirmware;
response.IsDemo = machine.IsDemo;
+
+ TangoUpdate tangoUpdate = new TangoUpdate();
+ tangoUpdate.ApplicationVersion = latest_machine_version.Version;
+ tangoUpdate.FirmwareVersion = latest_machine_version.FirmwareVersion;
+ tangoUpdate.MachineGuid = machine.Guid;
+ tangoUpdate.StartDate = DateTime.UtcNow;
+ tangoUpdate.UpdateStatus = TangoUpdateStatuses.SetupStarted;
+ db.TangoUpdates.Add(tangoUpdate);
+
+ db.SaveChanges();
+
+ _pendingUpdates.Add(new PPCPendingUpdate()
+ {
+ Token = response.NotifyCompletedToken,
+ TangoUpdateGuid = tangoUpdate.Guid,
+ });
}
return response;
@@ -153,6 +177,7 @@ namespace Tango.MachineService.Controllers
public DownloadUpdateResponse MachineUpdate(DownloadUpdateRequest request)
{
DownloadUpdateResponse response = new DownloadUpdateResponse();
+ response.NotifyCompletedToken = Guid.NewGuid().ToString();
using (ObservablesContext db = ObservablesContextHelper.CreateContext())
{
@@ -171,6 +196,7 @@ namespace Tango.MachineService.Controllers
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.FirmwareVersion = latest_machine_version.FirmwareVersion;
var manager = new BlobStorageManager();
var container = manager.GetContainer(MachineServiceConfig.TANGO_VERSIONS_CONTAINER);
@@ -178,13 +204,18 @@ namespace Tango.MachineService.Controllers
response.BlobAddress = blob.GenerateReadSignature(TimeSpan.FromMinutes(60));
+ if (!String.IsNullOrWhiteSpace(MachineServiceConfig.CDN_ENDPOINT))
+ {
+ response.CdnAddress = MachineServiceConfig.CDN_ENDPOINT + blob.Uri.AbsolutePath;
+ }
+
DbCredentials credentials = new DbCredentials();
using (SmoManager smo = new SmoManager())
{
credentials = smo.CreateRandomLoginAndUser();
- Task.Delay(TimeSpan.FromMinutes(10)).ContinueWith((x) =>
+ Task.Delay(TimeSpan.FromMinutes(SQL_TEMP_CREDENTIALS_EXP_MINUTS)).ContinueWith((x) =>
{
using (SmoManager m = new SmoManager())
{
@@ -202,6 +233,22 @@ namespace Tango.MachineService.Controllers
IntegratedSecurity = false,
Type = DataSourceType.SQLServer,
};
+
+ TangoUpdate tangoUpdate = new TangoUpdate();
+ tangoUpdate.ApplicationVersion = latest_machine_version.Version;
+ tangoUpdate.FirmwareVersion = latest_machine_version.FirmwareVersion;
+ tangoUpdate.MachineGuid = machine.Guid;
+ tangoUpdate.StartDate = DateTime.UtcNow;
+ tangoUpdate.UpdateStatus = TangoUpdateStatuses.UpdateStarted;
+ db.TangoUpdates.Add(tangoUpdate);
+
+ db.SaveChanges();
+
+ _pendingUpdates.Add(new PPCPendingUpdate()
+ {
+ Token = response.NotifyCompletedToken,
+ TangoUpdateGuid = tangoUpdate.Guid,
+ });
}
return response;
@@ -209,6 +256,40 @@ namespace Tango.MachineService.Controllers
[HttpPost]
[JwtTokenFilter]
+ public MachineUpdateCompletedResponse NotifyUpdateCompleted(MachineUpdateCompletedRequest request)
+ {
+ var pendingUpdate = _pendingUpdates.SingleOrDefault(x => x.Token == request.Token);
+ if (pendingUpdate != null)
+ {
+ _pendingUpdates.Remove(pendingUpdate);
+
+ using (ObservablesContext db = ObservablesContextHelper.CreateContext())
+ {
+ var tangoUpdate = db.TangoUpdates.SingleOrDefault(x => x.Guid == pendingUpdate.TangoUpdateGuid);
+
+ if (tangoUpdate != null)
+ {
+ tangoUpdate.LastUpdated = DateTime.UtcNow;
+ tangoUpdate.UpdateStatus = request.Status;
+ tangoUpdate.EndDate = DateTime.UtcNow;
+ tangoUpdate.FailedReason = request.FailedReason;
+ tangoUpdate.FailedLog = request.FailedLog;
+
+ if (request.ReportsAboutDbCheckNoDifferences)
+ {
+ db.TangoUpdates.Remove(tangoUpdate);
+ }
+
+ db.SaveChanges();
+ }
+ }
+ }
+
+ return new MachineUpdateCompletedResponse();
+ }
+
+ [HttpPost]
+ [JwtTokenFilter]
public CheckForUpdateResponse CheckForUpdates(CheckForUpdateRequest request)
{
CheckForUpdateResponse response = new CheckForUpdateResponse();
@@ -239,6 +320,40 @@ namespace Tango.MachineService.Controllers
}
response.Version = latest_machine_version.Version;
+ response.FirmwareVersion = latest_machine_version.FirmwareVersion;
+
+ //Compare database
+
+ var rmls = db.Rmls.Select(x => new { x.Guid, x.LastUpdated }).ToList();
+ var hardwareVersions = db.HardwareVersions.Select(x => new { x.Guid, x.LastUpdated }).ToList();
+ var catalogs = db.ColorCatalogs.Select(x => new { x.Guid, x.LastUpdated }).ToList();
+
+ bool hasDatabaseUpdates = false;
+
+ hasDatabaseUpdates = machine.LastUpdated > request.MachineLastUpdated;
+
+ if (!hasDatabaseUpdates)
+ {
+ hasDatabaseUpdates = rmls.Exists(x => request.Rmls.Exists(y => x.Guid == y.Guid && x.LastUpdated > y.LastUpdated) || !request.Rmls.Exists(y => x.Guid == y.Guid));
+ }
+
+ if (!hasDatabaseUpdates)
+ {
+ hasDatabaseUpdates = hardwareVersions.Exists(x => request.HardwareVersions.Exists(y => x.Guid == y.Guid && x.LastUpdated > y.LastUpdated) || !request.HardwareVersions.Exists(y => x.Guid == y.Guid));
+ }
+
+ if (!hasDatabaseUpdates)
+ {
+ hasDatabaseUpdates = catalogs.Exists(x => request.Catalogs.Exists(y => x.Guid == y.Guid && x.LastUpdated > y.LastUpdated) || !request.Catalogs.Exists(y => x.Guid == y.Guid));
+ }
+
+ if (hasDatabaseUpdates)
+ {
+ response.IsDatabaseUpdateAvailable = true;
+ response.UpdateDBResponse = UpdateDB(new UpdateDBRequest() { SerialNumber = request.SerialNumber });
+ }
+
+ //Compare database
if (machine.ForceVersionUpdate)
{
@@ -255,6 +370,7 @@ namespace Tango.MachineService.Controllers
public UpdateDBResponse UpdateDB(UpdateDBRequest request)
{
UpdateDBResponse response = new UpdateDBResponse();
+ response.NotifyCompletedToken = Guid.NewGuid().ToString();
using (ObservablesContext db = ObservablesContextHelper.CreateContext())
{
@@ -276,7 +392,7 @@ namespace Tango.MachineService.Controllers
{
credentials = manager.CreateRandomLoginAndUser();
- Task.Delay(TimeSpan.FromMinutes(10)).ContinueWith((x) =>
+ Task.Delay(TimeSpan.FromMinutes(SQL_TEMP_CREDENTIALS_EXP_MINUTS)).ContinueWith((x) =>
{
using (SmoManager m = new SmoManager())
{
@@ -294,6 +410,320 @@ namespace Tango.MachineService.Controllers
IntegratedSecurity = false,
Type = DataSourceType.SQLServer,
};
+
+ TangoUpdate tangoUpdate = new TangoUpdate();
+ tangoUpdate.ApplicationVersion = request.ApplicationVersion;
+ tangoUpdate.FirmwareVersion = request.FirmwareVersion;
+ tangoUpdate.MachineGuid = machine.Guid;
+ tangoUpdate.StartDate = DateTime.UtcNow;
+ tangoUpdate.UpdateStatus = TangoUpdateStatuses.DatabaseStarted;
+ db.TangoUpdates.Add(tangoUpdate);
+
+ db.SaveChanges();
+
+ _pendingUpdates.Add(new PPCPendingUpdate()
+ {
+ Token = response.NotifyCompletedToken,
+ TangoUpdateGuid = tangoUpdate.Guid,
+ });
+ }
+
+ return response;
+ }
+
+ #endregion
+
+ #region Synchronization
+
+ [HttpPost]
+ [JwtTokenFilter]
+ public UploadMachineDataResponse UploadMachineData(UploadMachineDataRequest request)
+ {
+ UploadMachineDataResponse response = new UploadMachineDataResponse();
+ response.NotifyCompletedToken = Guid.NewGuid().ToString();
+
+ using (ObservablesContext db = ObservablesContextHelper.CreateContext())
+ {
+ var machine = db.Machines.SingleOrDefault(x => x.Guid == RequestToken.Object.MachineGuid);
+
+ if (machine == null)
+ {
+ throw new AuthenticationException("The specified machine could not be found.");
+ }
+
+ TangoUpdate tangoUpdate = new TangoUpdate();
+ tangoUpdate.ApplicationVersion = request.ApplicationVersion;
+ tangoUpdate.FirmwareVersion = request.FirmwareVersion;
+ tangoUpdate.MachineGuid = machine.Guid;
+ tangoUpdate.StartDate = DateTime.UtcNow;
+ tangoUpdate.UpdateStatus = TangoUpdateStatuses.SynchronizationStarted;
+ db.TangoUpdates.Add(tangoUpdate);
+ db.SaveChanges();
+
+ _pendingUpdates.Add(new PPCPendingUpdate()
+ {
+ Token = response.NotifyCompletedToken,
+ TangoUpdateGuid = tangoUpdate.Guid,
+ });
+ }
+
+ User machineUser = null;
+
+ try
+ {
+ using (ObservablesContext db = ObservablesContextHelper.CreateContext())
+ {
+ var machine = db.Machines.SingleOrDefault(x => x.Guid == RequestToken.Object.MachineGuid);
+
+ if (machine == null)
+ {
+ throw new AuthenticationException("The specified machine could not be found.");
+ }
+
+ machineUser = db.Users.Include(x => x.Contact).SingleOrDefault(x => x.Contact.FirstName == machine.Name);
+
+ if (machineUser == null)
+ {
+ //No machine user then create one.
+ machineUser = new User();
+ machineUser.Email = machine.SerialNumber + "@twine-s.com";
+ machineUser.Password = machine.SerialNumber;
+ machineUser.OrganizationGuid = machine.OrganizationGuid;
+ machineUser.Contact = new Contact();
+ machineUser.Contact.Email = machineUser.Email;
+ machineUser.Contact.FirstName = machine.Name;
+ machineUser.Contact.LastName = machine.Name;
+ machineUser.Contact.FullName = machine.Name;
+ machineUser.Address = new Address();
+
+ db.Users.Add(machineUser);
+ db.SaveChanges();
+ }
+ }
+
+ //Insert/Replace Jobs.
+ foreach (var dto in request.Jobs)
+ {
+ using (ObservablesContext db = ObservablesContextHelper.CreateContext())
+ {
+ try
+ {
+ var job = dto.ToObservable();
+
+ job.ID = 0;
+ job.UserGuid = machineUser.Guid;
+ job.CustomerGuid = null;
+ job.IsSynchronized = true;
+
+ var existingJob = db.Jobs.SingleOrDefault(x => x.Guid == job.Guid);
+
+ if (existingJob == null)
+ {
+ db.Jobs.Add(job);
+ db.SaveChanges();
+ }
+ else if (job.LastUpdated > existingJob.LastUpdated)
+ {
+ existingJob.Delete(db);
+ db.Jobs.Add(job);
+ db.SaveChanges();
+ }
+ }
+ catch (Exception ex)
+ {
+ response.FailedJobs.Add(new SynchronizationFailedEntity()
+ {
+ Guid = dto.Guid,
+ Reason = ex.FlattenMessage(),
+ });
+ }
+ }
+ }
+
+ //Insert JobRuns.
+ foreach (var dto in request.JobRuns)
+ {
+ using (ObservablesContext db = ObservablesContextHelper.CreateContext())
+ {
+ try
+ {
+ var run = dto.ToObservable();
+ run.ID = 0;
+ run.IsSynchronized = true;
+
+ if (db.JobRuns.SingleOrDefault(x => x.Guid == run.Guid) == null)
+ {
+ db.JobRuns.Add(run);
+ db.SaveChanges();
+ }
+ }
+ catch (Exception ex)
+ {
+ response.FailedJobRuns.Add(new SynchronizationFailedEntity()
+ {
+ Guid = dto.Guid,
+ Reason = ex.FlattenMessage(),
+ });
+ }
+ }
+ }
+
+ //Insert MachineEvents.
+ foreach (var dto in request.MachineEvents)
+ {
+ using (ObservablesContext db = ObservablesContextHelper.CreateContext())
+ {
+ try
+ {
+ var ev = dto.ToObservable();
+ ev.ID = 0;
+ ev.UserGuid = machineUser.Guid;
+ ev.IsSynchronized = true;
+
+ if (db.MachinesEvents.SingleOrDefault(x => x.Guid == ev.Guid) == null)
+ {
+ db.MachinesEvents.Add(ev);
+ db.SaveChanges();
+ }
+ }
+ catch (Exception ex)
+ {
+ response.FailedMachineEvents.Add(new SynchronizationFailedEntity()
+ {
+ Guid = dto.Guid,
+ Reason = ex.FlattenMessage(),
+ });
+ }
+ }
+ }
+
+ //Insert TangoUpdates.
+ foreach (var dto in request.OfflineUpdates)
+ {
+ using (ObservablesContext db = ObservablesContextHelper.CreateContext())
+ {
+ try
+ {
+ var update = dto.ToObservable();
+ update.ID = 0;
+ update.IsSynchronized = true;
+
+ if (db.TangoUpdates.SingleOrDefault(x => x.Guid == update.Guid) == null)
+ {
+ db.TangoUpdates.Add(update);
+ db.SaveChanges();
+ }
+ }
+ catch (Exception ex)
+ {
+ response.FailedOfflineUpdates.Add(new SynchronizationFailedEntity()
+ {
+ Guid = dto.Guid,
+ Reason = ex.FlattenMessage(),
+ });
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ NotifyUpdateCompleted(new MachineUpdateCompletedRequest()
+ {
+ Status = TangoUpdateStatuses.SynchronizationFailed,
+ FailedReason = ex.FlattenMessage(),
+ FailedLog = ex.FlattenException(),
+ Token = response.NotifyCompletedToken,
+ });
+ throw ex;
+ }
+
+ return response;
+ }
+
+ [HttpPost]
+ [JwtTokenFilter]
+ public DownloadMachineDataResponse DownloadMachineData(DownloadMachineDataRequest request)
+ {
+ DownloadMachineDataResponse response = new DownloadMachineDataResponse();
+
+ using (ObservablesContext db = ObservablesContextHelper.CreateContext())
+ {
+ var machine = db.Machines.SingleOrDefault(x => x.Guid == RequestToken.Object.MachineGuid);
+
+ if (machine == null)
+ {
+ throw new AuthenticationException("The specified machine could not be found.");
+ }
+
+ //Send Jobs
+ if (request.RequestJobs)
+ {
+ var jobs = new JobsCollectionBuilder(db).Set(x => x.MachineGuid == machine.Guid && !x.IsSynchronized).WithSegments().WithBrushStops().Query(x => x.Take(request.MaxJobs).OrderByDescending(z => z.LastUpdated)).BuildList();
+
+ foreach (var job in jobs)
+ {
+ JobDTO dto = JobDTO.FromObservable(job);
+ response.Jobs.Add(dto);
+ }
+ }
+
+ //Send Job Runs
+ if (request.RequestJobRuns)
+ {
+ var jobRuns = db.JobRuns.Where(x => x.MachineGuid == machine.Guid && !x.IsSynchronized).Take(request.MaxJobRuns).OrderByDescending(x => x.LastUpdated).ToList();
+
+ foreach (var jobRun in jobRuns)
+ {
+ JobRunDTO dto = JobRunDTO.FromObservable(jobRun);
+ response.JobRuns.Add(dto);
+ }
+ }
+
+ //Send Machine Events
+ if (request.RequestMachineEvents)
+ {
+ var machineEvents = db.MachinesEvents.Where(x => x.MachineGuid == machine.Guid && !x.IsSynchronized).Take(request.MaxMachinesEvents).OrderByDescending(x => x.LastUpdated).ToList();
+
+ foreach (var machineEvent in machineEvents)
+ {
+ MachinesEventDTO dto = MachinesEventDTO.FromObservable(machineEvent);
+ response.MachineEvents.Add(dto);
+ }
+ }
+ }
+
+ return response;
+ }
+
+ [HttpPost]
+ [JwtTokenFilter]
+ public NotifyMachineDataDownloadCompletedResponse NotifyMachineDataDownloadCompleted(NotifyMachineDataDownloadCompletedRequest request)
+ {
+ var response = new NotifyMachineDataDownloadCompletedResponse();
+
+ using (ObservablesContext db = ObservablesContextHelper.CreateContext())
+ {
+ var machine = db.Machines.SingleOrDefault(x => x.Guid == RequestToken.Object.MachineGuid);
+
+ if (machine == null)
+ {
+ throw new AuthenticationException("The specified machine could not be found.");
+ }
+
+ if (request.SynchronizedJobs.Count > 0)
+ {
+ db.Database.ExecuteSqlCommand($"UPDATE JOBS SET IS_SYNCHRONIZED = 1 WHERE GUID IN ({String.Join(",", request.SynchronizedJobs.Select(x => "'" + x + "'"))});");
+ }
+
+ if (request.SynchronizedJobRuns.Count > 0)
+ {
+ db.Database.ExecuteSqlCommand($"UPDATE JOB_RUNS SET IS_SYNCHRONIZED = 1 WHERE GUID IN ({String.Join(",", request.SynchronizedJobRuns.Select(x => "'" + x + "'"))});");
+ }
+
+ if (request.SynchronizedMachineEvents.Count > 0)
+ {
+ db.Database.ExecuteSqlCommand($"UPDATE MACHINES_EVENTS SET IS_SYNCHRONIZED = 1 WHERE GUID IN ({String.Join(",", request.SynchronizedMachineEvents.Select(x => "'" + x + "'"))});");
+ }
}
return response;
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs b/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs
index e8165a4a6..014ef68ba 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs
+++ b/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs
@@ -16,5 +16,6 @@ namespace Tango.MachineService
public static String REFRESH_TOKENS_TABLE_NAME => ConfigurationManager.AppSettings[nameof(REFRESH_TOKENS_TABLE_NAME)].ToString();
public static String REFRESH_TOKENS_TABLE_PARTITION => ConfigurationManager.AppSettings[nameof(REFRESH_TOKENS_TABLE_PARTITION)].ToString();
public static bool USE_DB_ACCESS_TOKENS => bool.Parse(ConfigurationManager.AppSettings[nameof(USE_DB_ACCESS_TOKENS)].ToString());
+ public static String CDN_ENDPOINT => ConfigurationManager.AppSettings[nameof(CDN_ENDPOINT)].ToString();
}
} \ No newline at end of file
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Models/PPCPendingUpdate.cs b/Software/Visual_Studio/Web/Tango.MachineService/Models/PPCPendingUpdate.cs
new file mode 100644
index 000000000..12504a1a5
--- /dev/null
+++ b/Software/Visual_Studio/Web/Tango.MachineService/Models/PPCPendingUpdate.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+
+namespace Tango.MachineService.Models
+{
+ public class PPCPendingUpdate
+ {
+ public String Token { get; set; }
+ public String TangoUpdateGuid { get; set; }
+ }
+} \ No newline at end of file
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj
index 2c20fdadb..56ca19e96 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj
+++ b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj
@@ -288,6 +288,7 @@
<Compile Include="Models\DownloadModel.cs" />
<Compile Include="Models\LoginRequest.cs" />
<Compile Include="Models\MachineStudioPendingUpload.cs" />
+ <Compile Include="Models\PPCPendingUpdate.cs" />
<Compile Include="Models\PPCPendingUpload.cs" />
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="App_Start\WebApiConfig.cs" />
@@ -420,7 +421,7 @@
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
- <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" />
+ <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" />
</VisualStudio>
</ProjectExtensions>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Web.config b/Software/Visual_Studio/Web/Tango.MachineService/Web.config
index dce9e1fb9..658439cc0 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService/Web.config
+++ b/Software/Visual_Studio/Web/Tango.MachineService/Web.config
@@ -25,11 +25,12 @@
<add key="MACHINE_STUDIO_VERSIONS_CONTAINER" value="machine-studio-versions-dev" />
<add key="DEPLOYMENT_SLOT" value="DEV" />
<add key="ENVIRONMENT_GROUP" value="Tango DEV" />
- <add key="ENFORCE_MACHINE_STUDIO_VERSION" value="true" />
+ <add key="ENFORCE_MACHINE_STUDIO_VERSION" value="false" />
<add key="JWT_TOKEN_SECRET" value="GQDstcKsx0NHjLOuXOYg5MbeJ1yT0u1iwDVTwine" />
<add key="REFRESH_TOKENS_TABLE_NAME" value="RefreshTokens" />
<add key="REFRESH_TOKENS_TABLE_PARTITION" value="REFRESH_TOKENS_PART" />
<add key="USE_DB_ACCESS_TOKENS" value="false" />
+ <add key="CDN_ENDPOINT" value="https://tango.azureedge.net" />
</appSettings>
<!--
For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.
@@ -61,6 +62,11 @@
</location>
<system.webServer>
+ <security>
+ <requestFiltering>
+ <requestLimits maxAllowedContentLength="2147483648" />
+ </requestFiltering>
+ </security>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />