diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-08-30 19:04:18 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-08-30 19:04:18 +0300 |
| commit | 37e5138e6acac4a9b93e018087fe9c50d36c4b34 (patch) | |
| tree | 4acec95a8e5362c67f0e0fc5444c40c23791776d /Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels | |
| parent | 3d9beda13daccac78fb05dc94d1430a0a47e9db6 (diff) | |
| download | Tango-37e5138e6acac4a9b93e018087fe9c50d36c4b34.tar.gz Tango-37e5138e6acac4a9b93e018087fe9c50d36c4b34.zip | |
Implemented machine update on PPC !!!
Need to verify update scripts...
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels')
3 files changed, 183 insertions, 3 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs index 28692cdfa..fd36d0d13 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs @@ -84,6 +84,10 @@ namespace Tango.PPC.UI.ViewModels /// </summary> public RelayCommand SignOutCommand { get; set; } + /// <summary> + /// Gets or sets the update command. + /// </summary> + public RelayCommand UpdateCommand { get; set; } #endregion #region Constructors @@ -100,6 +104,11 @@ namespace Tango.PPC.UI.ViewModels StopPrintingCommand = new RelayCommand(StopPrinting); SignOutCommand = new RelayCommand(SignOut); + UpdateCommand = new RelayCommand(() => + { + NavigationManager.NavigateTo(NavigationView.MachineUpdateView); + TangoIOC.Default.GetInstance<MachineUpdateViewVM>().CheckForUpdates(); + }); } #endregion diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs index 0f66b6fc8..f3cb83ffe 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data.SqlClient; using System.Diagnostics; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -227,11 +228,11 @@ namespace Tango.PPC.UI.ViewModels /// </summary> private void CompleteSetup() { - String updater_exe = AssemblyHelper.GetCurrentAssemblyFolder() + "\\Tango.PPC.Updater.exe"; + String updater_exe = Path.Combine(_setup_result.UpdatePackagePath, "Tango.PPC.Updater.exe"); LogManager.Log("Completing machine setup..."); - LogManager.Log($"Executing '{updater_exe}' with arguments '{_setup_result.UpdatePackagePath}'..."); - Process.Start(updater_exe, _setup_result.UpdatePackagePath); + LogManager.Log($"Executing '{updater_exe}' with arguments '{PathHelper.GetStartupPath()}'..."); + Process.Start(updater_exe, PathHelper.GetStartupPath()); LogManager.Log("Terminating application process!"); Environment.Exit(0); } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs new file mode 100644 index 000000000..84e65e516 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs @@ -0,0 +1,170 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.Commands; +using Tango.Core.Helpers; +using Tango.PPC.Common; +using Tango.PPC.Common.MachineUpdate; +using Tango.PPC.UI.ViewsContracts; + +namespace Tango.PPC.UI.ViewModels +{ + public class MachineUpdateViewVM : PPCViewModel<IMachineUpdateView> + { + public enum MachineUpdateView + { + + UpdateCheckView, + UpdateCheckErrorView, + UpdateAvailableView, + UpToDateView, + UpdateProgressView, + UpdateCompletedView, + UpdateFailedView, + } + + private MachineUpdateResult _update_result; + + #region Properties + + /// <summary> + /// Gets or sets the machine update manager. + /// </summary> + public IMachineUpdateManager MachineUpdateManager { get; set; } + + private String _latestVersion; + /// <summary> + /// Gets or sets the latest version. + /// </summary> + public String LatestVersion + { + get { return _latestVersion; } + set { _latestVersion = value; RaisePropertyChangedAuto(); } + } + + #endregion + + #region Commands + + /// <summary> + /// Gets or sets the complete command. + /// </summary> + public RelayCommand CompleteCommand { get; set; } + + /// <summary> + /// Gets or sets the install command. + /// </summary> + public RelayCommand UpdateCommand { get; set; } + + /// <summary> + /// Gets or sets the restart command. + /// </summary> + public RelayCommand RestartCommand { get; set; } + + /// <summary> + /// Gets or sets the close command. + /// </summary> + public RelayCommand CloseCommand { get; set; } + + #endregion + + #region Constructors + + public MachineUpdateViewVM(IMachineUpdateManager machineUpdateManager) + { + MachineUpdateManager = machineUpdateManager; + + CompleteCommand = new RelayCommand(CompleteUpdate); + UpdateCommand = new RelayCommand(Update); + RestartCommand = new RelayCommand(CheckForUpdates); + CloseCommand = new RelayCommand(() => + { + NavigationManager.NavigateTo(Common.Navigation.NavigationView.HomeModule); + NavigateTo(MachineUpdateView.UpdateCheckView); + }); + } + + #endregion + + #region Update + + public async void CheckForUpdates() + { + await NavigateTo(MachineUpdateView.UpdateCheckView); + + try + { + var response = await MachineUpdateManager.CheckForUpdate(MachineProvider.Machine.SerialNumber, "http://localhost:51581/"); + + if (response.IsUpdateAvailable) + { + LatestVersion = response.Version; + await NavigateTo(MachineUpdateView.UpdateAvailableView); + } + else + { + await NavigateTo(MachineUpdateView.UpToDateView); + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error while trying to check for updates."); + await NavigateTo(MachineUpdateView.UpdateFailedView); + } + } + + private async void Update() + { + await NavigateTo(MachineUpdateView.UpdateProgressView); + + LogManager.Log("Starting machine update..."); + + try + { + _update_result = await MachineUpdateManager.Update(MachineProvider.Machine.SerialNumber, "http://localhost:51581/"); + LogManager.Log("Machine update completed."); + await NavigateTo(MachineUpdateView.UpdateCompletedView); + } + catch (Exception ex) + { + LogManager.Log(ex, "Machine update failed."); + await NavigateTo(MachineUpdateView.UpdateFailedView); + } + } + + #endregion + + #region Complete + + private void CompleteUpdate() + { + String updater_exe = Path.Combine(_update_result.UpdatePackagePath, "Tango.PPC.Updater.exe"); + + LogManager.Log("Completing machine setup..."); + LogManager.Log($"Executing '{updater_exe}' with arguments '{PathHelper.GetStartupPath()}'..."); + Process.Start(updater_exe, PathHelper.GetStartupPath()); + LogManager.Log("Terminating application process!"); + Environment.Exit(0); + } + + #endregion + + public override void OnApplicationStarted() + { + + } + + /// <summary> + /// Navigates to the specified view. + /// </summary> + /// <param name="view">The view.</param> + private Task NavigateTo(MachineUpdateView view) + { + return View.NavigateTo(view); + } + } +} |
