blob: 95fb77e48a493616ff43a5ee59bb51f09f760c80 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
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(); }
}
private bool _isPreparing;
public bool IsPreparing
{
get { return _isPreparing; }
set { _isPreparing = 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)
{
CanClose = false;
IsPreparing = true;
ContinueCommand = new RelayCommand(ContinueThreadLoading, () => !IsFinalizing && SelectedRml != null);
MachineProvider = machineProvider;
MachineProvider.MachineOperator.ThreadLoadingStatusChanged += MachineOperator_ThreadLoadingStatusChanged;
MachineProvider.MachineOperator.ThreadLoadingCompleted += MachineOperator_ThreadLoadingCompleted;
MachineProvider.MachineOperator.ThreadLoadingFailed += MachineOperator_ThreadLoadingFailed;
MachineProvider.MachineOperator.ThreadLoadingConfirmationRequired += MachineOperator_ThreadLoadingConfirmationRequired;
}
public ThreadLoadingViewVM(IMachineProvider machineProvider, ThreadLoadingConfirmationRequiredEventArgs confirmationArgs) : this(machineProvider)
{
_confirmationArgs = confirmationArgs;
IsPreparing = false;
}
private void MachineOperator_ThreadLoadingConfirmationRequired(object sender, ThreadLoadingConfirmationRequiredEventArgs e)
{
_confirmationArgs = e;
IsPreparing = false;
}
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;
MachineProvider.MachineOperator.ThreadLoadingConfirmationRequired -= MachineOperator_ThreadLoadingConfirmationRequired;
}
}
}
|