annotate Messaging/Server/UI/MainWindowViewModel.cs @ 29:9919ee227c93

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