28
|
1 using System.Windows.Input;
|
26
|
2 using Common;
|
|
3 using Common.Logger;
|
29
|
4 using Common.Messages;
|
26
|
5 using GalaSoft.MvvmLight;
|
|
6 using GalaSoft.MvvmLight.Command;
|
|
7 using System.Windows;
|
27
|
8 using Server.EndPoints;
|
26
|
9 using Server.Interfaces;
|
27
|
10 using Server.Listeners;
|
26
|
11
|
|
12 namespace Server.UI
|
|
13 {
|
|
14 public class MainWindowViewModel : ViewModelBase
|
|
15 {
|
|
16 #region Properties
|
|
17
|
|
18 #region OverrideSwitch
|
|
19
|
|
20 public const string OverrideSwitchPropertyName = "OverrideSwitch";
|
|
21 private bool? _overrideSwitch = false;
|
|
22 public bool? OverrideSwitch
|
|
23 {
|
|
24 get { return _overrideSwitch; }
|
|
25 set
|
|
26 {
|
|
27 if (_overrideSwitch == value) return;
|
|
28 var oldValue = _overrideSwitch;
|
|
29 _overrideSwitch = value;
|
|
30 RaisePropertyChanged(() => OverrideSwitch, oldValue, value, false);
|
|
31 }
|
|
32 }
|
|
33
|
|
34 #endregion
|
|
35
|
|
36 #endregion
|
|
37
|
|
38 public ICommand CloseCommand { get; set; }
|
|
39
|
29
|
40 public MessageEndPoint<MsmqClientMessage, MsmqLogMessage> MsmqEndPoint { get; set; }
|
|
41 public MessageEndPoint<SocketClientMessage, SocketLogMessage> SocketEndPoint { get; set; }
|
|
42 public MessageEndPoint<RabbitClientMessage, RabbitLogMessage> RabbitEndPoint { get; set; }
|
|
43 public MessageEndPoint<RabbitProtoClientMessage, RabbitProtoLogMessage> RabbitProtoEndPoint { get; set; }
|
26
|
44
|
|
45 #region Constructor
|
|
46
|
|
47 public MainWindowViewModel()
|
|
48 {
|
29
|
49 InitMsmqEndPoint(Settings.MsmqQueueName);
|
|
50 //InitSocketEndPoint(Settings.SocketsPortNumber);
|
|
51 InitRabbitEndPoint(Settings.RabbitPortNumber, Settings.RabbitQueueName);
|
27
|
52 InitRabbitProtoEndPoint(Settings.RabbitProtoPortNumber);
|
26
|
53
|
|
54 CloseCommand = new RelayCommand(CloseCommandExecute);
|
28
|
55 }
|
27
|
56
|
28
|
57 #endregion
|
27
|
58
|
29
|
59 private void InitMsmqEndPoint(string queueName)
|
|
60 {
|
|
61 IListener listener = new MsmqListener(queueName);
|
|
62 MsmqEndPoint = new MessageEndPoint<MsmqClientMessage, MsmqLogMessage>(listener)
|
|
63 {
|
|
64 DisplayText = "Microsoft Message Queue",
|
|
65 ToolTip = string.Format("Listening on msmq queue ({0})", queueName)
|
|
66 };
|
|
67 }
|
|
68
|
27
|
69 private void InitSocketEndPoint(int port)
|
|
70 {
|
|
71 IListener listener = new AsyncSocketListener(port);
|
29
|
72 SocketEndPoint = new MessageEndPoint<SocketClientMessage, SocketLogMessage>(listener)
|
27
|
73 {
|
|
74 DisplayText = "Async Sockets",
|
|
75 ToolTip = "Listening over TCP/IP on socket localhost:" + port
|
|
76 };
|
26
|
77 }
|
|
78
|
28
|
79 private void InitRabbitEndPoint(int port, string queueName)
|
27
|
80 {
|
28
|
81 IListener listener = new RabbitQueueListener(port, queueName);
|
29
|
82 RabbitEndPoint = new MessageEndPoint<RabbitClientMessage, RabbitLogMessage>(listener)
|
27
|
83 {
|
|
84 DisplayText = "RabbitMQ",
|
|
85 ToolTip = "Listening..." + port
|
|
86 };
|
|
87 }
|
|
88
|
|
89 private void InitRabbitProtoEndPoint(int port)
|
|
90 {
|
|
91 IListener listener = null;
|
29
|
92 RabbitProtoEndPoint = new MessageEndPoint<RabbitProtoClientMessage, RabbitProtoLogMessage>(listener)
|
27
|
93 {
|
|
94 DisplayText = "RabbitMQ with Protobuf-net",
|
|
95 ToolTip = "Listening...." + port
|
|
96 };
|
|
97 }
|
29
|
98
|
26
|
99 private void CloseCommandExecute()
|
|
100 {
|
|
101 Log.Write("Closing command executed");
|
|
102 Application.Current.Shutdown();
|
|
103 }
|
|
104 }
|
|
105 }
|