diff options
22 files changed, 394 insertions, 15 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs index 7c67ac1a3..1474eaa04 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs @@ -61,6 +61,11 @@ namespace Tango.PPC.Common.Application bool IsInTechnicianMode { get; } /// <summary> + /// Gets a value indicating whether an update has occurred before the application started. + /// </summary> + bool IsAfterUpdate { get; } + + /// <summary> /// Shutdown the application. /// </summary> void ShutDown(); 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 85d61d4cc..299e18e57 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/IMachineUpdateManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/IMachineUpdateManager.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.PMR.Synchronization; +using Tango.PPC.Common.UpdatePackages; using Tango.PPC.Common.Web; namespace Tango.PPC.Common.MachineUpdate @@ -64,5 +65,17 @@ namespace Tango.PPC.Common.MachineUpdate /// <param name="filePath">The file path.</param> /// <returns></returns> Task<UpdatePackageFile> GetUpdatePackageFileInfo(String filePath); + + /// <summary> + /// Checks whether any post update packages needs to be installed. + /// </summary> + /// <returns></returns> + Task<bool> PostUpdatePackagesRequired(); + + /// <summary> + /// Runs all post update packages. + /// </summary> + /// <returns></returns> + Task<PackageRunnerResult> RunPostUpdatePackages(); } } 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 ae3e093be..33a6d04e6 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs @@ -19,6 +19,7 @@ using Tango.Integration.Upgrade; using Tango.PMR.Synchronization; using Tango.PPC.Common.Application; using Tango.PPC.Common.Connection; +using Tango.PPC.Common.Navigation; using Tango.PPC.Common.UpdatePackages; using Tango.PPC.Common.Web; using Tango.Settings; @@ -33,6 +34,7 @@ namespace Tango.PPC.Common.MachineUpdate private IPPCApplicationManager _app_manager; private IMachineProvider _machineProvider; private IPackageRunner _packageRunner; + private INavigationManager _navigationManager; private PPCWebClient _client; #region Events @@ -66,7 +68,7 @@ namespace Tango.PPC.Common.MachineUpdate /// Initializes a new instance of the <see cref="MachineUpdateManager"/> class. /// </summary> /// <param name="applicationManager">The application manager.</param> - public MachineUpdateManager(PPCWebClient ppcWebClient, IPPCApplicationManager applicationManager, IMachineProvider machineProvider, IPackageRunner packageRunner) + public MachineUpdateManager(PPCWebClient ppcWebClient, IPPCApplicationManager applicationManager, IMachineProvider machineProvider, IPackageRunner packageRunner, INavigationManager navigationManager) { _client = ppcWebClient; _machineProvider = machineProvider; @@ -81,7 +83,7 @@ namespace Tango.PPC.Common.MachineUpdate private void _packageRunner_PackageStateChanged(object sender, PackageStateChangedEventArgs e) { - UpdateProgress("Preparing", e.PackageName); + UpdateProgress(e.PackageType == PackageType.Pre ? "Preparing" : "Finalizing", e.PackageName); } #endregion @@ -833,6 +835,26 @@ namespace Tango.PPC.Common.MachineUpdate }); } + /// <summary> + /// Checks whether any post update packages needs to be installed. + /// </summary> + /// <returns></returns> + public Task<bool> PostUpdatePackagesRequired() + { + String packagesFolder = Path.Combine(AssemblyHelper.GetCurrentAssemblyFolder(), "packages"); + return _packageRunner.IsPackageInstallationRequired(PackageType.Post, packagesFolder); + } + + /// <summary> + /// Runs all post update packages. + /// </summary> + /// <returns></returns> + public Task<PackageRunnerResult> RunPostUpdatePackages() + { + String packagesFolder = Path.Combine(AssemblyHelper.GetCurrentAssemblyFolder(), "packages"); + return _packageRunner.Run(PackageType.Post, packagesFolder); + } + #endregion #region Protected Methods diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Navigation/NavigationView.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Navigation/NavigationView.cs index d8a1eec56..643908e87 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Navigation/NavigationView.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Navigation/NavigationView.cs @@ -23,5 +23,6 @@ namespace Tango.PPC.Common.Navigation ShutdownView, RestartingSystemView, EmergencyView, + RestartingView, } } 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 892269c03..671cac4f1 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 @@ -162,6 +162,7 @@ <Compile Include="UpdatePackages\PackageContext.cs" /> <Compile Include="UpdatePackages\PackageInstallation.cs" /> <Compile Include="UpdatePackages\PackageInstallationState.cs" /> + <Compile Include="UpdatePackages\PackageRunnerResult.cs" /> <Compile Include="UpdatePackages\PackageStateChangedEventArgs.cs" /> <Compile Include="UpdatePackages\PackagesFile.cs" /> <Compile Include="UpdatePackages\PackageType.cs" /> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/UpdatePackages/DefaultPackageRunner.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/UpdatePackages/DefaultPackageRunner.cs index 882896f04..e1323916b 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/UpdatePackages/DefaultPackageRunner.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/UpdatePackages/DefaultPackageRunner.cs @@ -6,9 +6,14 @@ using System.IO; using System.Linq; using System.Reflection; using System.Text; +using System.Threading; using System.Threading.Tasks; using Tango.Core; +using Tango.Core.DI; using Tango.Core.Helpers; +using Tango.PPC.Common.Application; +using Tango.PPC.Common.Connection; +using Tango.PPC.Common.Notifications; namespace Tango.PPC.Common.UpdatePackages { @@ -87,11 +92,16 @@ namespace Tango.PPC.Common.UpdatePackages File.WriteAllText(_configFile, json); } - public Task Run(PackageType type, String packagesFolder) + public Task<PackageRunnerResult> Run(PackageType type, String packagesFolder) { - return Task.Factory.StartNew(() => + return Task.Factory.StartNew<PackageRunnerResult>(() => { + PackageRunnerResult result = new PackageRunnerResult(); + PackageContext context = new PackageContext(); + context.ApplicationManager = TangoIOC.Default.GetInstance<IPPCApplicationManager>(); + context.MachineProvider = TangoIOC.Default.GetInstance<IMachineProvider>(); + context.NotificationProvider = TangoIOC.Default.GetInstance<INotificationProvider>(); LogManager.Log($"Running {type}-update packages..."); @@ -163,19 +173,27 @@ namespace Tango.PPC.Common.UpdatePackages { try { - OnPackageRuns(att.Name, installedPackage.State); + OnPackageRuns(att.Name, installedPackage.State, installedPackage.Type); + installedPackage.InstallationDate = DateTime.Now; packageInstance.Run(context).GetAwaiter().GetResult(); installedPackage.State = PackageInstallationState.Installed; installedPackage.FailedReason = null; - OnPackageRuns(att.Name, installedPackage.State); + OnPackageRuns(att.Name, installedPackage.State, installedPackage.Type); LogManager.Log("Package installed successfully."); + + if (att.RequiresRestart) + { + result.RestartRequired = true; + } + + Thread.Sleep(2000); } catch (Exception ex) { LogManager.Log(ex, "Package installation failed."); installedPackage.State = PackageInstallationState.Failed; installedPackage.FailedReason = ex.FlattenMessage(); - OnPackageRuns(att.Name, installedPackage.State); + OnPackageRuns(att.Name, installedPackage.State, installedPackage.Type); continue; } } @@ -210,15 +228,97 @@ namespace Tango.PPC.Common.UpdatePackages { LogManager.Log(ex, "Error saving packages file!"); } + + return result; + }); + } + + public Task<bool> IsPackageInstallationRequired(PackageType type, String packagesFolder) + { + return Task.Factory.StartNew<bool>(() => + { + LogManager.Log("Checking if any package installation is required..."); + + _packagesFile = GetPackagesFile().Result; + + //Get all packages in folder. + foreach (var packageFile in Directory.GetFiles(packagesFolder, "*.dll")) + { + LogManager.Log($"Loading assembly '{Path.GetFileName(packageFile)}'..."); + + Assembly asm; + + //Load assembly and investigate for types based on package type. + try + { + asm = Assembly.LoadFile(packageFile); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error loading assembly!"); + continue; + } + + try + { + foreach (var packageType in asm.GetTypes().Where( + x => typeof(IPPCPackage).IsAssignableFrom(x) && + x.GetCustomAttribute<PPCPackageAttribute>() != null && + x.GetCustomAttribute<PPCPackageAttribute>().Type == type)) + { + LogManager.Log($"Checking package '{packageType.FullName}'..."); + + try + { + //Getting installed package from file. + var installedPackage = _packagesFile.PackageInstallations.SingleOrDefault(x => x.PackageName == packageType.FullName); + + //Check if requires installation. + if (installedPackage == null || installedPackage.State != PackageInstallationState.Installed) + { + if (installedPackage == null) + { + LogManager.Log("Package was never installed."); + return true; + } + else + { + LogManager.Log($"Package installation state is '{installedPackage.State}' due to {installedPackage.FailedReason}"); + return true; + } + } + else + { + LogManager.Log("Package is already installed."); + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error in handling the package!"); + continue; + } + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error investigating assembly!"); + continue; + } + } + + LogManager.Log("No packages to install."); + + return false; }); } - protected virtual void OnPackageRuns(String packageName, PackageInstallationState state) + protected virtual void OnPackageRuns(String packageName, PackageInstallationState state, PackageType type) { PackageStateChanged?.Invoke(this, new PackageStateChangedEventArgs() { PackageName = packageName, State = state, + PackageType = type, }); } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/UpdatePackages/IPackageRunner.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/UpdatePackages/IPackageRunner.cs index 03c583dca..8a3490f8d 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/UpdatePackages/IPackageRunner.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/UpdatePackages/IPackageRunner.cs @@ -10,6 +10,7 @@ namespace Tango.PPC.Common.UpdatePackages { event EventHandler<PackageStateChangedEventArgs> PackageStateChanged; Task<PackagesFile> GetPackagesFile(); - Task Run(PackageType type, String packagesFolder); + Task<PackageRunnerResult> Run(PackageType type, String packagesFolder); + Task<bool> IsPackageInstallationRequired(PackageType type, String packagesFolder); } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/UpdatePackages/PPCPackageAttribute.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/UpdatePackages/PPCPackageAttribute.cs index 7ae4ea52d..3186b57b1 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/UpdatePackages/PPCPackageAttribute.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/UpdatePackages/PPCPackageAttribute.cs @@ -13,10 +13,13 @@ namespace Tango.PPC.Common.UpdatePackages public PackageType Type { get; set; } - public PPCPackageAttribute(PackageType type, String name) + public bool RequiresRestart { get; set; } + + public PPCPackageAttribute(PackageType type, String name, bool requiresRestart) { Type = type; Name = name; + RequiresRestart = requiresRestart; } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/UpdatePackages/PackageContext.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/UpdatePackages/PackageContext.cs index cf96ff026..4cfe49af8 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/UpdatePackages/PackageContext.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/UpdatePackages/PackageContext.cs @@ -3,11 +3,16 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.PPC.Common.Application; +using Tango.PPC.Common.Connection; +using Tango.PPC.Common.Notifications; namespace Tango.PPC.Common.UpdatePackages { public class PackageContext { - + public IPPCApplicationManager ApplicationManager { get; set; } + public IMachineProvider MachineProvider { get; set; } + public INotificationProvider NotificationProvider { get; set; } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/UpdatePackages/PackageInstallation.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/UpdatePackages/PackageInstallation.cs index bcffb1b6e..bf00915bd 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/UpdatePackages/PackageInstallation.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/UpdatePackages/PackageInstallation.cs @@ -12,8 +12,15 @@ namespace Tango.PPC.Common.UpdatePackages public PackageType Type { get; set; } + public DateTime InstallationDate { get; set; } + public PackageInstallationState State { get; set; } public String FailedReason { get; set; } + + public PackageInstallation() + { + InstallationDate = DateTime.Now; + } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/UpdatePackages/PackageRunnerResult.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/UpdatePackages/PackageRunnerResult.cs new file mode 100644 index 000000000..55f3a490a --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/UpdatePackages/PackageRunnerResult.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Common.UpdatePackages +{ + public class PackageRunnerResult + { + public bool RestartRequired { get; set; } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/UpdatePackages/PackageStateChangedEventArgs.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/UpdatePackages/PackageStateChangedEventArgs.cs index 62eb00e5e..9c8cbe2c0 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/UpdatePackages/PackageStateChangedEventArgs.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/UpdatePackages/PackageStateChangedEventArgs.cs @@ -10,5 +10,6 @@ namespace Tango.PPC.Common.UpdatePackages { public PackageInstallationState State { get; set; } public String PackageName { get; set; } + public PackageType PackageType { get; set; } } } 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 /// </summary> public DateTime StartUpDate { get; private set; } + /// <summary> + /// Gets a value indicating whether an update has occurred before the application started. + /// </summary> + public bool IsAfterUpdate { get; private set; } + private bool _isScreenLocked; /// <summary> /// 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 /// <summary> /// Restarts the application. /// </summary> - 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<INavigationManager>(); + 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<PPCViewModel>()) 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 @@ <Compile Include="ViewModels\MachineUpdateViewVM.cs" /> <Compile Include="ViewModels\NoPermissionsViewVM.cs" /> <Compile Include="ViewModels\RestartingSystemViewVM.cs" /> + <Compile Include="ViewModels\RestartingViewVM.cs" /> <Compile Include="ViewsContracts\ILayoutView.cs" /> <Compile Include="ViewsContracts\IMachineSetupView.cs" /> <Compile Include="ViewsContracts\IMachineUpdateView.cs" /> @@ -180,6 +181,9 @@ <Compile Include="Views\LoadingErrorView.xaml.cs"> <DependentUpon>LoadingErrorView.xaml</DependentUpon> </Compile> + <Compile Include="Views\RestartingView.xaml.cs"> + <DependentUpon>RestartingView.xaml</DependentUpon> + </Compile> <Compile Include="Views\LoadingView.xaml.cs"> <DependentUpon>LoadingView.xaml</DependentUpon> </Compile> @@ -269,6 +273,10 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="Views\RestartingView.xaml"> + <Generator>MSBuild:Compile</Generator> + <SubType>Designer</SubType> + </Page> <Page Include="Views\LoadingView.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> @@ -608,7 +616,7 @@ if $(ConfigurationName) == Release del *.xml</PostBuildEvent> </PropertyGroup> <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.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<IOperationSystemManager>(); TangoIOC.Default.Unregister<PPCWebClient>(); TangoIOC.Default.Unregister<IBackupManager>(); + TangoIOC.Default.Unregister<IPackageRunner>(); TangoIOC.Default.Register<PPCWebClient, PPCWebClient>(new PPCWebClient()); TangoIOC.Default.Register<IDispatcherProvider, DefaultDispatcherProvider>(new DefaultDispatcherProvider(Application.Current.Dispatcher)); @@ -110,6 +111,7 @@ namespace Tango.PPC.UI TangoIOC.Default.Register<NoPermissionsViewVM>(); TangoIOC.Default.Register<RestartingSystemViewVM>(); TangoIOC.Default.Register<EmergencyViewVM>(); + TangoIOC.Default.Register<RestartingViewVM>(); TangoIOC.Default.GetInstance<IPPCApplicationManager>().ContentRendered += (_, __) => @@ -215,5 +217,13 @@ namespace Tango.PPC.UI return TangoIOC.Default.GetInstance<EmergencyViewVM>(); } } + + public static RestartingViewVM RestartingViewVM + { + get + { + return TangoIOC.Default.GetInstance<RestartingViewVM>(); + } + } } }
\ 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 @@ <local:MachineUpdateView></local:MachineUpdateView> <local:RestartingSystemView></local:RestartingSystemView> <local:EmergencyView></local:EmergencyView> + <local:RestartingView></local:RestartingView> </controls:NavigationControl> </touch:TouchPanel> </Grid> 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 @@ +<UserControl x:Class="Tango.PPC.UI.Views.RestartingView" + 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:vm="clr-namespace:Tango.PPC.UI.ViewModels" + xmlns:fx="clr-namespace:Tango.SharedUI.Effects;assembly=Tango.SharedUI" + xmlns:gif="clr-namespace:Tango.AnimatedGif;assembly=Tango.AnimatedGif" + xmlns:global="clr-namespace:Tango.PPC.UI" + xmlns:touch="clr-namespace:Tango.Touch.Controls;assembly=Tango.Touch" + xmlns:local="clr-namespace:Tango.PPC.UI.Views" + mc:Ignorable="d" + d:DesignHeight="1280" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=vm:RestartingViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.RestartingViewVM}"> + <Grid> + <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"> + <Grid Margin="0 100 0 0"> + <Image Source="/Images/machine.png" Stretch="Uniform" Width="250" RenderOptions.BitmapScalingMode="Fant"></Image> + <touch:TouchBusyIndicator Foreground="{StaticResource TangoGrayBrush}" Width="350" Height="350" IsIndeterminate="{Binding IsVisible}" /> + </Grid> + + <TextBlock Margin="0 40 0 0" HorizontalAlignment="Center" FontSize="{StaticResource TangoTitleFontSize}" Foreground="{StaticResource TangoGrayTextBrush}"> + <Run>v</Run><Run Text="{Binding ApplicationManager.Version,Mode=OneWay}"></Run> + </TextBlock> + <TextBlock FontSize="{StaticResource TangoHeaderFontSize}" Margin="0 100 0 0" HorizontalAlignment="Center" Width="170"> + <TextBlock.Style> + <Style TargetType="TextBlock"> + <Setter Property="Text" Value="Restarting"></Setter> + <Style.Triggers> + <DataTrigger Binding="{Binding IsVisible}" Value="True"> + <DataTrigger.EnterActions> + <BeginStoryboard x:Name="storyRes"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Text" RepeatBehavior="5x"> + <DiscreteObjectKeyFrame KeyTime="00:00:0.2" Value="Restarting." /> + <DiscreteObjectKeyFrame KeyTime="00:00:0.6" Value="Restarting.." /> + <DiscreteObjectKeyFrame KeyTime="00:00:0.9" Value="Restarting..." /> + <DiscreteObjectKeyFrame KeyTime="00:00:1.4" Value="Restarting..." /> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </BeginStoryboard> + </DataTrigger.EnterActions> + <DataTrigger.ExitActions> + <RemoveStoryboard BeginStoryboardName="storyRes" /> + </DataTrigger.ExitActions> + </DataTrigger> + </Style.Triggers> + </Style> + </TextBlock.Style> + </TextBlock> + </StackPanel> + </Grid> +</UserControl> 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 +{ + /// <summary> + /// Interaction logic for LoadingView.xaml + /// </summary> + public partial class RestartingView : UserControl + { + public RestartingView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/PPC/UpdatePackages/Tango.PPC.Packages.SamplePostPackage/SamplePostPackage.cs b/Software/Visual_Studio/PPC/UpdatePackages/Tango.PPC.Packages.SamplePostPackage/SamplePostPackage.cs index 0d5e117da..25c2c514b 100644 --- a/Software/Visual_Studio/PPC/UpdatePackages/Tango.PPC.Packages.SamplePostPackage/SamplePostPackage.cs +++ b/Software/Visual_Studio/PPC/UpdatePackages/Tango.PPC.Packages.SamplePostPackage/SamplePostPackage.cs @@ -8,7 +8,7 @@ using Tango.PPC.Common.UpdatePackages; namespace Tango.PPC.Packages.SamplePostPackage { - [PPCPackage(PackageType.Post, "Sample Post Package")] + [PPCPackage(PackageType.Post, "Sample Post Package", true)] public class SamplePostPackage : ExtendedObject, IPPCPackage { public Task Run(PackageContext context) diff --git a/Software/Visual_Studio/PPC/UpdatePackages/Tango.PPC.Packages.SamplePrePackage/SamplePrePackage.cs b/Software/Visual_Studio/PPC/UpdatePackages/Tango.PPC.Packages.SamplePrePackage/SamplePrePackage.cs index 1e51e9c94..5aa811e85 100644 --- a/Software/Visual_Studio/PPC/UpdatePackages/Tango.PPC.Packages.SamplePrePackage/SamplePrePackage.cs +++ b/Software/Visual_Studio/PPC/UpdatePackages/Tango.PPC.Packages.SamplePrePackage/SamplePrePackage.cs @@ -8,7 +8,7 @@ using Tango.PPC.Common.UpdatePackages; namespace Tango.PPC.Packages.SamplePrePackage { - [PPCPackage(PackageType.Pre, "Sample Pre Package")] + [PPCPackage(PackageType.Pre, "Sample Pre Package", false)] public class SamplePrePackage : ExtendedObject, IPPCPackage { public Task Run(PackageContext context) |
