blob: 86c65a68956709f829abc5cae00d3bfbb1751f93 (
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Tango.BL.Enumerations;
using Tango.Core;
using Tango.Core.DI;
using Tango.FSE.BL;
using Tango.FSE.Common.Authentication;
using Tango.FSE.Common.Connection;
using Tango.FSE.Common.Diagnostics;
using Tango.FSE.Common.Notifications;
using Tango.PMR.Diagnostics;
namespace Tango.FSE.Diagnostics.Project
{
public abstract class DiagnosticsWidget : ExtendedObject, IDisposable
{
[JsonIgnore]
[TangoInject(TangoInjectMode.WhenAvailable)]
protected IAuthenticationProvider AuthenticationProvider { get; set; }
[JsonIgnore]
[TangoInject(TangoInjectMode.WhenAvailable)]
protected IMachineProvider MachineProvider { get; set; }
[JsonIgnore]
[TangoInject(TangoInjectMode.WhenAvailable)]
protected INotificationProvider NotificationProvider { get; set; }
private FSEServicesContainer _services;
[JsonIgnore]
[TangoInject(TangoInjectMode.WhenAvailable)]
public FSEServicesContainer Services
{
get { return _services; }
set { _services = value; OnServicesAvailable(); }
}
public String ID { get; set; }
private int _column;
public int Column
{
get { return _column; }
set { _column = value; RaisePropertyChangedAuto(); }
}
private int _row;
public int Row
{
get { return _row; }
set { _row = value; RaisePropertyChangedAuto(); }
}
private int _columnSpan;
public int ColumnSpan
{
get { return _columnSpan; }
set { _columnSpan = value; RaisePropertyChangedAuto(); }
}
private int _rowSpan;
public int RowSpan
{
get { return _rowSpan; }
set { _rowSpan = value; RaisePropertyChangedAuto(); }
}
private double _width;
public double Width
{
get { return _width; }
set { _width = value; RaisePropertyChangedAuto(); }
}
private double _height;
public double Height
{
get { return _height; }
set { _height = value; RaisePropertyChangedAuto(); }
}
private bool _displayComponentName;
public bool DisplayComponentName
{
get { return _displayComponentName; }
set { _displayComponentName = value; RaisePropertyChangedAuto(); }
}
private Dock _componentNameAlignment;
public Dock ComponentNameAlignment
{
get { return _componentNameAlignment; }
set { _componentNameAlignment = value; RaisePropertyChangedAuto(); }
}
private String _customComponentName;
public String CustomComponentName
{
get { return _customComponentName; }
set { _customComponentName = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(DisplayName)); }
}
private bool _isVisible;
[JsonIgnore]
public bool IsVisible
{
get { return _isVisible; }
set
{
if (_isVisible != value)
{
_isVisible = value;
OnVisibleChanged(_isVisible);
RaisePropertyChangedAuto();
}
}
}
private bool _isSelected;
[JsonIgnore]
public bool IsSelected
{
get { return _isSelected; }
set { _isSelected = value; RaisePropertyChangedAuto(); }
}
[JsonIgnore]
public abstract String DisplayName
{
get;
}
[JsonIgnore]
public bool SupportsComponentSelection
{
get
{
return this is ISupportsComponentSelection;
}
}
[JsonIgnore]
public bool IsCurrentUserEditor
{
get
{
return AuthenticationProvider.CurrentUser.HasPermission(Permissions.FSE_EditDiagnosticsProject);
}
}
[JsonIgnore]
public virtual bool HasSettings
{
get
{
return (this is DiagnosticsConfigurableWidget) || (SupportsComponentSelection && (this as ISupportsComponentSelection).EnableComponentSelection);
}
}
private bool _editMode;
[JsonIgnore]
public bool EditMode
{
get { return _editMode; }
set { _editMode = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(HasSettings)); }
}
[JsonIgnore]
public bool IsDisposed { get; protected set; }
public DiagnosticsWidget()
{
ID = Guid.NewGuid().ToString();
Width = 100;
Height = 100;
ComponentNameAlignment = Dock.Top;
TangoIOC.Default.Inject(this);
}
protected virtual void OnServicesAvailable()
{
}
public virtual void OnDiagnosticsData(DiagnosticsPackage package)
{
//Do Nothing.
}
protected virtual void OnVisibleChanged(bool isVisible)
{
//Called when the widget visibility changed.
}
public abstract FrameworkElement GetView();
public virtual Task Init()
{
return Task.FromResult(true);
}
protected async void InitAsync()
{
await Init();
}
public DiagnosticsWidget Clone()
{
var json = JsonConvert.SerializeObject(this, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All });
var cloned = JsonConvert.DeserializeObject(json, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All }) as DiagnosticsWidget;
cloned.ID = Guid.NewGuid().ToString();
return cloned;
}
public void RaiseHasSettings()
{
RaisePropertyChanged(nameof(HasSettings));
}
public virtual void Dispose()
{
IsDisposed = true;
}
}
}
|