diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-12-07 22:46:37 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-12-07 22:46:37 +0200 |
| commit | 00f7facd947e0e8ce05a43d4f9d036e8f9a6a69e (patch) | |
| tree | e8b839ab42dbb7fc05e7398a9fb1b3e4941fa6c1 /Software/Visual_Studio/PPC | |
| parent | a6e6af346bf160b4a83163a6f1b268920cf2005c (diff) | |
| download | Tango-00f7facd947e0e8ce05a43d4f9d036e8f9a6a69e.tar.gz Tango-00f7facd947e0e8ce05a43d4f9d036e8f9a6a69e.zip | |
Implemented auto check for update notification on PPC...
Related Work Items: #1460
Diffstat (limited to 'Software/Visual_Studio/PPC')
10 files changed, 244 insertions, 4 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/IMachineUpdateManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/IMachineUpdateManager.cs index 299e18e57..3655aa462 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/IMachineUpdateManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/IMachineUpdateManager.cs @@ -11,6 +11,19 @@ namespace Tango.PPC.Common.MachineUpdate { public interface IMachineUpdateManager { + /// <summary> + /// Occurs when an application update is available. + /// </summary> + event EventHandler<CheckForUpdateResponse> UpdateAvailable; + + /// <summary> + /// Gets or sets a value indicating whether to automatically check for new application updates. + /// </summary> + bool AutoCheckForUpdates { get; set; } + + /// <summary> + /// Gets the current machine update progress status. + /// </summary> MachineUpdateProgress Status { get; } /// <summary> 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 658c323de..e98f6d717 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs @@ -37,10 +37,17 @@ namespace Tango.PPC.Common.MachineUpdate private IPackageRunner _packageRunner; private PPCWebClient _client; private List<LogItemBase> _logs; + private System.Timers.Timer _checkForUpdateTimer; + private bool _isUpdating; #region Events /// <summary> + /// Occurs when an application update is available. + /// </summary> + public event EventHandler<CheckForUpdateResponse> UpdateAvailable; + + /// <summary> /// Occurs when there is a text log message available. /// </summary> public event EventHandler<string> ProgressLog; @@ -55,12 +62,25 @@ namespace Tango.PPC.Common.MachineUpdate #region Properties private MachineUpdateProgress _status; + /// <summary> + /// Gets the current machine update progress status. + /// </summary> public MachineUpdateProgress Status { get { return _status; } private set { _status = value; RaisePropertyChangedAuto(); } } + private bool _autoCheckForUpdates; + /// <summary> + /// Gets or sets a value indicating whether to automatically check for new application updates. + /// </summary> + public bool AutoCheckForUpdates + { + get { return _autoCheckForUpdates; } + set { _autoCheckForUpdates = value; RaisePropertyChangedAuto(); } + } + #endregion #region Constructors @@ -79,6 +99,10 @@ namespace Tango.PPC.Common.MachineUpdate _logs = new List<LogItemBase>(); LogManager.NewLog += LogManager_NewLog; + + _checkForUpdateTimer = new System.Timers.Timer(TimeSpan.FromMinutes(1).TotalMilliseconds); + _checkForUpdateTimer.Elapsed += _checkForUpdateTimer_Elapsed; + _checkForUpdateTimer.Start(); } #endregion @@ -159,6 +183,8 @@ namespace Tango.PPC.Common.MachineUpdate LogManager.Log(xx, "Error notifying update failed."); } } + + _isUpdating = false; } private async void OnCompleted(MachineUpdateResult result, TaskCompletionSource<MachineUpdateResult> completionSource, DownloadUpdateResponse response, String dbBackupFile) @@ -186,6 +212,8 @@ namespace Tango.PPC.Common.MachineUpdate LogManager.Log(ex, "Error notifying update completed."); } } + + _isUpdating = false; } private void OnCompleted(UpdateDBResponse response) @@ -205,6 +233,8 @@ namespace Tango.PPC.Common.MachineUpdate LogManager.Log(ex, "Error notifying database completed."); } } + + _isUpdating = false; } private void OnFailed(Exception ex, UpdateDBResponse response, bool performDatabaseRollback, String dbBackupFile, Tango.Core.DataSource localDataSource) @@ -256,6 +286,8 @@ namespace Tango.PPC.Common.MachineUpdate LogManager.Log(xx, "Error notifying database failed."); } } + + _isUpdating = false; } private String GetLogsStringAndClear() @@ -295,6 +327,8 @@ namespace Tango.PPC.Common.MachineUpdate try { + _isUpdating = true; + var machineServiceAddress = SettingsManager.Default.GetOrCreate<PPCSettings>().GetMachineServiceAddress(); LogManager.Log($"Starting machine update for serial number {serialNumber}..."); @@ -594,6 +628,7 @@ namespace Tango.PPC.Common.MachineUpdate return Task.Factory.StartNew(() => { + _isUpdating = true; UpdateDBResponse update_response = null; var localDataSource = SettingsManager.Default.GetOrCreate<CoreSettings>().DataSource; bool performDatabaseRollback = false; @@ -930,5 +965,31 @@ namespace Tango.PPC.Common.MachineUpdate } #endregion + + #region Auto Check For Update + + private async void _checkForUpdateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) + { + if (AutoCheckForUpdates && !_isUpdating) + { + _checkForUpdateTimer.Stop(); + + try + { + var response = await CheckForUpdate(_machineProvider.Machine.SerialNumber); + if (response.IsUpdateAvailable) + { + _checkForUpdateTimer.Interval = TimeSpan.FromMinutes(60).TotalMilliseconds; + LogManager.Log($"New application version detected ({response.Version}). Raising event..."); + UpdateAvailable?.Invoke(this, response); + } + } + catch { } + + _checkForUpdateTimer.Start(); + } + } + + #endregion } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/update_available.png b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/update_available.png Binary files differnew file mode 100644 index 000000000..cafcf1d83 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/update_available.png diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs index 4c36c3cbe..2a825cc19 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs @@ -129,6 +129,7 @@ namespace Tango.PPC.UI.Navigation toView = MainView.Instance.NavigationControl.NavigateTo(view.ToString(), () => { + _currentVM = toView.DataContext; NotifyOnNavigated(fromView.DataContext, toView.DataContext); }); 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 new file mode 100644 index 000000000..4dea142b0 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItem.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.PPC.Common.Notifications; + +namespace Tango.PPC.UI.Notifications.NotificationItems +{ + /// <summary> + /// Represents a simple text message notification item which can be inserted into the application notifications panel. + /// </summary> + /// <seealso cref="Tango.PPC.Common.Notifications.NotificationItem" /> + public class UpdateAvailableNotificationItem : NotificationItem + { + /// <summary> + /// Initializes a new instance of the <see cref="UpdateAvailableNotificationItem"/> class. + /// </summary> + public UpdateAvailableNotificationItem() + { + CanClose = true; + } + + private String _version; + /// <summary> + /// Gets or sets the message. + /// </summary> + public String Version + { + get { return _version; } + set { _version = value; RaisePropertyChangedAuto(); } + } + + /// <summary> + /// Gets or sets the view type. + /// </summary> + public override Type ViewType + { + get { return typeof(UpdateAvailableNotificationItemView); } + } + } +} 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 new file mode 100644 index 000000000..c4533b843 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItemView.xaml @@ -0,0 +1,26 @@ +<UserControl x:Class="Tango.PPC.UI.Notifications.NotificationItems.UpdateAvailableNotificationItemView" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:touch="clr-namespace:Tango.Touch.Controls;assembly=Tango.Touch" + xmlns:local="clr-namespace:Tango.PPC.UI.Notifications.NotificationItems" + xmlns:common="clr-namespace:Tango.PPC.Common.Converters" + mc:Ignorable="d" + x:Name="MessageNotificationItemControl" + d:DesignHeight="60" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=local:UpdateAvailableNotificationItem, IsDesignTimeCreatable=False}" MinHeight="90" Height="90" MaxHeight="150" Background="White"> + + <Grid> + <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> + </DockPanel> + </Border> + </Grid> +</UserControl> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItemView.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItemView.xaml.cs new file mode 100644 index 000000000..791d40540 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItemView.xaml.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.PPC.UI.Notifications.NotificationItems +{ + /// <summary> + /// Represents the <see cref="UpdateAvailableNotificationItemView"/> view. + /// </summary> + /// <seealso cref="System.Windows.Controls.UserControl" /> + /// <seealso cref="System.Windows.Markup.IComponentConnector" /> + public partial class UpdateAvailableNotificationItemView : UserControl + { + public UpdateAvailableNotificationItemView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj index 3225eacc1..ab5492ab6 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj @@ -149,6 +149,10 @@ <Compile Include="Navigation\DefaultNavigationManager.cs" /> <Compile Include="Notifications\DefaultNotificationProvider.cs" /> <Compile Include="Notifications\DialogAndView.cs" /> + <Compile Include="Notifications\NotificationItems\UpdateAvailableNotificationItem.cs" /> + <Compile Include="Notifications\NotificationItems\UpdateAvailableNotificationItemView.xaml.cs"> + <DependentUpon>UpdateAvailableNotificationItemView.xaml</DependentUpon> + </Compile> <Compile Include="Notifications\PendingNotification.cs" /> <Compile Include="PPCApplication\DefaultPPCApplicationManager.cs" /> <Compile Include="Printing\DefaultPrintingManager.cs" /> @@ -245,6 +249,10 @@ <DependentUpon>MainWindow.xaml</DependentUpon> <SubType>Code</SubType> </Compile> + <Page Include="Notifications\NotificationItems\UpdateAvailableNotificationItemView.xaml"> + <Generator>MSBuild:Compile</Generator> + <SubType>Designer</SubType> + </Page> <Page Include="Resources\Colors.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> @@ -365,6 +373,7 @@ <Resource Include="Images\GlobalStatus\shutting-down.png" /> <Resource Include="Images\GlobalStatus\error.png" /> <Resource Include="Images\GlobalStatus\service.png" /> + <Resource Include="Images\update_available.png" /> <Content Include="Manifests\release.xml" /> <Content Include="Manifests\debug.xml" /> <None Include="firmware_package.tfp"> @@ -621,7 +630,7 @@ if $(ConfigurationName) == Debug copy /Y "$(TargetDir)Packages" "$(TargetDir)"</ </PropertyGroup> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> + <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> </VisualStudio> </ProjectExtensions> </Project>
\ No newline at end of file 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 4cc4ee46f..25a4f8c4b 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs @@ -12,6 +12,7 @@ using Tango.PPC.Common; using Tango.PPC.Common.MachineUpdate; using Tango.PPC.Common.Web; using Tango.PPC.UI.Dialogs; +using Tango.PPC.UI.Notifications.NotificationItems; using Tango.PPC.UI.ViewsContracts; namespace Tango.PPC.UI.ViewModels @@ -36,6 +37,7 @@ namespace Tango.PPC.UI.ViewModels private DbCompareResult _db_compare_result; private bool _isChecking; private CheckForUpdateResponse _checkUpdateResponse; + private UpdateAvailableNotificationItem _updateNotificationItem; #region Properties @@ -125,6 +127,8 @@ namespace Tango.PPC.UI.ViewModels NavigationManager.NavigateTo(Common.Navigation.NavigationView.HomeModule); NavigateTo(MachineUpdateView.UpdateCheckView); }); + + machineUpdateManager.UpdateAvailable += MachineUpdateManager_UpdateAvailable; } #endregion @@ -280,6 +284,24 @@ namespace Tango.PPC.UI.ViewModels { RunPostUpdatePackages(); } + else + { + MachineUpdateManager.AutoCheckForUpdates = MachineProvider.Machine.AutoCheckForUpdates; + } + } + + /// <summary> + /// Called when the navigation system has navigated to this VM view. + /// </summary> + public override void OnNavigatedTo() + { + base.OnNavigatedTo(); + + if (_updateNotificationItem != null) + { + _updateNotificationItem.Close(); + _updateNotificationItem = null; + } } #endregion @@ -389,5 +411,39 @@ namespace Tango.PPC.UI.ViewModels } #endregion + + #region Auto Check For Update + + private void MachineUpdateManager_UpdateAvailable(object sender, CheckForUpdateResponse e) + { + if (!IsVisible && _updateNotificationItem == null) + { + LogManager.Log($"New application version detected ({e.Version}). Pushing notification..."); + + InvokeUI(() => + { + _updateNotificationItem = new UpdateAvailableNotificationItem(); + _updateNotificationItem.Version = Version.Parse(e.Version).ToString(3); + _updateNotificationItem.Pressed += (_, __) => + { + _updateNotificationItem = null; + + if (!IsVisible) + { + LogManager.Log("Update available notification pressed. Navigating to update view..."); + NavigationManager.NavigateTo(Common.Navigation.NavigationView.MachineUpdateView); + CheckForUpdates(); + } + }; + _updateNotificationItem.Closed += (_, __) => + { + _updateNotificationItem = null; + }; + NotificationProvider.PushNotification(_updateNotificationItem); + }); + } + } + + #endregion } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml index 0cc21aa28..9315f9f0e 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml @@ -239,10 +239,12 @@ <touch:TouchNotificationBar.NotificationTemplate> <DataTemplate> <components:Ripple Padding="0"> - <touch:TouchClickableControl Command="{Binding PressedCommand}"> - <ContentControl Content="{Binding Converter={StaticResource ItemBaseConverter}}"/> + <Grid Background="Transparent"> + <touch:TouchClickableControl Command="{Binding PressedCommand}"> + <ContentControl Content="{Binding Converter={StaticResource ItemBaseConverter}}"/> + </touch:TouchClickableControl> <touch:TouchIconButton Visibility="{Binding CanClose,Converter={StaticResource BooleanToVisibilityConverter}}" DockPanel.Dock="Right" Background="Transparent" Padding="35" Style="{StaticResource TangoRoundTouchIconButton}" Command="{Binding CloseCommand}" CommandParameter="{Binding}" HorizontalAlignment="Right" MaxHeight="90" Width="{Binding RelativeSource={RelativeSource Self},Path=ActualHeight}" Icon="Close" Foreground="{StaticResource TangoDarkForegroundBrush}" /> - </touch:TouchClickableControl> + </Grid> </components:Ripple> </DataTemplate> </touch:TouchNotificationBar.NotificationTemplate> |
