diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-12-08 00:19:54 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-12-08 00:19:54 +0200 |
| commit | 3cd59dd3b04168ad91cb1fe51231e9b3ddd74705 (patch) | |
| tree | b7431f7fcdf3336a1811140a4e84d3660009d5f1 /Software/Visual_Studio/PPC | |
| parent | 00f7facd947e0e8ce05a43d4f9d036e8f9a6a69e (diff) | |
| download | Tango-3cd59dd3b04168ad91cb1fe51231e9b3ddd74705.tar.gz Tango-3cd59dd3b04168ad91cb1fe51231e9b3ddd74705.zip | |
Implemented fast database update detection of RMLL, Hardware Versions & Color Catalogs.
Related Work Items: #1622
Diffstat (limited to 'Software/Visual_Studio/PPC')
8 files changed, 104 insertions, 10 deletions
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<CheckForUpdateResponse>(() => { + _isUpdating = true; + var machineServiceAddress = SettingsManager.Default.GetOrCreate<PPCSettings>().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 @@ <Compile Include="Web\MachineVersionsResponse.cs" /> <Compile Include="Web\LatestVersionRequest.cs" /> <Compile Include="Web\LatestVersionResponse.cs" /> + <Compile Include="Web\UpdatedEntity.cs" /> <Compile Include="Web\UploadCompletedResponse.cs" /> <Compile Include="Web\UploadCompletedRequest.cs" /> <Compile Include="Web\UploadVersionRequest.cs" /> @@ -406,7 +407,7 @@ </Target> <ProjectExtensions> <VisualStudio> - <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> </Project>
\ 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<UpdatedEntity> Rmls { get; set; } + public List<UpdatedEntity> HardwareVersions { get; set; } + public List<UpdatedEntity> Catalogs { get; set; } + + public CheckForUpdateRequest() + { + Rmls = new List<UpdatedEntity>(); + HardwareVersions = new List<UpdatedEntity>(); + Catalogs = new List<UpdatedEntity>(); + } } } 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; + /// <summary> + /// Gets or sets a value indicating whether this instance is database update. + /// </summary> + public bool IsDatabaseUpdate + { + get { return _isDatabaseUpdate; } + set { _isDatabaseUpdate = value; RaisePropertyChangedAuto(); } + } + /// <summary> /// Gets or sets the view type. /// </summary> 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 @@ <Border BorderThickness="0 0 0 2" BorderBrush="{StaticResource TangoPrimaryAccentBrush}" Padding="15"> <DockPanel> <Image Source="/Images/update_available.png" MaxHeight="50" /> - <TextBlock Margin="20 0 0 0" VerticalAlignment="Center"> - <Run>Version</Run> - <Run Foreground="{StaticResource TangoPrimaryAccentBrush}" FontWeight="SemiBold" Text="{Binding Version,FallbackValue='1.0.0.0',TargetNullValue='1.0.0.0'}"></Run> - <Run>is available!</Run> - <Run>Tap to start updating your system.</Run> - </TextBlock> + + <Grid> + <TextBlock Margin="20 0 0 0" VerticalAlignment="Center" Visibility="{Binding IsDatabaseUpdate,Converter={StaticResource BooleanToVisibilityInverseConverter}}"> + <Run>Version</Run> + <Run Foreground="{StaticResource TangoPrimaryAccentBrush}" FontWeight="SemiBold" Text="{Binding Version,FallbackValue='1.0.0.0',TargetNullValue='1.0.0.0'}"></Run> + <Run>is available!</Run> + <Run>Tap to start updating your system.</Run> + </TextBlock> + <TextBlock Margin="20 0 0 0" VerticalAlignment="Center" Text="Database updates are available. Tap to start updating your system." Visibility="{Binding IsDatabaseUpdate,Converter={StaticResource BooleanToVisibilityConverter}}"></TextBlock> + </Grid> </DockPanel> </Border> </Grid> 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; |
