forked from silahian/VisualHFT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProviderVM.cs
147 lines (137 loc) · 4.27 KB
/
ProviderVM.cs
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
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VisualHFT.Model
{
public enum eSESSIONSTATUS
{
PRICE_CONNECTED_ORDER_DISCONNECTED,
PRICE_DSICONNECTED_ORDER_CONNECTED,
BOTH_CONNECTED,
BOTH_DISCONNECTED
};
public class ProviderVM : INotifyPropertyChanged
{
protected readonly System.Timers.Timer _timer;
protected string providerName;
protected int providerID;
protected eSESSIONSTATUS status;
protected DateTime? lastUpdated;
protected int _MILLISECONDS_HEART_BEAT = 5000;
public event PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
public ProviderVM()
{
_timer = new System.Timers.Timer();
_timer.Interval = 5000;
_timer.Elapsed += _timer_Elapsed;
_timer.Enabled = true;
_timer.Start();
}
private void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
RaisePropertyChanged("StatusImage");
RaisePropertyChanged("Tooltip");
}
public ProviderVM(ProviderVM p)
{
this.providerID = p.ProviderID;
this.providerName = p.ProviderName;
this.status = p.Status;
}
public string ProviderName
{
get
{
return providerName;
}
set
{
providerName = value;
RaisePropertyChanged("ProviderName");
}
}
public int ProviderID
{
get
{
return providerID;
}
set
{
providerID = value;
RaisePropertyChanged("ProviderID");
}
}
public eSESSIONSTATUS Status
{
get
{
return status;
}
set
{
status = value;
RaisePropertyChanged("Status");
RaisePropertyChanged("StatusImage");
RaisePropertyChanged("Tooltip");
}
}
public string StatusImage
{
get
{
if (lastUpdated.HasValue && DateTime.Now.Subtract(lastUpdated.Value).TotalMilliseconds > _MILLISECONDS_HEART_BEAT)
{
return "/Images/imgRedBall.png";
}
else if (status == eSESSIONSTATUS.BOTH_CONNECTED)
return "/Images/imgGreenBall.png";
else if (status == eSESSIONSTATUS.BOTH_DISCONNECTED)
return "/Images/imgRedBall.png";
else
return "/Images/imgYellowBall.png";
}
}
public string Tooltip
{
get
{
if (lastUpdated.HasValue && DateTime.Now.Subtract(lastUpdated.Value).TotalMilliseconds > _MILLISECONDS_HEART_BEAT)
{
return "Not receving heart-beat";
}
else if (status == eSESSIONSTATUS.BOTH_CONNECTED)
return "Connected";
else if (status == eSESSIONSTATUS.BOTH_DISCONNECTED)
return "Disconnected";
else if (status == eSESSIONSTATUS.PRICE_CONNECTED_ORDER_DISCONNECTED)
return "Price connected. Order disconnected";
else if (status == eSESSIONSTATUS.PRICE_DSICONNECTED_ORDER_CONNECTED)
return "Price disconnected. Order connected";
else
return "";
}
}
public DateTime? LastUpdated
{
get { return lastUpdated; }
set
{
lastUpdated = value;
RaisePropertyChanged("LastUpdated");
}
}
}
}