blob: ede913c47010f3dda78cca511591e0e06f046c4b (
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using Tango.BL.Entities;
using Tango.Core.Commands;
using Tango.Core.DI;
using Tango.Integration.Operation;
using Tango.PMR.Printing;
using Tango.PPC.Common;
using Tango.PPC.Common.Connection;
using Tango.PPC.Common.Notifications;
using Tango.Settings;
using Tango.SharedUI;
namespace Tango.PPC.Maintenance.Dialogs
{
public class HeadCleaningViewVM : DialogViewVM
{
private HeadCleaningHandler _handler;
[TangoInject]
private IMachineProvider MachineProvider { get; set; }
[TangoInject]
private INotificationProvider NotificationProvider { get; set; }
private bool _isStarted;
public bool IsStarted
{
get { return _isStarted; }
set { _isStarted = value; RaisePropertyChangedAuto(); }
}
private bool _isCompleted;
public bool IsCompleted
{
get { return _isCompleted; }
set { _isCompleted = value; RaisePropertyChangedAuto(); }
}
private bool _isAborting;
public bool IsAborting
{
get { return _isAborting; }
set { _isAborting = value; RaisePropertyChangedAuto(); }
}
private bool _isFailed;
public bool IsFailed
{
get { return _isFailed; }
set { _isFailed = value; RaisePropertyChangedAuto(); }
}
private StartHeadCleaningResponse _status;
public StartHeadCleaningResponse Status
{
get { return _status; }
set { _status = value; RaisePropertyChangedAuto(); }
}
public bool IsLongCleaning { get; set; }
public RelayCommand StartCommand { get; set; }
public RelayCommand AbortCommand { get; set; }
public HeadCleaningViewVM()
{
CanClose = true;
TangoIOC.Default.Inject(this);
StartCommand = new RelayCommand(Start);
AbortCommand = new RelayCommand(Abort);
}
private async void Start()
{
try
{
CanClose = false;
IsStarted = true;
_handler = await MachineProvider.MachineOperator.PerformHeadCleaning(IsLongCleaning);
_handler.Completed += _handler_Completed;
_handler.Failed += _handler_Failed;
_handler.StatusChanged += _handler_StatusChanged;
}
catch (Exception ex)
{
_handler_Failed(this, ex);
}
}
private void _handler_StatusChanged(object sender, HeadCleaningStatusChangedEventArgs e)
{
Status = e.Status;
}
private void _handler_Failed(object sender, Exception e)
{
IsStarted = false;
IsFailed = true;
InvokeUI(() =>
{
CanClose = true;
Cancel();
NotificationProvider.ShowError($"Error occurred while trying to perform the head cleaning.\n{e.FlattenMessage()}");
});
}
private void _handler_Completed(object sender, EventArgs e)
{
IsStarted = false;
IsCompleted = true;
InvokeUI(() =>
{
Accept();
NotificationProvider.ShowSuccess("Head cleaning completed successfully.");
});
}
protected override void Cancel()
{
if (CanClose)
{
base.Cancel();
}
}
private async void Abort()
{
IsAborting = true;
try
{
await _handler.Abort();
CanClose = true;
Cancel();
await NotificationProvider.ShowInfo("Head cleaning aborted.");
}
catch (Exception ex)
{
if (!IsCompleted)
{
CanClose = true;
IsAborting = false;
await NotificationProvider.ShowError($"Error occurred while trying to abort the head cleaning.\n{ex.FlattenMessage()}");
}
}
}
}
}
|