From 36bde2234f457f4bb93caf6d1f2e47ddf895be39 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Fri, 6 Dec 2019 21:10:57 +0200 Subject: Added new PID and heaters to hw, diagnostics and tech. Implemented proper sorting on hw version and tech board. (DB CHANGE!) Related Work Items: #1595 --- .../ViewModels/MainViewVM.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs index 40dc82d29..7ebcbeb55 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs @@ -236,13 +236,13 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels _db = ObservablesContext.CreateDefault(); - CurrentVersion.HardwareMotors = _db.HardwareMotorTypes.ToList().Select(x => new HardwareMotor() { HardwareMotorType = x }).ToSynchronizedObservableCollection(); - CurrentVersion.HardwareDancers = _db.HardwareDancerTypes.ToList().Select(x => new HardwareDancer() { HardwareDancerType = x }).ToSynchronizedObservableCollection(); - CurrentVersion.HardwarePidControls = _db.HardwarePidControlTypes.ToList().Select(x => new HardwarePidControl() { HardwarePidControlType = x }).ToSynchronizedObservableCollection(); - CurrentVersion.HardwareWinders = _db.HardwareWinderTypes.ToList().Select(x => new HardwareWinder() { HardwareWinderType = x }).ToSynchronizedObservableCollection(); - CurrentVersion.HardwareSpeedSensors = _db.HardwareSpeedSensorTypes.ToList().Select(x => new HardwareSpeedSensor() { HardwareSpeedSensorType = x }).ToSynchronizedObservableCollection(); - CurrentVersion.HardwareBlowers = _db.HardwareBlowerTypes.ToList().Select(x => new HardwareBlower() { HardwareBlowerType = x }).ToSynchronizedObservableCollection(); - CurrentVersion.HardwareBreakSensors = _db.HardwareBreakSensorTypes.ToList().Select(x => new HardwareBreakSensor() { HardwareBreakSensorType = x }).ToSynchronizedObservableCollection(); + CurrentVersion.HardwareMotors = _db.HardwareMotorTypes.ToList().Select(x => new HardwareMotor() { HardwareMotorType = x }).OrderByAlphaNumeric(x => x.HardwareMotorType.Description).ToSynchronizedObservableCollection(); + CurrentVersion.HardwareDancers = _db.HardwareDancerTypes.ToList().Select(x => new HardwareDancer() { HardwareDancerType = x }).OrderByAlphaNumeric(x => x.HardwareDancerType.Description).ToSynchronizedObservableCollection(); + CurrentVersion.HardwarePidControls = _db.HardwarePidControlTypes.ToList().Select(x => new HardwarePidControl() { HardwarePidControlType = x }).OrderByAlphaNumeric(x => x.HardwarePidControlType.Description).ToSynchronizedObservableCollection(); + CurrentVersion.HardwareWinders = _db.HardwareWinderTypes.ToList().Select(x => new HardwareWinder() { HardwareWinderType = x }).OrderByAlphaNumeric(x => x.HardwareWinderType.Description).ToSynchronizedObservableCollection(); + CurrentVersion.HardwareSpeedSensors = _db.HardwareSpeedSensorTypes.ToList().Select(x => new HardwareSpeedSensor() { HardwareSpeedSensorType = x }).OrderByAlphaNumeric(x => x.HardwareSpeedSensorType.Description).ToSynchronizedObservableCollection(); + CurrentVersion.HardwareBlowers = _db.HardwareBlowerTypes.ToList().Select(x => new HardwareBlower() { HardwareBlowerType = x }).OrderByAlphaNumeric(x => x.HardwareBlowerType.Description).ToSynchronizedObservableCollection(); + CurrentVersion.HardwareBreakSensors = _db.HardwareBreakSensorTypes.ToList().Select(x => new HardwareBreakSensor() { HardwareBreakSensorType = x }).OrderByAlphaNumeric(x => x.HardwareBreakSensorType.Description).ToSynchronizedObservableCollection(); } private void RefreshVersions() -- cgit v1.3.1 From 3cd59dd3b04168ad91cb1fe51231e9b3ddd74705 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Sun, 8 Dec 2019 00:19:54 +0200 Subject: Implemented fast database update detection of RMLL, Hardware Versions & Color Catalogs. Related Work Items: #1622 --- Software/DB/PPC/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/PPC/Tango_log.ldf | Bin 53673984 -> 53673984 bytes .../ViewModels/MainViewVM.cs | 1 + .../ViewModels/MainViewVM.cs | 1 + .../MachineUpdate/MachineUpdateManager.cs | 23 +++++++++++++-- .../PPC/Tango.PPC.Common/Tango.PPC.Common.csproj | 3 +- .../Tango.PPC.Common/Web/CheckForUpdateRequest.cs | 11 ++++++++ .../Tango.PPC.Common/Web/CheckForUpdateResponse.cs | 7 +++++ .../PPC/Tango.PPC.Common/Web/UpdatedEntity.cs | 31 +++++++++++++++++++++ .../UpdateAvailableNotificationItem.cs | 10 +++++++ .../UpdateAvailableNotificationItemView.xaml | 16 +++++++---- .../Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs | 13 ++++++++- .../Controllers/PPCController.cs | 28 +++++++++++++++++++ 13 files changed, 134 insertions(+), 10 deletions(-) create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/Web/UpdatedEntity.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs') diff --git a/Software/DB/PPC/Tango.mdf b/Software/DB/PPC/Tango.mdf index a84785a6e..92884377a 100644 Binary files a/Software/DB/PPC/Tango.mdf and b/Software/DB/PPC/Tango.mdf differ diff --git a/Software/DB/PPC/Tango_log.ldf b/Software/DB/PPC/Tango_log.ldf index e97b6d351..9a2dcca84 100644 Binary files a/Software/DB/PPC/Tango_log.ldf and b/Software/DB/PPC/Tango_log.ldf differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Catalogs/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Catalogs/ViewModels/MainViewVM.cs index 652ad3093..3cc4406d6 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Catalogs/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Catalogs/ViewModels/MainViewVM.cs @@ -305,6 +305,7 @@ namespace Tango.MachineStudio.Catalogs.ViewModels try { IsFree = false; + ActiveCatalog.LastUpdated = DateTime.UtcNow; await _activeCatalogContext.SaveChangesAsync(); await LoadCatalogs(); _notification.ShowInfo("Catalog updated successfully."); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs index 7ebcbeb55..256ed24d6 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs @@ -418,6 +418,7 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels await Task.Factory.StartNew(() => { + CurrentVersion.LastUpdated = DateTime.UtcNow; _db.SaveChanges(); RefreshVersions(); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs index e98f6d717..5296a9f34 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; +using Tango.BL; using Tango.Core; using Tango.Core.DB; using Tango.Core.ExtensionMethods; @@ -594,6 +595,8 @@ namespace Tango.PPC.Common.MachineUpdate { return Task.Factory.StartNew(() => { + _isUpdating = true; + var machineServiceAddress = SettingsManager.Default.GetOrCreate().GetMachineServiceAddress(); LogManager.Log($"Connecting to machine service on {machineServiceAddress}..."); @@ -606,12 +609,28 @@ namespace Tango.PPC.Common.MachineUpdate request.SerialNumber = serialNumber; request.Version = _app_manager.Version.ToString(); + try + { + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + request.Rmls = db.Rmls.ToList().Select(x => new UpdatedEntity(x)).ToList(); + request.HardwareVersions = db.HardwareVersions.ToList().Select(x => new UpdatedEntity(x)).ToList(); + request.Catalogs = db.ColorCatalogs.ToList().Select(x => new UpdatedEntity(x)).ToList(); + } + } + catch (Exception ex) + { + LogManager.Log(ex, "An error occurred while trying to fill the existing database entities before checking for updates."); + } + CheckForUpdateResponse update_response = null; update_response = _client.CheckForUpdates(request).Result; LogManager.Log($"Check for update response received: {Environment.NewLine}{update_response.ToJsonString()}"); + _isUpdating = false; + return update_response; }); } @@ -977,10 +996,10 @@ namespace Tango.PPC.Common.MachineUpdate try { var response = await CheckForUpdate(_machineProvider.Machine.SerialNumber); - if (response.IsUpdateAvailable) + if (response.IsUpdateAvailable || response.IsDatabaseUpdateAvailable) { _checkForUpdateTimer.Interval = TimeSpan.FromMinutes(60).TotalMilliseconds; - LogManager.Log($"New application version detected ({response.Version}). Raising event..."); + LogManager.Log($"New {(response.IsDatabaseUpdateAvailable ? "database updates" : "application version")} detected ({response.Version}). Raising event..."); UpdateAvailable?.Invoke(this, response); } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj index 671cac4f1..e3a23903e 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj @@ -226,6 +226,7 @@ + @@ -406,7 +407,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateRequest.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateRequest.cs index b98848e4f..0feb32aaf 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateRequest.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateRequest.cs @@ -11,5 +11,16 @@ namespace Tango.PPC.Common.Web { public String SerialNumber { get; set; } public String Version { get; set; } + + public List Rmls { get; set; } + public List HardwareVersions { get; set; } + public List Catalogs { get; set; } + + public CheckForUpdateRequest() + { + Rmls = new List(); + HardwareVersions = new List(); + Catalogs = new List(); + } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateResponse.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateResponse.cs index 370c0f5ea..63d870834 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateResponse.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateResponse.cs @@ -10,8 +10,15 @@ namespace Tango.PPC.Common.Web public class CheckForUpdateResponse : WebResponseMessage { public bool IsUpdateAvailable { get; set; } + public bool IsDatabaseUpdateAvailable { get; set; } public String Version { get; set; } public bool SetupFirmware { get; set; } public bool SetupFPGA { get; set; } + public UpdateDBResponse UpdateDBResponse { get; set; } + + public CheckForUpdateResponse() + { + UpdateDBResponse = new UpdateDBResponse(); + } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/UpdatedEntity.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/UpdatedEntity.cs new file mode 100644 index 000000000..faee20678 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/UpdatedEntity.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL; + +namespace Tango.PPC.Common.Web +{ + public class UpdatedEntity + { + public UpdatedEntity() + { + + } + + public UpdatedEntity(IObservableEntity entity) : this() + { + Guid = entity.Guid; + LastUpdated = entity.LastUpdated; + } + + public String Guid { get; set; } + public DateTime LastUpdated { get; set; } + + public override string ToString() + { + return $"{Guid} | {LastUpdated}"; + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItem.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItem.cs index 4dea142b0..9e336f276 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItem.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItem.cs @@ -31,6 +31,16 @@ namespace Tango.PPC.UI.Notifications.NotificationItems set { _version = value; RaisePropertyChangedAuto(); } } + private bool _isDatabaseUpdate; + /// + /// Gets or sets a value indicating whether this instance is database update. + /// + public bool IsDatabaseUpdate + { + get { return _isDatabaseUpdate; } + set { _isDatabaseUpdate = value; RaisePropertyChangedAuto(); } + } + /// /// Gets or sets the view type. /// diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItemView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItemView.xaml index c4533b843..fc9b05b9b 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItemView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItemView.xaml @@ -14,12 +14,16 @@ - - Version - - is available! - Tap to start updating your system. - + + + + Version + + is available! + Tap to start updating your system. + + + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs index 25a4f8c4b..0371e94da 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs @@ -162,6 +162,16 @@ namespace Tango.PPC.UI.ViewModels LatestVersion = response.Version; await NavigateTo(MachineUpdateView.UpdateAvailableView); } + else if (response.IsDatabaseUpdateAvailable) + { + IsDbUpdate = true; + _db_compare_result = new DbCompareResult() + { + RequiresUpdate = true, + UpdateDBResponse = response.UpdateDBResponse + }; + await NavigateTo(MachineUpdateView.UpdateAvailableView); + } else { _db_compare_result = await MachineUpdateManager.UpdateDBCheck(MachineProvider.Machine.SerialNumber); @@ -418,12 +428,13 @@ namespace Tango.PPC.UI.ViewModels { if (!IsVisible && _updateNotificationItem == null) { - LogManager.Log($"New application version detected ({e.Version}). Pushing notification..."); + LogManager.Log($"New {(e.IsDatabaseUpdateAvailable ? "database updates" : "application version")} detected ({e.Version}). Pushing notification..."); InvokeUI(() => { _updateNotificationItem = new UpdateAvailableNotificationItem(); _updateNotificationItem.Version = Version.Parse(e.Version).ToString(3); + _updateNotificationItem.IsDatabaseUpdate = e.IsDatabaseUpdateAvailable && !e.IsUpdateAvailable; _updateNotificationItem.Pressed += (_, __) => { _updateNotificationItem = null; diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs index f0239978f..2dee09e69 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs @@ -314,6 +314,34 @@ namespace Tango.MachineService.Controllers response.Version = latest_machine_version.Version; + //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 = 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) { response.IsUpdateAvailable = true; -- cgit v1.3.1