comparison Messaging/Server/UI/MainWindowViewModel.cs @ 31:7d9de5746f18

Working version
author adminsh@apollo
date Thu, 22 Mar 2012 08:09:41 +0000
parents 9919ee227c93
children 874e51b94623
comparison
equal deleted inserted replaced
30:8d574f2d4174 31:7d9de5746f18
1 using System.Windows.Input; 1 using System.Windows.Input;
2 using Common; 2 using Common;
3 using Common.Logger;
4 using Common.Messages; 3 using Common.Messages;
5 using GalaSoft.MvvmLight; 4 using GalaSoft.MvvmLight;
6 using GalaSoft.MvvmLight.Command; 5 using GalaSoft.MvvmLight.Command;
7 using System.Windows; 6 using System.Windows;
7 using GalaSoft.MvvmLight.Messaging;
8 using Server.EndPoints; 8 using Server.EndPoints;
9 using Server.Interfaces;
10 using Server.Listeners; 9 using Server.Listeners;
11 10
12 namespace Server.UI 11 namespace Server.UI
13 { 12 {
14 public class MainWindowViewModel : ViewModelBase 13 public class MainWindowViewModel : ViewModelBase
23 { 22 {
24 get { return _overrideSwitch; } 23 get { return _overrideSwitch; }
25 set 24 set
26 { 25 {
27 if (_overrideSwitch == value) return; 26 if (_overrideSwitch == value) return;
28 var oldValue = _overrideSwitch;
29 _overrideSwitch = value; 27 _overrideSwitch = value;
30 RaisePropertyChanged(() => OverrideSwitch, oldValue, value, false); 28 RaisePropertyChanged(() => OverrideSwitch);
29 if (OverrideSwitch == null) return;
30
31 Messenger.Default.Send((bool) OverrideSwitch
32 ? new OverrideSwitchMessage() {Switch = Switch.On}
33 : new OverrideSwitchMessage() {Switch = Switch.Off});
31 } 34 }
32 } 35 }
33 36
34 #endregion 37 #endregion
35 38
36 #endregion 39 #endregion
37 40
38 public ICommand CloseCommand { get; set; } 41 public ICommand CloseCommand { get; set; }
39 42
40 public MessageEndPoint<MsmqClientMessage, MsmqLogMessage> MsmqEndPoint { get; set; } 43 public MessageEndPoint<MsmqClientMessage, MsmqLogMessage> MsmqEndPoint { get; set; }
41 public MessageEndPoint<SocketClientMessage, SocketLogMessage> SocketEndPoint { get; set; }
42 public MessageEndPoint<RabbitClientMessage, RabbitLogMessage> RabbitEndPoint { get; set; } 44 public MessageEndPoint<RabbitClientMessage, RabbitLogMessage> RabbitEndPoint { get; set; }
43 public MessageEndPoint<RabbitProtoClientMessage, RabbitProtoLogMessage> RabbitProtoEndPoint { get; set; } 45 public MessageEndPoint<ZeroMqClientMessage, ZeroMqLogMessage> ZeroMqEndPoint { get; set; }
44 46
45 #region Constructor 47 #region Constructor
46 48
47 public MainWindowViewModel() 49 public MainWindowViewModel()
48 { 50 {
49 InitMsmqEndPoint(Settings.MsmqQueueName); 51 InitMsmqEndPoint(Settings.MsmqQueueName);
50 //InitSocketEndPoint(Settings.SocketsPortNumber);
51 InitRabbitEndPoint(Settings.RabbitPortNumber, Settings.RabbitQueueName); 52 InitRabbitEndPoint(Settings.RabbitPortNumber, Settings.RabbitQueueName);
52 InitRabbitProtoEndPoint(Settings.RabbitProtoPortNumber); 53 InitZeroMqEndPoint(Settings.ZeroMqAddress);
53 54
54 CloseCommand = new RelayCommand(CloseCommandExecute); 55 CloseCommand = new RelayCommand(CloseCommandExecute);
55 } 56 }
56 57
57 #endregion 58 #endregion
64 DisplayText = "Microsoft Message Queue", 65 DisplayText = "Microsoft Message Queue",
65 ToolTip = string.Format("Listening on msmq queue ({0})", queueName) 66 ToolTip = string.Format("Listening on msmq queue ({0})", queueName)
66 }; 67 };
67 } 68 }
68 69
69 private void InitSocketEndPoint(int port)
70 {
71 IListener listener = new AsyncSocketListener(port);
72 SocketEndPoint = new MessageEndPoint<SocketClientMessage, SocketLogMessage>(listener)
73 {
74 DisplayText = "Async Sockets",
75 ToolTip = "Listening over TCP/IP on socket localhost:" + port
76 };
77 }
78
79 private void InitRabbitEndPoint(int port, string queueName) 70 private void InitRabbitEndPoint(int port, string queueName)
80 { 71 {
81 IListener listener = new RabbitQueueListener(port, queueName); 72 IListener listener = new RabbitQueueListener(port, queueName);
82 RabbitEndPoint = new MessageEndPoint<RabbitClientMessage, RabbitLogMessage>(listener) 73 RabbitEndPoint = new MessageEndPoint<RabbitClientMessage, RabbitLogMessage>(listener)
83 { 74 {
84 DisplayText = "RabbitMQ", 75 DisplayText = "RabbitMQ",
85 ToolTip = "Listening..." + port 76 ToolTip = string.Format("Listening on port {0} to queue {1} and binding it to amq.direct", port, queueName)
86 }; 77 };
87 } 78 }
88 79
89 private void InitRabbitProtoEndPoint(int port) 80 private void InitZeroMqEndPoint(string address)
90 { 81 {
91 IListener listener = null; 82 IListener listener = new ZeroMqListener(address);
92 RabbitProtoEndPoint = new MessageEndPoint<RabbitProtoClientMessage, RabbitProtoLogMessage>(listener) 83 ZeroMqEndPoint = new MessageEndPoint<ZeroMqClientMessage, ZeroMqLogMessage>(listener)
93 { 84 {
94 DisplayText = "RabbitMQ with Protobuf-net", 85 DisplayText = "ZeroMq",
95 ToolTip = "Listening...." + port 86 ToolTip = "Listening on " + address
96 }; 87 };
97 } 88 }
98 89
99 private void CloseCommandExecute() 90 private void CloseCommandExecute()
100 { 91 {
101 Log.Write("Closing command executed");
102 Application.Current.Shutdown(); 92 Application.Current.Shutdown();
103 } 93 }
104 } 94 }
105 } 95 }