From 1208554e06da8aec1b074932df488769572ffcfb Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 19 Dec 2019 18:01:01 +0200 Subject: Implemented auto thread loading. Implemented advanced settings for technician. Implemented thread loading on emulator. Removed PowerUpSelectedRML from settings. Now using LoadedRml settings for ThreadLoading and PowerUp. --- .../PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs | 76 +++++++++++++++++++++- 1 file changed, 74 insertions(+), 2 deletions(-) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels') 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 8a4d20b76..eeb11ffab 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs @@ -63,6 +63,7 @@ namespace Tango.PPC.UI.ViewModels base.OnApplicationReady(); MachineProvider.MachineOperator.CartridgeValidationRequestReceived += MachineOperator_CartridgeValidationRequestReceived; MachineProvider.MachineOperator.PowerUpStarted += MachineOperator_PowerUpStarted; + MachineProvider.MachineOperator.ThreadLoadingConfirmationRequired += MachineOperator_ThreadLoadingConfirmationRequired; } #region Event Handlers @@ -120,7 +121,7 @@ namespace Tango.PPC.UI.ViewModels rmls = await new RmlsCollectionBuilder(db).SetAll().WithSite(MachineProvider.Machine.SiteGuid).BuildListAsync(); } - var selectedRml = rmls.SingleOrDefault(x => x.Guid == Settings.LastPowerUpSelectedRmlGuid); + var selectedRml = rmls.SingleOrDefault(x => x.Guid == Settings.LoadedRmlGuid); vm = new PowerUpViewVM(); vm.Rmls = rmls; @@ -165,7 +166,7 @@ namespace Tango.PPC.UI.ViewModels LogManager.Log("Uploading process parameters..."); var r = MachineProvider.MachineOperator.UploadProcessParameters(processToLoad).Result; - Settings.LastPowerUpSelectedRmlGuid = vm.IsSelectedRml ? vm.SelectedRml.Guid : null; + Settings.LoadedRmlGuid = vm.IsSelectedRml ? vm.SelectedRml.Guid : null; Settings.Save(); } } @@ -177,6 +178,77 @@ namespace Tango.PPC.UI.ViewModels }); } + private async void MachineOperator_ThreadLoadingConfirmationRequired(object sender, ThreadLoadingConfirmationRequiredEventArgs e) + { + LogManager.Log("Thread loading confirmation detected, showing thread loading screen..."); + + if (!Settings.DisplayAutomaticThreadLoadingScreen) + { + LogManager.Log("Thread loading screen disabled. skipping..."); + return; + } + + ThreadLoadingViewVM vm; + + try + { + LogManager.Log("Loading site rmls..."); + + List rmls = new List(); + + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + rmls = await new RmlsCollectionBuilder(db).SetAll().WithSite(MachineProvider.Machine.SiteGuid).WithActiveParametersGroup().BuildListAsync(); + } + + var selectedRml = rmls.SingleOrDefault(x => x.Guid == Settings.LoadedRmlGuid); + + vm = new ThreadLoadingViewVM(MachineProvider, e); + vm.Rmls = rmls; + vm.SelectedRml = selectedRml != null ? selectedRml : rmls.FirstOrDefault(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error initializing thread loading screen."); + return; + } + + InvokeUI(async () => + { + await NotificationProvider.ShowDialog(vm); + + LogManager.Log("Thread loading screen closed."); + + if (!vm.DialogResult) + { + LogManager.Log("Thread loading screen aborted by user. No operation was performed."); + return; + } + + try + { + if (vm.Result.IsCompleted) + { + await NotificationProvider.ShowSuccess("Thread loading completed successfully."); + } + else + { + await NotificationProvider.ShowError($"Thread loading failed due to the following reason:\n{vm.Result.FailedException.FlattenException()}"); + } + + if (vm.SelectedRml != null) + { + Settings.LoadedRmlGuid = vm.SelectedRml.Guid; + Settings.Save(); + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error occurred after thread loading screen closed."); + } + }); + } + #endregion } } -- cgit v1.3.1