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. --- .../Tango.PPC.UI/Dialogs/ThreadLoadingViewVM.cs | 155 +++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ThreadLoadingViewVM.cs (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ThreadLoadingViewVM.cs') diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ThreadLoadingViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ThreadLoadingViewVM.cs new file mode 100644 index 000000000..5e5370416 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ThreadLoadingViewVM.cs @@ -0,0 +1,155 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using Tango.Core.Commands; +using Tango.Integration.Operation; +using Tango.PMR.ThreadLoading; +using Tango.PPC.Common.Connection; +using Tango.SharedUI; + +namespace Tango.PPC.UI.Dialogs +{ + public class ThreadLoadingViewVM : DialogViewVM + { + public class ThreadLoadingResult + { + public bool IsCompleted { get; set; } + public Exception FailedException { get; set; } + } + + private ThreadLoadingConfirmationRequiredEventArgs _confirmationArgs; + + public ThreadLoadingResult Result { get; set; } + + public IMachineProvider MachineProvider { get; set; } + + private StartThreadLoadingResponse _status; + public StartThreadLoadingResponse Status + { + get { return _status; } + set { _status = value; RaisePropertyChangedAuto(); } + } + + private bool _isFinalizing; + public bool IsFinalizing + { + get { return _isFinalizing; } + set { _isFinalizing = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } + } + + public List Rmls { get; set; } + + private Rml _selectedRml; + public Rml SelectedRml + { + get { return _selectedRml; } + set { _selectedRml = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } + } + + public RelayCommand ContinueCommand { get; set; } + + public ThreadLoadingViewVM(IMachineProvider machineProvider, ThreadLoadingConfirmationRequiredEventArgs confirmationArgs) + { + CanClose = true; + _confirmationArgs = confirmationArgs; + ContinueCommand = new RelayCommand(ContinueThreadLoading, () => !IsFinalizing && SelectedRml != null); + MachineProvider = machineProvider; + MachineProvider.MachineOperator.ThreadLoadingStatusChanged += MachineOperator_ThreadLoadingStatusChanged; + MachineProvider.MachineOperator.ThreadLoadingCompleted += MachineOperator_ThreadLoadingCompleted; + MachineProvider.MachineOperator.ThreadLoadingFailed += MachineOperator_ThreadLoadingFailed; + } + + private async void ContinueThreadLoading() + { + IsFinalizing = true; + + try + { + await Task.Factory.StartNew(() => { _confirmationArgs.Confirm(SelectedRml.GetActiveProcessGroup().ProcessParametersTables.FirstOrDefault()); }); + } + catch (Exception ex) + { + Result = new ThreadLoadingResult() + { + FailedException = ex, + }; + + IsFinalizing = false; + + if (IsVisible) + { + InvokeUI(() => + { + Accept(); + }); + } + } + } + + private void MachineOperator_ThreadLoadingCompleted(object sender, StartThreadLoadingResponse e) + { + Result = new ThreadLoadingResult() + { + IsCompleted = true + }; + + if (IsVisible) + { + InvokeUI(() => + { + Accept(); + }); + } + } + + private void MachineOperator_ThreadLoadingFailed(object sender, StartThreadLoadingResponse e) + { + Result = new ThreadLoadingResult() + { + FailedException = new Exception(e.ErrorReason), + }; + + if (IsVisible) + { + InvokeUI(() => + { + Accept(); + }); + } + } + + private void MachineOperator_ThreadLoadingStatusChanged(object sender, StartThreadLoadingResponse e) + { + Status = e; + + if(Status.State == ThreadLoadingState.Finalizing) + { + IsFinalizing = true; + } + } + + protected override void Cancel() + { + IsFinalizing = false; + ClearEvents(); + base.Cancel(); + } + + protected override void Accept() + { + IsFinalizing = false; + ClearEvents(); + base.Accept(); + } + + private void ClearEvents() + { + MachineProvider.MachineOperator.ThreadLoadingStatusChanged -= MachineOperator_ThreadLoadingStatusChanged; + MachineProvider.MachineOperator.ThreadLoadingCompleted -= MachineOperator_ThreadLoadingCompleted; + MachineProvider.MachineOperator.ThreadLoadingFailed -= MachineOperator_ThreadLoadingFailed; + } + } +} -- cgit v1.3.1