Mercurial > silverbladetech
annotate Messaging/Server/UI/MainWindowViewModel.cs @ 72:177a9d1eba10
Latest version
author | Steven Hollidge <stevenhollidge@hotmail.com> |
---|---|
date | Mon, 23 Apr 2012 17:57:21 +0100 |
parents | 874e51b94623 |
children |
rev | line source |
---|---|
28 | 1 using System.Windows.Input; |
26 | 2 using Common; |
29 | 3 using Common.Messages; |
26 | 4 using GalaSoft.MvvmLight; |
5 using GalaSoft.MvvmLight.Command; | |
6 using System.Windows; | |
31 | 7 using GalaSoft.MvvmLight.Messaging; |
27 | 8 using Server.EndPoints; |
9 using Server.Listeners; | |
26 | 10 |
11 namespace Server.UI | |
12 { | |
13 public class MainWindowViewModel : ViewModelBase | |
14 { | |
15 #region Properties | |
16 | |
17 #region OverrideSwitch | |
18 | |
19 public const string OverrideSwitchPropertyName = "OverrideSwitch"; | |
20 private bool? _overrideSwitch = false; | |
21 public bool? OverrideSwitch | |
22 { | |
23 get { return _overrideSwitch; } | |
24 set | |
25 { | |
26 if (_overrideSwitch == value) return; | |
27 _overrideSwitch = value; | |
31 | 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}); | |
26 | 34 } |
35 } | |
36 | |
37 #endregion | |
38 | |
39 #endregion | |
40 | |
41 public ICommand CloseCommand { get; set; } | |
42 | |
29 | 43 public MessageEndPoint<MsmqClientMessage, MsmqLogMessage> MsmqEndPoint { get; set; } |
44 public MessageEndPoint<RabbitClientMessage, RabbitLogMessage> RabbitEndPoint { get; set; } | |
31 | 45 public MessageEndPoint<ZeroMqClientMessage, ZeroMqLogMessage> ZeroMqEndPoint { get; set; } |
26 | 46 |
47 #region Constructor | |
48 | |
49 public MainWindowViewModel() | |
50 { | |
29 | 51 InitMsmqEndPoint(Settings.MsmqQueueName); |
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 | 54 |
55 CloseCommand = new RelayCommand(CloseCommandExecute); | |
28 | 56 } |
27 | 57 |
28 | 58 #endregion |
27 | 59 |
29 | 60 private void InitMsmqEndPoint(string queueName) |
61 { | |
62 IListener listener = new MsmqListener(queueName); | |
63 MsmqEndPoint = new MessageEndPoint<MsmqClientMessage, MsmqLogMessage>(listener) | |
64 { | |
65 DisplayText = "Microsoft Message Queue", | |
66 ToolTip = string.Format("Listening on msmq queue ({0})", queueName) | |
67 }; | |
68 } | |
69 | |
28 | 70 private void InitRabbitEndPoint(int port, string queueName) |
27 | 71 { |
28 | 72 IListener listener = new RabbitQueueListener(port, queueName); |
29 | 73 RabbitEndPoint = new MessageEndPoint<RabbitClientMessage, RabbitLogMessage>(listener) |
27 | 74 { |
75 DisplayText = "RabbitMQ", | |
31 | 76 ToolTip = string.Format("Listening on port {0} to queue {1} and binding it to amq.direct", port, queueName) |
27 | 77 }; |
78 } | |
79 | |
31 | 80 private void InitZeroMqEndPoint(string address) |
27 | 81 { |
31 | 82 IListener listener = new ZeroMqListener(address); |
83 ZeroMqEndPoint = new MessageEndPoint<ZeroMqClientMessage, ZeroMqLogMessage>(listener) | |
27 | 84 { |
31 | 85 DisplayText = "ZeroMq", |
86 ToolTip = "Listening on " + address | |
27 | 87 }; |
88 } | |
29 | 89 |
26 | 90 private void CloseCommandExecute() |
91 { | |
92 Application.Current.Shutdown(); | |
93 } | |
94 } | |
31 | 95 } |