diff options
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels')
10 files changed, 64 insertions, 1184 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs index f10e84d05..f1127ebfe 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs @@ -12,7 +12,6 @@ using Tango.PMR.Integration; using Tango.PPC.Common; using Tango.PPC.Common.ExternalBridge; using Tango.PPC.Common.Navigation; -using Tango.PPC.UI.Dialogs; namespace Tango.PPC.UI.ViewModels { @@ -25,8 +24,6 @@ namespace Tango.PPC.UI.ViewModels { private bool _disconnecting; - private const int KEEP_SAFETY_AUTHENTICATION_MINUTES = 5; - #region Properties private ExternalBridgeClientConnectedEventArgs _connection; @@ -82,7 +79,7 @@ namespace Tango.PPC.UI.ViewModels LogManager.Log("Disconnecting current external bridge session."); _disconnecting = true; InvalidateRelayCommands(); - ExternalBridgeService.DisconnectFullControlSession(); + ExternalBridgeService.DisconnectSession(); } #endregion @@ -106,7 +103,7 @@ namespace Tango.PPC.UI.ViewModels public override void OnApplicationStarted() { ExternalBridgeService.ConnectionRequest += ExternalBridgeService_ConnectionRequest; - ExternalBridgeService.FullControlSessionDisconnected += ExternalBridgeService_FullControlSessionDisconnected; + ExternalBridgeService.ClientDisconnected += ExternalBridgeService_ClientDisconnected; } #endregion @@ -114,11 +111,11 @@ namespace Tango.PPC.UI.ViewModels #region Event Handlers /// <summary> - /// Handles the <see cref="ExternalBridgeService.FullControlSessionDisconnected"/> event. + /// Handles the <see cref="ExternalBridgeService.ClientDisconnected"/> event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> - private void ExternalBridgeService_FullControlSessionDisconnected(object sender, EventArgs e) + private void ExternalBridgeService_ClientDisconnected(object sender, EventArgs e) { if (IsVisible) { @@ -136,14 +133,13 @@ namespace Tango.PPC.UI.ViewModels /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="ExternalBridgeClientConnectedEventArgs"/> instance containing the event data.</param> - private async void ExternalBridgeService_ConnectionRequest(object sender, ExternalBridgeClientConnectedEventArgs e) + private void ExternalBridgeService_ConnectionRequest(object sender, ExternalBridgeClientConnectedEventArgs e) { LogManager.Log($"External bridge connection request received.\n{e.ToJsonString()}"); if (!e.Request.Intent.RequiresPassword() || e.Request.Password == Settings.ExternalBridgePassword) { - e.ApplicationInformation.Version = ApplicationManager.Version.ToString(); - e.ApplicationInformation.StartupDate = ApplicationManager.StartUpDate.ToUniversalTime().ToString(); + e.Confirmed = true; Connection = e; @@ -154,41 +150,6 @@ namespace Tango.PPC.UI.ViewModels LogManager.Log($"External bridge connection user has been identified as {User.Contact.FullName}"); } - if (e.Request.RequireSafetyLevelOperations) - { - DateTime lastAuthenticationTime; - bool bypassSafetyConfirmation = false; - - if (ExternalBridgeReceiver.LastSafetyLevelContactsTimes.TryGetValue(e.Request.UserName, out lastAuthenticationTime)) - { - if (DateTime.Now < lastAuthenticationTime.AddMinutes(KEEP_SAFETY_AUTHENTICATION_MINUTES)) - { - bypassSafetyConfirmation = true; - e.Confirm(); - } - } - - if (!bypassSafetyConfirmation) - { - SafetyLevelOperationsConfirmationViewVM vm = new SafetyLevelOperationsConfirmationViewVM(e); - await NotificationProvider.ShowDialog(vm); - - if (vm.DialogResult) - { - e.Confirm(); - } - else - { - e.Decline("Safety level connection refused by the remote user."); - return; - } - } - } - else - { - e.Confirm(); - } - if (e.Request.Intent == ExternalBridgeLoginIntent.FullControl) { LogManager.Log("Navigating to external bridge view..."); @@ -200,7 +161,6 @@ namespace Tango.PPC.UI.ViewModels } else { - e.Decline("Connection password did not match the machine external bridge password."); LogManager.Log("Connection password did not match the machine external bridge password."); } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/InternalModuleViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/InternalModuleViewVM.cs deleted file mode 100644 index 29e6417f4..000000000 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/InternalModuleViewVM.cs +++ /dev/null @@ -1,17 +0,0 @@ -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 InternalModuleViewVM : PPCViewModel - { - public override void OnApplicationStarted() - { - - } - } -} 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 a2baec8b8..9e8a9fe34 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs @@ -3,19 +3,13 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using System.Windows; -using System.Windows.Media; using System.Windows.Threading; -using Tango.Core; using Tango.Core.Commands; using Tango.Core.DI; using Tango.Integration.Operation; -using Tango.PMR.IFS; using Tango.PPC.Common; -using Tango.PPC.Common.Connection; using Tango.PPC.Common.Modules; using Tango.PPC.Common.Navigation; -using Tango.PPC.UI.Views; using Tango.PPC.UI.ViewsContracts; using Tango.SharedUI; @@ -28,7 +22,6 @@ namespace Tango.PPC.UI.ViewModels public class LayoutViewVM : PPCViewModel<ILayoutView> { private JobHandler _jobHandler; - private bool _resettingDevice; /// <summary> /// Gets or sets the module loader. @@ -36,86 +29,6 @@ namespace Tango.PPC.UI.ViewModels [TangoInject] public IPPCModuleLoader ModuleLoader { get; set; } - #region Classes - - public class CartridgeModel : ExtendedObject - { - private IMachineProvider _machineProvider; - - public CartridgeStatus Status { get; set; } - - public bool InProgress - { - get { return Status.State == CartridgeState.Filling || Status.State == CartridgeState.Emptying; } - } - - public String Message - { - get { return Status.Cartridge.Slot == PMR.Diagnostics.CartridgeSlot.Ink ? "Ink filling is in progress..." : "Waste emptying is in progress..."; } - } - - public Brush Brush - { - get - { - if (Status.Cartridge.Slot == PMR.Diagnostics.CartridgeSlot.Ink) - { - try - { - int index = Status.Cartridge.Index; - - var idsPack = _machineProvider.Machine.Configuration.NoneEmptyIdsPacks.FirstOrDefault(x => x.PackIndex == index); - - if (idsPack != null) - { - switch (idsPack.LiquidType.Type) - { - case BL.Enumerations.LiquidTypes.Cyan: - return Application.Current.Resources["TangoCyanInkBrush"] as Brush; - case BL.Enumerations.LiquidTypes.Magenta: - return Application.Current.Resources["TangoMagentaInkBrush"] as Brush; - case BL.Enumerations.LiquidTypes.Yellow: - return Application.Current.Resources["TangoYellowInkBrush"] as Brush; - case BL.Enumerations.LiquidTypes.Black: - return Application.Current.Resources["TangoBlackInkBrush"] as Brush; - case BL.Enumerations.LiquidTypes.Lubricant: - return Application.Current.Resources["TangoLubricantBrush"] as Brush; - case BL.Enumerations.LiquidTypes.Cleaner: - return Application.Current.Resources["TangoCleanerBrush"] as Brush; - case BL.Enumerations.LiquidTypes.TransparentInk: - return Application.Current.Resources["TangoTransparentInkBrush"] as Brush; - } - } - } - catch (Exception ex) - { - LogManager.Log(ex, "Error generating ink filling brush."); - } - - return Application.Current.Resources["TangoPrimaryAccentBrush"] as Brush; - } - else - { - return Application.Current.Resources["TangoWasteBrush"] as Brush; - } - } - } - - public CartridgeModel(IMachineProvider machineProvider) - { - _machineProvider = machineProvider; - Status = new CartridgeStatus(); - } - - public void Invalidate() - { - RaisePropertyChanged(nameof(InProgress)); - RaisePropertyChanged(nameof(Status)); - } - } - - #endregion - #region Properties private bool _isMenuOpened; @@ -159,23 +72,6 @@ namespace Tango.PPC.UI.ViewModels set { _isPowerOpened = value; RaisePropertyChangedAuto(); } } - private bool _isInkFillingOrWasteEmptying; - /// <summary> - /// Gets or sets a value indicating whether ink filling or waste emptying is active. - /// </summary> - public bool IsInkFillingOrWasteEmptying - { - get { return _isInkFillingOrWasteEmptying; } - set { _isInkFillingOrWasteEmptying = value; RaisePropertyChangedAuto(); } - } - - private List<CartridgeModel> _cartridges; - public List<CartridgeModel> Cartridges - { - get { return _cartridges; } - set { _cartridges = value; RaisePropertyChangedAuto(); } - } - #endregion #region Commands @@ -225,21 +121,6 @@ namespace Tango.PPC.UI.ViewModels /// </summary> public RelayCommand RestartApplicationCommand { get; set; } - /// <summary> - /// Gets or sets the power off command. - /// </summary> - public RelayCommand PowerOffCommand { get; set; } - - /// <summary> - /// Gets or sets the reset command. - /// </summary> - public RelayCommand ResetCommand { get; set; } - - /// <summary> - /// Gets or sets the stand by command. - /// </summary> - public RelayCommand StandByCommand { get; set; } - #endregion #region Constructors @@ -256,13 +137,15 @@ namespace Tango.PPC.UI.ViewModels StopPrintingCommand = new RelayCommand(StopPrinting); SignOutCommand = new RelayCommand(SignOut); - UpdateCommand = new RelayCommand(UpdateMachine); + UpdateCommand = new RelayCommand(() => + { + NavigationManager.NavigateTo(NavigationView.MachineUpdateView); + TangoIOC.Default.GetInstance<MachineUpdateViewVM>().CheckForUpdates(); + IsMenuOpened = false; + }); PowerCommand = new RelayCommand(() => IsPowerOpened = true); RestartApplicationCommand = new RelayCommand(RestartApplication); - PowerOffCommand = new RelayCommand(PowerOffMachine, () => MachineProvider.MachineOperator.Status != MachineStatuses.Disconnected); - ResetCommand = new RelayCommand(ResetMachine, () => MachineProvider.MachineOperator.Status != MachineStatuses.Disconnected); - StandByCommand = new RelayCommand(StandBy, () => MachineProvider.MachineOperator.CanPrint); } #endregion @@ -356,83 +239,6 @@ namespace Tango.PPC.UI.ViewModels } } - /// <summary> - /// Powers off the machine. - /// </summary> - private async void PowerOffMachine() - { - IsMenuOpened = false; - - if (await NotificationProvider.ShowQuestion("Are you sure you wish to turn off the machine?")) - { - try - { - await MachineProvider.MachineOperator.PowerDown(); - } - catch (Exception ex) - { - LogManager.Log(ex, "Error triggering power down."); - await NotificationProvider.ShowError(ex.FlattenMessage()); - } - } - } - - /// <summary> - /// Resets the machine. - /// </summary> - private async void ResetMachine() - { - IsMenuOpened = false; - - if (!await NotificationProvider.ShowQuestion("Are you sure you want to reset the machine?")) return; - - try - { - _resettingDevice = true; - ResetCommand.RaiseCanExecuteChanged(); - await MachineProvider.MachineOperator.Reset(); - await NotificationProvider.ShowInfo("Machine was successfully restarted."); - } - catch (Exception ex) - { - await NotificationProvider.ShowError(ex.FlattenMessage()); - } - finally - { - _resettingDevice = false; - ResetCommand.RaiseCanExecuteChanged(); - } - } - - private async void StandBy() - { - IsMenuOpened = false; - - try - { - LogManager.Log("Executing stand-by command."); - await MachineProvider.MachineOperator.StandBy(); - } - catch (Exception ex) - { - LogManager.Log(ex, "Error switching to stand-by mode."); - await NotificationProvider.ShowError($"Error switching to stand-by mode.\n{ex.FlattenMessage()}"); - } - } - - private void UpdateMachine() - { - if (MachineProvider.MachineOperator.IsPrinting) - { - NotificationProvider.ShowInfo("Cannot perform a machine update while the machine is dyeing."); - return; - } - - NavigationManager.NavigateTo(NavigationView.MachineUpdateView); - TangoIOC.Default.GetInstance<MachineUpdateViewVM>().CheckForUpdates(); - IsMenuOpened = false; - } - #endregion #region Override Methods @@ -444,34 +250,6 @@ namespace Tango.PPC.UI.ViewModels { base.OnApplicationStarted(); MachineProvider.MachineOperator.PrintingStarted += MachineOperator_PrintingStarted; - MachineProvider.MachineOperator.InkFillingStatusChanged += MachineOperator_InkFillingStatusChanged; - } - - private void MachineOperator_InkFillingStatusChanged(object sender, InkFillingStatusChangedEventArgs e) - { - if (Cartridges == null) - { - Cartridges = MachineProvider.MachineOperator.InkFillingStatus.CartridgesStatuses.Select(x => new CartridgeModel(MachineProvider) { Status = x }).ToList(); - } - else - { - foreach (var cartridgeStatus in e.Status.CartridgesStatuses) - { - var model = Cartridges.SingleOrDefault(x => x.Status == cartridgeStatus); - - if (model != null) - { - model.Status = cartridgeStatus; - } - } - } - - foreach (var cartridgeModel in Cartridges) - { - cartridgeModel.Invalidate(); - } - - IsInkFillingOrWasteEmptying = Cartridges.Any(x => x.Status.State == CartridgeState.Filling || x.Status.State == CartridgeState.Emptying); } /// <summary> @@ -482,22 +260,6 @@ namespace Tango.PPC.UI.ViewModels } - public override void OnApplicationReady() - { - base.OnApplicationReady(); - MachineProvider.MachineOperator.StatusChanged += MachineOperator_StatusChanged; - } - - private void MachineOperator_StatusChanged(object sender, MachineStatuses e) - { - InvokeUI(() => - { - PowerOffCommand.RaiseCanExecuteChanged(); - ResetCommand.RaiseCanExecuteChanged(); - StandByCommand.RaiseCanExecuteChanged(); - }); - } - #endregion #region Public Methods diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs index 38dd569e1..f926a0f4c 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs @@ -74,46 +74,37 @@ namespace Tango.PPC.UI.ViewModels /// </summary> public async override void OnApplicationStarted() { - //We don't use authentication! - - //using (ObservablesContext db = ObservablesContext.CreateDefault()) - //{ - // var machine = await db.Machines.FirstAsync(); - - // if (db.Users.Count() == 1 || machine.AutoLogin) - // { - // var user = await new UserBuilder(db).SetFirst().WithRolesAndPermissions().BuildAsync(); + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + var machine = await db.Machines.FirstAsync(); - // if (!user.HasRole(Roles.PPCUser)) - // { - // var role = db.Roles.Single(x => x.Code == (int)Roles.PPCUser); - // user.Roles.Add(role); - // db.UsersRoles.Add(new BL.Entities.UsersRole() - // { - // User = user, - // Role = role, - // }); - // await db.SaveChangesAsync(); - // } + if (db.Users.Count() == 1 || machine.AutoLogin) + { + var user = await new UserBuilder(db).SetFirst().WithRolesAndPermissions().BuildAsync(); - // LogManager.Log($"Application started. Single user/Auto login detected ({user.Email}). Skipping LoginView..."); - // await AuthenticationProvider.Login(user.Email, user.Password, false); - // await Task.Delay(1000); - // IsLoading = false; - // } - // else - // { - // LogManager.Log("Application started. Navigating to LoginView..."); - // await NavigationManager.NavigateTo(NavigationView.LoginView); - // await Task.Delay(1000); - // IsLoading = false; - // } - //} + if (!user.HasRole(Roles.PPCUser)) + { + var role = db.Roles.Single(x => x.Code == (int)Roles.PPCUser); + user.Roles.Add(role); + db.UsersRoles.Add(new BL.Entities.UsersRole() + { + User = user, + Role = role, + }); + await db.SaveChangesAsync(); + } - LogManager.Log($"Application started with no authentication mode..."); - await AuthenticationProvider.Login(); - await Task.Delay(1000); - IsLoading = false; + LogManager.Log($"Application started. Single user/Auto login detected ({user.Email}). Skipping LoginView..."); + await AuthenticationProvider.Login(user.Email, user.Password, false); + IsLoading = false; + } + else + { + LogManager.Log("Application started. Navigating to LoginView..."); + await NavigationManager.NavigateTo(NavigationView.LoginView); + IsLoading = false; + } + } } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoginViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoginViewVM.cs index ec316989f..aa9689ef3 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoginViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoginViewVM.cs @@ -92,13 +92,7 @@ namespace Tango.PPC.UI.ViewModels await Task.Delay(500); - if (!AuthenticationProvider.AuthenticationRequired) - { - LogManager.Log("Application is ready! Navigating to home module..."); - await NavigationManager.NavigateTo(NavigationView.HomeModule); - IsLoading = false; - } - else if (AuthenticationProvider.CurrentUser != null && AuthenticationProvider.CurrentUser.HasPermission(Permissions.RunPPC)) + if (AuthenticationProvider.CurrentUser != null && AuthenticationProvider.CurrentUser.HasPermission(Permissions.RunPPC)) { LogManager.Log("Application is ready! Navigating to home module..."); await NavigationManager.NavigateTo(NavigationView.HomeModule); 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 ae31a64a1..aca9dbcf7 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs @@ -347,10 +347,7 @@ namespace Tango.PPC.UI.ViewModels try { - if (!App.StartupArgs.Contains("-webDebug")) - { - _ppcWebClient.Environment = DeploymentSlot; - } + _ppcWebClient.Environment = DeploymentSlot; await _operationSystemManager.ChangeTimeZone(SelectedTimeZone); _setup_result = await MachineSetupManager.Setup(SerialNumber); State = MachineSetupStates.Completed; 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 5fe153ee9..01e67d3ce 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs @@ -1,38 +1,22 @@ using System; using System.Collections.Generic; -using System.Data.Entity; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; -using System.Threading; using System.Threading.Tasks; -using Tango.BL; -using Tango.Core; using Tango.Core.Commands; -using Tango.Core.ExtensionMethods; using Tango.Core.Helpers; -using Tango.Core.Threading; using Tango.Explorer; -using Tango.Integration.ExternalBridge; -using Tango.PMR.FirmwareUpgrade; using Tango.PPC.Common; -using Tango.PPC.Common.Application; -using Tango.PPC.Common.ExternalBridge; using Tango.PPC.Common.MachineUpdate; -using Tango.PPC.Common.Navigation; -using Tango.PPC.Common.Notifications; -using Tango.PPC.Common.Publish; using Tango.PPC.Common.Web; -using Tango.PPC.Shared.RemoteUpgrade; using Tango.PPC.UI.Dialogs; -using Tango.PPC.UI.Notifications.NotificationItems; using Tango.PPC.UI.ViewsContracts; -using Tango.Transport; namespace Tango.PPC.UI.ViewModels { - public class MachineUpdateViewVM : PPCViewModel<IMachineUpdateView>, IExternalBridgeRequestHandler + public class MachineUpdateViewVM : PPCViewModel<IMachineUpdateView> { public enum MachineUpdateView { @@ -52,7 +36,6 @@ namespace Tango.PPC.UI.ViewModels private DbCompareResult _db_compare_result; private bool _isChecking; private CheckForUpdateResponse _checkUpdateResponse; - private UpdateAvailableNotificationItem _updateNotificationItem; #region Properties @@ -124,10 +107,9 @@ namespace Tango.PPC.UI.ViewModels #region Constructors - public MachineUpdateViewVM(IMachineUpdateManager machineUpdateManager, IPPCExternalBridgeService externalBridge, IPPCApplicationManager applicationManager, INavigationManager navigationManager, INotificationProvider notificationProvider) + public MachineUpdateViewVM(IMachineUpdateManager machineUpdateManager) { MachineUpdateManager = machineUpdateManager; - externalBridge.RegisterRequestHandler(this); CompleteCommand = new RelayCommand(CompleteUpdate); UpdateCommand = new RelayCommand(Update); @@ -143,13 +125,6 @@ namespace Tango.PPC.UI.ViewModels NavigationManager.NavigateTo(Common.Navigation.NavigationView.HomeModule); NavigateTo(MachineUpdateView.UpdateCheckView); }); - - machineUpdateManager.UpdateAvailable += MachineUpdateManager_UpdateAvailable; - - NavigationManager = navigationManager; - NotificationProvider = notificationProvider; - ApplicationManager = applicationManager; - ApplicationManager.UpdaterFailed += ApplicationManager_UpdaterFailed; } #endregion @@ -175,28 +150,7 @@ namespace Tango.PPC.UI.ViewModels return; } - var response = await MachineUpdateManager.CheckForUpdate(); - - try - { - if (response.UsedNotExistingRmlsGuids.Count > 0) - { - using (ObservablesContext db = ObservablesContext.CreateDefault()) - { - var arr = response.UsedNotExistingRmlsGuids.ToArray(); - var jobs = await db.Jobs.Where(x => arr.Contains(x.RmlGuid)).ToListAsync(); - FailedError = $"The following jobs must be removed or change thread type before the system can be updated:\n{String.Join("\n", jobs.Select(x => x.Name))}"; - _isChecking = false; - await NavigateTo(MachineUpdateView.UpdateFailedView); - return; - } - } - } - catch (Exception ex) - { - LogManager.Log(ex, "Error on used RML check procedure."); - } - + var response = await MachineUpdateManager.CheckForUpdate(MachineProvider.Machine.SerialNumber); _checkUpdateResponse = response; if (response.IsUpdateAvailable) @@ -204,19 +158,9 @@ 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(); + _db_compare_result = await MachineUpdateManager.UpdateDBCheck(MachineProvider.Machine.SerialNumber); if (_db_compare_result.RequiresUpdate) { @@ -251,7 +195,7 @@ namespace Tango.PPC.UI.ViewModels try { - _update_result = await MachineUpdateManager.Update(_checkUpdateResponse.SetupFirmware, _checkUpdateResponse.SetupFPGA); + _update_result = await MachineUpdateManager.Update(MachineProvider.Machine.SerialNumber, _checkUpdateResponse.SetupFirmware, _checkUpdateResponse.SetupFPGA); LogManager.Log("Machine update completed."); await NavigateTo(MachineUpdateView.UpdateCompletedView); } @@ -269,7 +213,7 @@ namespace Tango.PPC.UI.ViewModels try { - await MachineUpdateManager.UpdateDB(_db_compare_result); + await MachineUpdateManager.UpdateDB(_db_compare_result, MachineProvider.Machine.SerialNumber); LogManager.Log("Database update completed."); await NavigateTo(MachineUpdateView.UpdateCompletedView); } @@ -290,15 +234,15 @@ namespace Tango.PPC.UI.ViewModels { LogManager.Log("Completing machine update..."); - if (IsDbUpdate || !_update_result.RequiresBinariesUpdate) + if (!IsDbUpdate) { - LogManager.Log("Restarting Application..."); - ApplicationManager.Restart(); + String updater_exe = Path.Combine(_update_result.UpdatePackagePath, "Tango.PPC.Updater.exe"); + ApplicationManager.UpdateApplication(updater_exe, PathHelper.GetStartupPath()); } else { - String updater_exe = Path.Combine(_update_result.UpdatePackagePath, "Tango.PPC.Updater.exe"); - ApplicationManager.UpdateApplication(updater_exe, PathHelper.GetStartupPath()); + LogManager.Log("Restarting Application..."); + ApplicationManager.Restart(); } } @@ -331,100 +275,15 @@ namespace Tango.PPC.UI.ViewModels base.OnApplicationReady(); StorageProvider.RegisterFileHandler(ExplorerFileDefinition.Update.Extension, HandleSoftwareUpdatePackageLoaded); - StorageProvider.RegisterFileHandler(ExplorerFileDefinition.Firmware.Extension, HandleFirmwareUpgradeLoaded); - - if (ApplicationManager.IsAfterUpdate) - { - RunPostUpdatePackages(); - } - else - { - MachineUpdateManager.EnableAutoCheckForUpdates = true; - } - } - - /// <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 - - #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 #region Handle USB Update - private async void HandleSoftwareUpdatePackageLoaded(List<ExplorerFileItem> fileItems) + private async void HandleSoftwareUpdatePackageLoaded(ExplorerFileItem fileItem) { - var fileItem = fileItems.FirstOrDefault(); - - if (fileItem == null) return; - - PublishInfo packageFile = null; - - LogManager.Log("TUP file loaded from storage..."); + UpdatePackageFile packageFile = null; try { @@ -432,394 +291,43 @@ namespace Tango.PPC.UI.ViewModels } catch (Exception ex) { - LogManager.Log(ex, $"Error loading publish info from {fileItem.Path}."); + LogManager.Log(ex, $"Error loading update package file from {fileItem.Path}."); await NotificationProvider.ShowError("An error occurred while trying to load the selected software update package. Please make sure the package is valid."); return; } - UpdateFromFileViewVM vm = new UpdateFromFileViewVM(); - vm.PublishInfo = packageFile; - - LogManager.Log($"TUP publish info:\n{packageFile.ToJson()}"); - - LogManager.Log("Displaying TUP update dialog..."); - - await NotificationProvider.ShowDialog(vm); - - if (vm.DialogResult) + if (ApplicationManager.Version <= packageFile.Version) { - await NavigationManager.NavigateTo(Common.Navigation.NavigationView.MachineUpdateView); - await NavigateTo(MachineUpdateView.UpdateProgressView); - - LogManager.Log("Starting machine update from package..."); - - try - { - _update_result = await MachineUpdateManager.UpdateFromTUP(fileItem.Path, MachineProvider.Machine.SetupFirmware, MachineProvider.Machine.SetupFpga); - LogManager.Log("Machine update from package completed."); - await NavigateTo(MachineUpdateView.UpdateCompletedView); - } - catch (Exception ex) - { - LogManager.Log(ex, "Machine update from package failed."); - FailedError = ex.FlattenMessage(); - await NavigateTo(MachineUpdateView.UpdateFailedFromPackageView); - } - } - } - - private async void HandleFirmwareUpgradeLoaded(List<ExplorerFileItem> fileItems) - { - var fileItem = fileItems.FirstOrDefault(); - - if (fileItem == null) return; - - LogManager.Log("TFP file loaded from storage..."); - - VersionPackageDescriptor packageInfo; - FirmwareUpgradeFromFileViewVM vm = new FirmwareUpgradeFromFileViewVM(); - - try - { - using (FileStream st = File.OpenRead(fileItem.Path)) - { - packageInfo = await MachineProvider.MachineOperator.GetFirmwarePackageInfo(st); - } - - packageInfo.Validate(); - - vm.Version = packageInfo.GetMcuVersion().ToString(); - } - catch (Exception ex) - { - LogManager.Log(ex, $"Error loading package info from {fileItem.Path}."); - await NotificationProvider.ShowError($"An error occurred while trying to load the selected firmware upgrade package.\n{ex.FlattenMessage()}"); + await NotificationProvider.ShowError($"The selected update package (v{packageFile.Version.ToString()}) contains an older software version."); return; } - - LogManager.Log($"TFP publish info:\n{packageInfo.ToJsonString()}"); - - LogManager.Log("Displaying TFP update dialog..."); + UpdateFromFileViewVM vm = new UpdateFromFileViewVM(); + vm.Version = packageFile.Version.ToString(); await NotificationProvider.ShowDialog(vm); if (vm.DialogResult) { await NavigationManager.NavigateTo(Common.Navigation.NavigationView.MachineUpdateView); - await NavigateTo(MachineUpdateView.UpdateProgressView); - - LogManager.Log("Starting firmware upgrade from package..."); - - try - { - await MachineUpdateManager.UpdateFromTFP(fileItem.Path); - LogManager.Log("Firmware upgrade from package completed."); - _update_result = new MachineUpdateResult() - { - RequiresBinariesUpdate = false, - }; - await NavigateTo(MachineUpdateView.UpdateCompletedView); - } - catch (Exception ex) - { - LogManager.Log(ex, "Firmware upgrade from package failed."); - FailedError = ex.FlattenMessage(); - await NavigateTo(MachineUpdateView.UpdateFailedFromPackageView); - } - } - } - - #endregion - - #region Auto Check For Update - - private void MachineUpdateManager_UpdateAvailable(object sender, CheckForUpdateResponse e) - { - if (!IsVisible && _updateNotificationItem == null) - { - 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 += (_, __) => - { - if (MachineProvider.MachineOperator.IsPrinting) - { - NotificationProvider.ShowInfo("Cannot perform a machine update while the machine is dyeing."); - return; - } - - _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 - - #region Updater Failed - - private void ApplicationManager_UpdaterFailed(object sender, EventArgs e) - { - InvokeUI(async () => - { - try - { - await NavigationManager.NavigateTo(NavigationView.MachineUpdateView); - await NavigateTo(MachineUpdateView.UpdateProgressView); - await MachineUpdateManager.RestoreLastDatabaseBackup(); - await Task.Delay(5000); - ApplicationManager.Restart(); - } - catch (Exception ex) - { - await NotificationProvider.ShowError($"Could not restore the application to its previous state.\n{ex.FlattenMessage()}"); - ApplicationManager.Restart(); - } - }); - } - - #endregion - - #region External Bridge Handler - - [ExternalBridgeRequestHandlerMethod(typeof(StartRemoteApplicationUpgradeRequest), RequestHandlerLoggingMode.LogRequestName)] - public async Task OnStartRemoteApplicationUpgradeRequest(StartRemoteApplicationUpgradeRequest request, String token, ExternalBridgeReceiver receiver) - { - await receiver.SendGenericResponse(new StartRemoteApplicationUpgradeResponse(), token); - - bool stopReporting = false; - - try - { - ThreadFactory.StartNew(async () => - { - while (!stopReporting) - { - if (MachineUpdateManager.Status != null) - { - try - { - await receiver.SendGenericResponse(new StartRemoteApplicationUpgradeResponse() - { - Progress = new TangoProgress<double>() - { - Message = MachineUpdateManager.Status.Message, - IsIndeterminate = MachineUpdateManager.Status.IsIntermediate, - Maximum = MachineUpdateManager.Status.Total, - Value = MachineUpdateManager.Status.Progress - }, - }, token, new TransportResponseConfig() { Priority = QueuePriority.Low }); - } - catch (Exception ex) - { - LogManager.Log(ex, "Error sending remote upgrade progress."); - } - } - - Thread.Sleep(500); - } - }); - - InvokeUI(() => - { - NavigationManager.NavigateTo(Common.Navigation.NavigationView.MachineUpdateView); - NavigateTo(MachineUpdateView.UpdateProgressView); - }); + await NavigateTo(MachineUpdateView.UpdateFromPackageView); LogManager.Log("Starting machine update from package..."); try { - _update_result = await MachineUpdateManager.UpdateFromTUP(request.RemoteTupFilePath, request.SetupFirmware, request.SetupFPGA); + _update_result = await MachineUpdateManager.UpdateFromTUP(fileItem.Path); LogManager.Log("Machine update from package completed."); - stopReporting = true; - - InvokeUI(() => - { - NavigateTo(MachineUpdateView.UpdateCompletedView); - }); + await NavigateTo(MachineUpdateView.UpdateCompletedView); } catch (Exception ex) { LogManager.Log(ex, "Machine update from package failed."); - FailedError = ex.FlattenMessage(); - - InvokeUI(() => - { - NavigateTo(MachineUpdateView.UpdateFailedFromPackageView); - }); - - throw ex; - } - - await receiver.SendGenericResponse(new StartRemoteApplicationUpgradeResponse() - { - Progress = new TangoProgress<double>("Completed", false, 100, 100), - }, token, new TransportResponseConfig() - { - Completed = true - }); - - try - { - File.Delete(request.RemoteTupFilePath); - } - catch { } - - await Task.Delay(2000); - - CompleteUpdate(); - } - catch (Exception ex) - { - stopReporting = true; - await receiver.SendErrorResponse(ex, token); - } - finally - { - stopReporting = true; - - try - { - File.Delete(request.RemoteTupFilePath); - } - catch { } - } - } - - [ExternalBridgeRequestHandlerMethod(typeof(StartRemoteFirmwareUpgradeRequest), RequestHandlerLoggingMode.LogRequestName)] - public async Task OnStartRemoteFirmwareUpgradeRequest(StartRemoteFirmwareUpgradeRequest request, String token, ExternalBridgeReceiver receiver) - { - await receiver.SendGenericResponse(new StartRemoteFirmwareUpgradeResponse(), token); - - bool stopReporting = false; - - try - { - ThreadFactory.StartNew(async () => - { - while (!stopReporting) - { - if (MachineUpdateManager.Status != null) - { - try - { - await receiver.SendGenericResponse(new StartRemoteFirmwareUpgradeResponse() - { - Progress = new TangoProgress<double>() - { - Message = MachineUpdateManager.Status.Message, - IsIndeterminate = MachineUpdateManager.Status.IsIntermediate, - Maximum = MachineUpdateManager.Status.Total, - Value = MachineUpdateManager.Status.Progress - } - }, token, new TransportResponseConfig() { Priority = QueuePriority.Low }); - } - catch (Exception ex) - { - LogManager.Log(ex, "Error sending remote upgrade progress."); - } - } - - Thread.Sleep(500); - } - }); - - InvokeUI(() => - { - NavigationManager.NavigateTo(Common.Navigation.NavigationView.MachineUpdateView); - NavigateTo(MachineUpdateView.UpdateProgressView); - }); - - LogManager.Log("Starting firmware upgrade from package..."); - - try - { - await MachineUpdateManager.UpdateFromTFP(request.RemoteTfpFilePath); - stopReporting = true; - LogManager.Log("Firmware upgrade from package completed."); - _update_result = new MachineUpdateResult() - { - RequiresBinariesUpdate = false, - }; - - InvokeUI(() => - { - NavigateTo(MachineUpdateView.UpdateCompletedView); - }); - } - catch (Exception ex) - { - stopReporting = true; - - LogManager.Log(ex, "Firmware upgrade from package failed."); - FailedError = ex.FlattenMessage(); - - InvokeUI(() => - { - NavigateTo(MachineUpdateView.UpdateFailedFromPackageView); - }); - - throw ex; - } - - await receiver.SendGenericResponse(new StartRemoteFirmwareUpgradeResponse() - { - Progress = new TangoProgress<double>("Completed", false, 100, 100), - }, token, new TransportResponseConfig() - { - Completed = true - }); - - try - { - File.Delete(request.RemoteTfpFilePath); - } - catch { } - - await Task.Delay(2000); - - CompleteUpdate(); - } - catch (Exception ex) - { - stopReporting = true; - await receiver.SendErrorResponse(ex, token); - } - finally - { - stopReporting = true; - - try - { - File.Delete(request.RemoteTfpFilePath); + await NavigateTo(MachineUpdateView.UpdateFailedFromPackageView); } - catch { } } } - public void OnReceiverDisconnected(ExternalBridgeReceiver receiver) - { - //Do Nothing. - } - #endregion } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs index 05fb610c8..01a47539e 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs @@ -4,9 +4,6 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Threading; -using Tango.BL; -using Tango.BL.Builders; -using Tango.BL.Entities; using Tango.Core.DI; using Tango.Integration.ExternalBridge; using Tango.Integration.Operation; @@ -20,8 +17,6 @@ using Tango.PPC.Common.Notifications; using Tango.PPC.Common.WatchDog; using Tango.PPC.UI.Dialogs; using Tango.SharedUI; -using System.Data.Entity; -using Tango.PPC.UI.AppBarItems; namespace Tango.PPC.UI.ViewModels { @@ -32,10 +27,6 @@ namespace Tango.PPC.UI.ViewModels public class MainViewVM : PPCViewModel { private DispatcherTimer _date_timer; - private bool _isPowerUpDialogShown; - private bool _isThreadLoadingShown; - private PowerUpAppBarItem _powerUpAppBar; - private bool _started; private DateTime _currentDateTime; /// <summary> @@ -67,53 +58,8 @@ namespace Tango.PPC.UI.ViewModels { base.OnApplicationReady(); MachineProvider.MachineOperator.CartridgeValidationRequestReceived += MachineOperator_CartridgeValidationRequestReceived; - MachineProvider.MachineOperator.FirmwareStarted += MachineOperator_FirmwareStarted; - MachineProvider.MachineOperator.ThreadLoadingStatusChanged += MachineOperator_ThreadLoadingStatusChanged; - MachineProvider.MachineOperator.ThreadLoadingConfirmationRequired += MachineOperator_ThreadLoadingConfirmationRequired; - - MachineProvider.MachineOperator.PowerUpStarted += MachineOperator_PowerUpStarted; - MachineProvider.MachineOperator.PowerUpProgress += MachineOperator_PowerUpProgress; - MachineProvider.MachineOperator.PowerUpEnded += MachineOperator_PowerUpEnded; - } - - #region Power Up - - private void MachineOperator_PowerUpEnded(object sender, EventArgs e) - { - _started = false; - _powerUpAppBar?.Close(); - _powerUpAppBar = null; - } - - private void MachineOperator_PowerUpProgress(object sender, PMR.Power.StartPowerUpResponse status) - { - if (_powerUpAppBar != null) - { - _powerUpAppBar.Status = status; - } - } - - private void MachineOperator_PowerUpStarted(object sender, PMR.Power.StartPowerUpResponse e) - { - _started = true; - - InvokeUI(() => - { - if (_powerUpAppBar != null) - { - _powerUpAppBar.Close(); - } - - if (_started) - { - _powerUpAppBar = NotificationProvider.PushAppBarItem<PowerUpAppBarItem>(); - _powerUpAppBar.Priority = AppBarPriority.Low; - } - }); } - #endregion - #region Event Handlers /// <summary> @@ -146,106 +92,6 @@ namespace Tango.PPC.UI.ViewModels }); } - private async void MachineOperator_FirmwareStarted(object sender, EventArgs e) - { - if (_isPowerUpDialogShown) - { - LogManager.Log("Power up detected but power up dialog is already shown. Skipping..."); - return; - } - - LogManager.Log("Power up detected, showing power up screen..."); - - if (!Settings.DisplayPowerUpScreen) - { - LogManager.Log("Power up screen disabled. skipping..."); - return; - } - - PowerUpViewVM vm; - - try - { - LogManager.Log("Loading site rmls..."); - - List<Rml> rmls = new List<Rml>(); - - using (ObservablesContext db = ObservablesContext.CreateDefault()) - { - rmls = await new RmlsCollectionBuilder(db).SetAll().ForHeadType(MachineProvider.Machine.MachineHeadType).ForSite(MachineProvider.Machine.SiteGuid).BuildListAsync(); - } - - var selectedRml = rmls.SingleOrDefault(x => x.Guid == Settings.LoadedRmlGuid); - - vm = new PowerUpViewVM(); - vm.Rmls = rmls; - vm.SelectedRml = selectedRml != null ? selectedRml : rmls.FirstOrDefault(); - vm.IsSelectedRml = selectedRml != null; - } - catch (Exception ex) - { - LogManager.Log(ex, "Error initializing power up screen."); - return; - } - - InvokeUI(async () => - { - _isPowerUpDialogShown = true; - await NotificationProvider.ShowDialog<PowerUpViewVM>(vm); - _isPowerUpDialogShown = false; - - await Task.Factory.StartNew(() => - { - LogManager.Log("Power up screen closed."); - - try - { - using (ObservablesContext db = ObservablesContext.CreateDefault()) - { - List<ProcessParametersTable> processTables = new List<ProcessParametersTable>(); - - if (vm.IsSelectedRml) - { - LogManager.Log($"Selected rml '{vm.SelectedRml.Name}'..."); - processTables = new RmlBuilder(db).Set(vm.SelectedRml.Guid).WithActiveParametersGroup().Build().GetActiveProcessGroup().ProcessParametersTables.ToList(); - } - else - { - LogManager.Log("Selected minimal temperature..."); - var rmlsToAvg = new RmlsCollectionBuilder(db).SetAll().ForHeadType(MachineProvider.Machine.MachineHeadType).ForSite(MachineProvider.Machine.SiteGuid).WithActiveParametersGroup().Build(); - processTables = rmlsToAvg.Select(x => x.GetActiveProcessGroup()).SelectMany(x => x.ProcessParametersTables).ToList(); - } - - var processToLoad = processTables.OrderBy(x => x.GetAverageTemperature()).First(); - - LogManager.Log($"Selected process parameters:\nRML: {processToLoad.ProcessParametersTablesGroup.Rml.Name}\nGroup: {processToLoad.ProcessParametersTablesGroup.Name}\nProcess Table: {processToLoad.Name}"); - LogManager.Log("Uploading process parameters..."); - var r = MachineProvider.MachineOperator.UploadProcessParameters(processToLoad).Result; - - Settings.LoadedRmlGuid = vm.IsSelectedRml ? vm.SelectedRml.Guid : null; - Settings.Save(); - } - } - catch (Exception ex) - { - LogManager.Log(ex, "Error occurred while trying to get and upload the proper process parameters after power screen closed."); - } - }); - }); - } - - private void MachineOperator_ThreadLoadingStatusChanged(object sender, PMR.ThreadLoading.StartThreadLoadingResponse e) - { - //if (e.State == PMR.ThreadLoading.ThreadLoadingState.Preparing) - //{ - // DisplayThreadLoading(); - //} - } - - private void MachineOperator_ThreadLoadingConfirmationRequired(object sender, ThreadLoadingConfirmationRequiredEventArgs e) - { -// DisplayThreadLoading(e); - } #endregion } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/PowerOffViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/PowerOffViewVM.cs deleted file mode 100644 index e3ab7d111..000000000 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/PowerOffViewVM.cs +++ /dev/null @@ -1,134 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.Core.Commands; -using Tango.Integration.Operation; -using Tango.PMR.Power; -using Tango.PPC.Common; -using Tango.PPC.UI.AppBarItems; -using Tango.PPC.UI.Views; - -namespace Tango.PPC.UI.ViewModels -{ - public class PowerOffViewVM : PPCViewModel - { - private PowerDownHandler _handler; - private PowerOffAppBarItem _appBarItem; - private int _abortTries; - - private StartPowerDownResponse _status; - public StartPowerDownResponse Status - { - get { return _status; } - set { _status = value; RaisePropertyChangedAuto(); } - } - - public RelayCommand AbortCommand { get; set; } - - public PowerOffViewVM() - { - _appBarItem = new PowerOffAppBarItem(); - _appBarItem.Pressed += (x, e) => - { - NavigationManager.NavigateTo<InternalModule>(nameof(PowerOffView)); - }; - AbortCommand = new RelayCommand(AbortPowerOff); - } - - public override void OnApplicationStarted() - { - - } - - public override void OnApplicationReady() - { - base.OnApplicationReady(); - MachineProvider.MachineOperator.PowerDownStarted += MachineOperator_PowerDownStarted; - } - - private void MachineOperator_PowerDownStarted(object sender, PowerDownStartedEventArgs e) - { - _abortTries = 0; - _handler = e.Handler; - - _handler.StatusChanged += OnStatusChanged; - _handler.Failed += OnFailed; - _handler.Completed += OnCompleted; - - InvokeUI(async () => - { - await NavigationManager.NavigateTo<InternalModule>(nameof(PowerOffView)); - NotificationProvider.PushAppBarItem(_appBarItem); - }); - } - - private void OnStatusChanged(object sender, PowerDownStatusChangedEventArgs e) - { - Status = e.Status; - _appBarItem.Status = Status; - } - - private void OnCompleted(object sender, EventArgs e) - { - InvokeUI(async () => - { - if (IsVisible) - { - await NavigationManager.NavigateBack(); - } - - NotificationProvider.PopAppBarItem(_appBarItem); - }); - } - - private void OnFailed(object sender, Exception ex) - { - InvokeUI(async () => - { - await NotificationProvider.ShowError($"An error occurred while powering off the machine.\n{ex.FlattenMessage()}"); - - if (IsVisible) - { - await NavigationManager.NavigateBack(); - } - - NotificationProvider.PopAppBarItem(_appBarItem); - }); - } - - private async void AbortPowerOff() - { - try - { - NotificationProvider.SetGlobalBusyMessage("Aborting machine power off..."); - await _handler.Abort(); - await NavigationManager.NavigateBack(); - NotificationProvider.PopAppBarItem(_appBarItem); - } - catch (Exception ex) - { - _abortTries++; - LogManager.Log(ex, "Power down abort error."); - NotificationProvider.ReleaseGlobalBusyMessage(); - await NotificationProvider.ShowError($"An error occurred while trying to abort the power off sequence.\n{ex.FlattenMessage()}"); - - if (_abortTries > 2) - { - if (IsVisible) - { - await NavigationManager.NavigateBack(); - } - - NotificationProvider.PopAppBarItem(_appBarItem); - } - } - finally - { - NotificationProvider.ReleaseGlobalBusyMessage(); - } - } - } -} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/RestartingViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/RestartingViewVM.cs deleted file mode 100644 index 46111031b..000000000 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/RestartingViewVM.cs +++ /dev/null @@ -1,27 +0,0 @@ -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(); - } - } -} |
