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
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using Tango.BL.Entities;
using Tango.BL.Enumerations;
using Tango.Core;
using Tango.Core.DI;
using Tango.Core.Helpers;
using Tango.FSE.Common;
using Tango.FSE.Common.Connection;
using Tango.Integration.Operation;
using Tango.PMR.MachineStatus;
namespace Tango.FSE.UI.Tiles.MidTankLevels
{
public class MidTankLevelsTile : DashboardTile
{
public class MidTankLevelModel : ExtendedObject
{
public double Max { get; set; }
private double _level;
public double Level
{
get { return _level; }
set { _level = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(IsLow)); RaisePropertyChanged(nameof(IsEmpty)); }
}
public bool IsLow
{
get { return Level <= MachineOperator.LOW_MIDTANK_LITERS; }
}
public bool IsEmpty
{
get { return Level <= MachineOperator.EMPTY_MIDTANK_LITERS; }
}
public IdsPack IDSPack { get; set; }
}
private List<MidTankLevelModel> _midTankLevels;
public List<MidTankLevelModel> MidTankLevels
{
get { return _midTankLevels; }
set { _midTankLevels = value; RaisePropertyChangedAuto(); }
}
public MidTankLevelsTile()
{
Name = "Mid Tank Levels";
Column = 4;
Row = 0;
ColumnSpan = 4;
RowSpan = 3;
AutoContainerStyle = false;
MidTankLevels = new List<MidTankLevelModel>()
{
new MidTankLevelModel()
{
Level = 0.5,
Max = MachineOperator.MAX_MIDTANK_LITERS,
IDSPack = new IdsPack()
{
LiquidType = new LiquidType()
{
Code = LiquidTypes.Cyan.ToInt32(),
Color = ColorHelper.ColorToInteger(Colors.Cyan),
Name = "Cyan",
ShortName = "C",
},
},
},
new MidTankLevelModel()
{
Level = 0.2,
Max = MachineOperator.MAX_MIDTANK_LITERS,
IDSPack = new IdsPack()
{
LiquidType = new LiquidType()
{
Code = LiquidTypes.Magenta.ToInt32(),
Color = ColorHelper.ColorToInteger(Colors.Magenta),
Name = "Magenta",
ShortName = "M",
},
},
},
new MidTankLevelModel()
{
Level = 0.9,
Max = MachineOperator.MAX_MIDTANK_LITERS,
IDSPack = new IdsPack()
{
LiquidType = new LiquidType()
{
Code = LiquidTypes.Yellow.ToInt32(),
Color = ColorHelper.ColorToInteger(Colors.Yellow),
Name = "Yellow",
ShortName = "Y",
},
},
},
new MidTankLevelModel()
{
Level = 0.1,
Max = MachineOperator.MAX_MIDTANK_LITERS,
IDSPack = new IdsPack()
{
LiquidType = new LiquidType()
{
Code = LiquidTypes.Black.ToInt32(),
Color = ColorHelper.ColorToInteger(Colors.Black),
Name = "Black",
ShortName = "k",
},
},
}
};
}
public override FrameworkElement GetView()
{
return new MidTankLevelsTileView();
}
public override void OnApplicationStarted()
{
base.OnApplicationStarted();
MachineProvider.MachineOperator.MachineStatusChanged += MachineOperator_MachineStatusChanged;
MachineProvider.MachineConnected += MachineProvider_MachineConnected;
}
private void MachineProvider_MachineConnected(object sender, MachineConnectedEventArgs e)
{
MidTankLevels = MachineProvider.Machine.Configuration.NoneEmptyIdsPacks.Where(x => x.MidTankType.HasLevelMeasure).OrderBy(x => x.PackIndex).Select(x => new MidTankLevelModel()
{
Max = x.MidTankType.LiterCapacity,
IDSPack = x,
}).ToList();
}
private void MachineOperator_MachineStatusChanged(object sender, MachineStatus status)
{
UpdateMidTankLevels(status);
}
private void UpdateMidTankLevels(MachineStatus status)
{
if (IsVisible)
{
try
{
foreach (var item in status.IDSPacksLevels)
{
var model = MidTankLevels.SingleOrDefault(x => x.IDSPack.PackIndex == item.Index);
if (model != null)
{
model.Level = item.MidTankLevel;
}
}
}
catch
{
Debug.WriteLine("Error on update mid tank levels. (probably because of machine status arrived before machine connected event..)");
}
}
}
}
}
|