annotate Messaging/Server/UI/MainWindowViewModel.cs @ 88:e84dc4926a5a

OSL work from 2011
author stevenhollidge <stevenhollidge@hotmail.com>
date Fri, 27 Apr 2012 08:44:37 +0100
parents 874e51b94623
children
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;
29
9919ee227c93 msmq added
adminsh@apollo
parents: 28
diff changeset
3 using Common.Messages;
26
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
4 using GalaSoft.MvvmLight;
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
5 using GalaSoft.MvvmLight.Command;
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
6 using System.Windows;
31
7d9de5746f18 Working version
adminsh@apollo
parents: 29
diff changeset
7 using GalaSoft.MvvmLight.Messaging;
27
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
8 using Server.EndPoints;
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
9 using Server.Listeners;
26
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
10
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
11 namespace Server.UI
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
12 {
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
13 public class MainWindowViewModel : ViewModelBase
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
14 {
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
15 #region Properties
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
16
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
17 #region OverrideSwitch
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
18
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
19 public const string OverrideSwitchPropertyName = "OverrideSwitch";
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
20 private bool? _overrideSwitch = false;
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
21 public bool? OverrideSwitch
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
22 {
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
23 get { return _overrideSwitch; }
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
24 set
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
25 {
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
26 if (_overrideSwitch == value) return;
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
27 _overrideSwitch = value;
31
7d9de5746f18 Working version
adminsh@apollo
parents: 29
diff changeset
28 RaisePropertyChanged(() => OverrideSwitch);
7d9de5746f18 Working version
adminsh@apollo
parents: 29
diff changeset
29 if (OverrideSwitch == null) return;
7d9de5746f18 Working version
adminsh@apollo
parents: 29
diff changeset
30
7d9de5746f18 Working version
adminsh@apollo
parents: 29
diff changeset
31 Messenger.Default.Send((bool) OverrideSwitch
7d9de5746f18 Working version
adminsh@apollo
parents: 29
diff changeset
32 ? new OverrideSwitchMessage() {Switch = Switch.On}
7d9de5746f18 Working version
adminsh@apollo
parents: 29
diff changeset
33 : new OverrideSwitchMessage() {Switch = Switch.Off});
26
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
34 }
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
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
37 #endregion
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
38
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
39 #endregion
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
40
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
41 public ICommand CloseCommand { get; set; }
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
42
29
9919ee227c93 msmq added
adminsh@apollo
parents: 28
diff changeset
43 public MessageEndPoint<MsmqClientMessage, MsmqLogMessage> MsmqEndPoint { get; set; }
9919ee227c93 msmq added
adminsh@apollo
parents: 28
diff changeset
44 public MessageEndPoint<RabbitClientMessage, RabbitLogMessage> RabbitEndPoint { get; set; }
31
7d9de5746f18 Working version
adminsh@apollo
parents: 29
diff changeset
45 public MessageEndPoint<ZeroMqClientMessage, ZeroMqLogMessage> ZeroMqEndPoint { get; set; }
26
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 #region Constructor
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
48
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
49 public MainWindowViewModel()
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
50 {
29
9919ee227c93 msmq added
adminsh@apollo
parents: 28
diff changeset
51 InitMsmqEndPoint(Settings.MsmqQueueName);
9919ee227c93 msmq added
adminsh@apollo
parents: 28
diff changeset
52 InitRabbitEndPoint(Settings.RabbitPortNumber, Settings.RabbitQueueName);
34
874e51b94623 ZeroMq uses different style of address for client and server
adminsh@apollo
parents: 31
diff changeset
53 InitZeroMqEndPoint(Settings.ZeroMqServerAddress);
26
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
54
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
55 CloseCommand = new RelayCommand(CloseCommandExecute);
28
4c0dea4760c5 RabbitMq working
adminsh@apollo
parents: 27
diff changeset
56 }
27
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
57
28
4c0dea4760c5 RabbitMq working
adminsh@apollo
parents: 27
diff changeset
58 #endregion
27
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
59
29
9919ee227c93 msmq added
adminsh@apollo
parents: 28
diff changeset
60 private void InitMsmqEndPoint(string queueName)
9919ee227c93 msmq added
adminsh@apollo
parents: 28
diff changeset
61 {
9919ee227c93 msmq added
adminsh@apollo
parents: 28
diff changeset
62 IListener listener = new MsmqListener(queueName);
9919ee227c93 msmq added
adminsh@apollo
parents: 28
diff changeset
63 MsmqEndPoint = new MessageEndPoint<MsmqClientMessage, MsmqLogMessage>(listener)
9919ee227c93 msmq added
adminsh@apollo
parents: 28
diff changeset
64 {
9919ee227c93 msmq added
adminsh@apollo
parents: 28
diff changeset
65 DisplayText = "Microsoft Message Queue",
9919ee227c93 msmq added
adminsh@apollo
parents: 28
diff changeset
66 ToolTip = string.Format("Listening on msmq queue ({0})", queueName)
9919ee227c93 msmq added
adminsh@apollo
parents: 28
diff changeset
67 };
9919ee227c93 msmq added
adminsh@apollo
parents: 28
diff changeset
68 }
9919ee227c93 msmq added
adminsh@apollo
parents: 28
diff changeset
69
28
4c0dea4760c5 RabbitMq working
adminsh@apollo
parents: 27
diff changeset
70 private void InitRabbitEndPoint(int port, string queueName)
27
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
71 {
28
4c0dea4760c5 RabbitMq working
adminsh@apollo
parents: 27
diff changeset
72 IListener listener = new RabbitQueueListener(port, queueName);
29
9919ee227c93 msmq added
adminsh@apollo
parents: 28
diff changeset
73 RabbitEndPoint = new MessageEndPoint<RabbitClientMessage, RabbitLogMessage>(listener)
27
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
74 {
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
75 DisplayText = "RabbitMQ",
31
7d9de5746f18 Working version
adminsh@apollo
parents: 29
diff changeset
76 ToolTip = string.Format("Listening on port {0} to queue {1} and binding it to amq.direct", port, queueName)
27
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
77 };
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
78 }
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
79
31
7d9de5746f18 Working version
adminsh@apollo
parents: 29
diff changeset
80 private void InitZeroMqEndPoint(string address)
27
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
81 {
31
7d9de5746f18 Working version
adminsh@apollo
parents: 29
diff changeset
82 IListener listener = new ZeroMqListener(address);
7d9de5746f18 Working version
adminsh@apollo
parents: 29
diff changeset
83 ZeroMqEndPoint = new MessageEndPoint<ZeroMqClientMessage, ZeroMqLogMessage>(listener)
27
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
84 {
31
7d9de5746f18 Working version
adminsh@apollo
parents: 29
diff changeset
85 DisplayText = "ZeroMq",
7d9de5746f18 Working version
adminsh@apollo
parents: 29
diff changeset
86 ToolTip = "Listening on " + address
27
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 }
29
9919ee227c93 msmq added
adminsh@apollo
parents: 28
diff changeset
89
26
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
90 private void CloseCommandExecute()
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
91 {
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
92 Application.Current.Shutdown();
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
93 }
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
94 }
31
7d9de5746f18 Working version
adminsh@apollo
parents: 29
diff changeset
95 }