aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ThreadLoadingViewVM.cs
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2019-12-19 18:01:01 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2019-12-19 18:01:01 +0200
commit1208554e06da8aec1b074932df488769572ffcfb (patch)
tree9858ededeb8badda5fc8b3052ef9745e419f35fd /Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ThreadLoadingViewVM.cs
parent690604e6167bfa4fea0ab02f8b24a68142e8b546 (diff)
downloadTango-1208554e06da8aec1b074932df488769572ffcfb.tar.gz
Tango-1208554e06da8aec1b074932df488769572ffcfb.zip
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.
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ThreadLoadingViewVM.cs')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/ThreadLoadingViewVM.cs155
1 files changed, 155 insertions, 0 deletions
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<Rml> 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;
+ }
+ }
+}