Mercurial > silverbladetech
comparison Messaging/Server/EndPoints/MessageEndPoint.cs @ 29:9919ee227c93
msmq added
author | adminsh@apollo |
---|---|
date | Wed, 21 Mar 2012 22:09:18 +0000 |
parents | |
children | 7d9de5746f18 |
comparison
equal
deleted
inserted
replaced
28:4c0dea4760c5 | 29:9919ee227c93 |
---|---|
1 using System; | |
2 using System.Threading.Tasks; | |
3 using Common.Messages; | |
4 using GalaSoft.MvvmLight; | |
5 using GalaSoft.MvvmLight.Messaging; | |
6 using Server.Interfaces; | |
7 | |
8 namespace Server.EndPoints | |
9 { | |
10 public class MessageEndPoint<T, TV> : ObservableObject | |
11 where T : MessageBase | |
12 where TV : LogMessage | |
13 | |
14 { | |
15 #region Fields | |
16 | |
17 private readonly IListener _listener; | |
18 | |
19 #endregion | |
20 | |
21 #region Constructor | |
22 | |
23 public MessageEndPoint(IListener listener) | |
24 { | |
25 _listener = listener; | |
26 Init(); | |
27 } | |
28 | |
29 #endregion | |
30 | |
31 public void Init() | |
32 { | |
33 Messenger.Default.Register<T>(this, ClientMessageReceived); | |
34 Messenger.Default.Register<TV>(this, LogMessageReceived); | |
35 } | |
36 | |
37 protected void LogMessageReceived(TV message) | |
38 { | |
39 this.DisplayLog = DisplayLog + Environment.NewLine + message.Body; | |
40 } | |
41 | |
42 protected void ClientMessageReceived(T message) | |
43 { | |
44 this.DisplayCount++; | |
45 } | |
46 | |
47 #region Properties | |
48 | |
49 #region IsListening | |
50 | |
51 public const string IsListeningPropertyName = "IsListening"; | |
52 private bool _isListening; | |
53 public bool IsListening | |
54 { | |
55 get { return _isListening; } | |
56 set | |
57 { | |
58 if (_isListening == value) return; | |
59 _isListening = value; | |
60 RaisePropertyChanged(() => IsListening); | |
61 ToggleListener(); | |
62 } | |
63 } | |
64 | |
65 #endregion | |
66 | |
67 #region DisplayText | |
68 | |
69 public const string DisplayTextPropertyName = "DisplayText"; | |
70 private string _displayText; | |
71 public string DisplayText | |
72 { | |
73 get { return _displayText; } | |
74 set | |
75 { | |
76 if (_displayText == value) return; | |
77 _displayText = value; | |
78 RaisePropertyChanged(() => DisplayText); | |
79 } | |
80 } | |
81 | |
82 #endregion | |
83 | |
84 #region DisplayCount | |
85 | |
86 public const string DisplayCountPropertyName = "DisplayCount"; | |
87 private volatile int _displayCount; | |
88 public int DisplayCount | |
89 { | |
90 get { return _displayCount; } | |
91 set | |
92 { | |
93 if (_displayCount == value) return; | |
94 _displayCount = value; | |
95 RaisePropertyChanged(() => DisplayCount); | |
96 } | |
97 } | |
98 #endregion | |
99 | |
100 #region DisplayLog | |
101 | |
102 public const string DisplayLogPropertyName = "DisplayLog"; | |
103 private string _displayLog = string.Empty; | |
104 public string DisplayLog | |
105 { | |
106 get { return _displayLog; } | |
107 set | |
108 { | |
109 if (_displayLog == value) return; | |
110 _displayLog = value; | |
111 RaisePropertyChanged(() => DisplayLog); | |
112 IsLogChanged = true; | |
113 } | |
114 } | |
115 | |
116 #endregion | |
117 | |
118 #region IsLogChanged | |
119 | |
120 public const string IsLogChangedPropertyName = "IsLogChanged"; | |
121 private bool _isLogChanged; | |
122 public bool IsLogChanged | |
123 { | |
124 get { return _isLogChanged; } | |
125 set | |
126 { | |
127 if (_isLogChanged == value) return; | |
128 _isLogChanged = value; | |
129 RaisePropertyChanged(() => IsLogChanged); | |
130 } | |
131 } | |
132 | |
133 #endregion | |
134 | |
135 #region ToolTip | |
136 | |
137 public const string ToolTipPropertyName = "ToolTip"; | |
138 private string _toolTip = string.Empty; | |
139 public string ToolTip | |
140 { | |
141 get { return _toolTip; } | |
142 set | |
143 { | |
144 if (_toolTip == value) return; | |
145 _toolTip = value; | |
146 RaisePropertyChanged(() => ToolTip); | |
147 } | |
148 } | |
149 | |
150 #endregion | |
151 | |
152 #endregion | |
153 | |
154 #region Commands | |
155 | |
156 | |
157 private void ToggleListener() | |
158 { | |
159 if (null == _listener) return; | |
160 | |
161 if (_listener.IsListening) | |
162 { | |
163 Task.Factory.StartNew(_listener.Stop); | |
164 } | |
165 else | |
166 { | |
167 Task.Factory.StartNew(_listener.Start); | |
168 } | |
169 } | |
170 | |
171 #endregion | |
172 } | |
173 } |