From cd467ed8a6afec8dcf50d8dc71c75d9d445f7489 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 5 Dec 2019 11:30:45 +0200 Subject: Working on PPC packages... --- .../PPCApplication/DefaultPPCApplicationManager.cs | 23 ++++++++- .../PPC/Tango.PPC.UI/Tango.PPC.UI.csproj | 10 +++- .../PPC/Tango.PPC.UI/ViewModelLocator.cs | 10 ++++ .../Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs | 60 ++++++++++++++++++++++ .../Tango.PPC.UI/ViewModels/RestartingViewVM.cs | 27 ++++++++++ .../PPC/Tango.PPC.UI/Views/MainView.xaml | 1 + .../PPC/Tango.PPC.UI/Views/RestartingView.xaml | 52 +++++++++++++++++++ .../PPC/Tango.PPC.UI/Views/RestartingView.xaml.cs | 28 ++++++++++ 8 files changed, 209 insertions(+), 2 deletions(-) create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/RestartingViewVM.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Views/RestartingView.xaml create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Views/RestartingView.xaml.cs (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI') diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs index ed5ea2629..95c4ccdac 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs @@ -32,6 +32,7 @@ using Tango.PPC.UI.Dialogs; using Tango.Core.Threading; using Tango.PPC.Common.Messages; using Tango.Core.ExtensionMethods; +using Tango.PPC.Common.Navigation; namespace Tango.PPC.UI.PPCApplication { @@ -130,6 +131,11 @@ namespace Tango.PPC.UI.PPCApplication /// public DateTime StartUpDate { get; private set; } + /// + /// Gets a value indicating whether an update has occurred before the application started. + /// + public bool IsAfterUpdate { get; private set; } + private bool _isScreenLocked; /// /// Gets or sets a value indicating whether the screen is currently locked. @@ -220,6 +226,10 @@ namespace Tango.PPC.UI.PPCApplication isAfterSetup = true; LogManager.Log("System restart is required."); } + else + { + IsAfterUpdate = true; + } settings.ApplicationState = ApplicationStates.Ready; settings.Save(); @@ -419,7 +429,7 @@ namespace Tango.PPC.UI.PPCApplication /// /// Restarts the application. /// - public void Restart() + public async void Restart() { if (IsShuttingDown) return; @@ -427,8 +437,19 @@ namespace Tango.PPC.UI.PPCApplication try { + _dispatcher.Invoke(() => + { + var nav = TangoIOC.Default.GetInstance(); + if (nav != null) + { + nav.NavigateTo(NavigationView.RestartingView); + } + }); + LogManager.Log("Restarting the application..."); + await Task.Delay(8000); + _watchdogServer.Dispose(); foreach (var vm in TangoIOC.Default.GetAllInstancesByBase()) 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 e71e5794d..9691987c2 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 @@ -165,6 +165,7 @@ + @@ -180,6 +181,9 @@ LoadingErrorView.xaml + + RestartingView.xaml + LoadingView.xaml @@ -269,6 +273,10 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + Designer MSBuild:Compile @@ -608,7 +616,7 @@ if $(ConfigurationName) == Release del *.xml - + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs index ed56f8a08..60bce4e20 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs @@ -74,6 +74,7 @@ namespace Tango.PPC.UI TangoIOC.Default.Unregister(); TangoIOC.Default.Unregister(); TangoIOC.Default.Unregister(); + TangoIOC.Default.Unregister(); TangoIOC.Default.Register(new PPCWebClient()); TangoIOC.Default.Register(new DefaultDispatcherProvider(Application.Current.Dispatcher)); @@ -110,6 +111,7 @@ namespace Tango.PPC.UI TangoIOC.Default.Register(); TangoIOC.Default.Register(); TangoIOC.Default.Register(); + TangoIOC.Default.Register(); TangoIOC.Default.GetInstance().ContentRendered += (_, __) => @@ -215,5 +217,13 @@ namespace Tango.PPC.UI return TangoIOC.Default.GetInstance(); } } + + public static RestartingViewVM RestartingViewVM + { + get + { + return TangoIOC.Default.GetInstance(); + } + } } } \ 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 01e67d3ce..4cc4ee46f 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs @@ -275,6 +275,66 @@ namespace Tango.PPC.UI.ViewModels base.OnApplicationReady(); StorageProvider.RegisterFileHandler(ExplorerFileDefinition.Update.Extension, HandleSoftwareUpdatePackageLoaded); + + if (ApplicationManager.IsAfterUpdate) + { + RunPostUpdatePackages(); + } + } + + #endregion + + #region Post Update Packages + + private async void RunPostUpdatePackages() + { + await Task.Delay(1000); + + LogManager.Log("Application was loaded after an update. Checking for required post-update packages..."); + + bool required = false; + + try + { + required = await MachineUpdateManager.PostUpdatePackagesRequired(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error checking for post-update packages."); + } + + if (required) + { + LogManager.Log("Post-update packages found and needs to be installed. Navigating to machine update and running post-update packages..."); + await NavigationManager.NavigateTo(Common.Navigation.NavigationView.MachineUpdateView); + await NavigateTo(MachineUpdateView.UpdateProgressView); + try + { + var result = await MachineUpdateManager.RunPostUpdatePackages(); + + LogManager.Log("Post-update packages installed successfully."); + + await Task.Delay(2000); + + if (result.RestartRequired) + { + LogManager.Log("Restart required. Restarting..."); + ApplicationManager.Restart(); + } + else + { + await NavigationManager.NavigateTo(Common.Navigation.NavigationView.LayoutView); + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error occurred while running post-update packages."); + } + } + else + { + LogManager.Log("No post-update packages installation required."); + } } #endregion diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/RestartingViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/RestartingViewVM.cs new file mode 100644 index 000000000..46111031b --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/RestartingViewVM.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.PPC.Common; + +namespace Tango.PPC.UI.ViewModels +{ + public class RestartingViewVM : PPCViewModel + { + public override void OnApplicationStarted() + { + + } + + public override void OnNavigatedTo() + { + base.OnNavigatedTo(); + } + + public override void OnNavigatedFrom() + { + base.OnNavigatedFrom(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml index d139ad5ed..5be95ded4 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml @@ -124,6 +124,7 @@ + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/RestartingView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/RestartingView.xaml new file mode 100644 index 000000000..41017f629 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/RestartingView.xaml @@ -0,0 +1,52 @@ + + + + + + + + + + v + + + + + + + + + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/RestartingView.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/RestartingView.xaml.cs new file mode 100644 index 000000000..fabd7b47b --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/RestartingView.xaml.cs @@ -0,0 +1,28 @@ +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.Views +{ + /// + /// Interaction logic for LoadingView.xaml + /// + public partial class RestartingView : UserControl + { + public RestartingView() + { + InitializeComponent(); + } + } +} -- cgit v1.3.1