annotate Messaging/Server/UI/MainWindowViewModel.cs @ 28:4c0dea4760c5

RabbitMq working
author adminsh@apollo
date Wed, 21 Mar 2012 20:29:04 +0000
parents 96fdf58e05b4
children 9919ee227c93
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;
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;
27
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
7 using Server.EndPoints;
26
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
8 using Server.Interfaces;
27
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 var oldValue = _overrideSwitch;
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
28 _overrideSwitch = value;
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
29 RaisePropertyChanged(() => OverrideSwitch, oldValue, value, false);
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
30 }
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 #endregion
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 #endregion
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 public ICommand CloseCommand { get; set; }
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
38
27
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
39 public BaseEndPoint SocketEndPoint { get; set; }
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
40 public BaseEndPoint RabbitEndPoint { get; set; }
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
41 public BaseEndPoint RabbitProtoEndPoint { get; set; }
26
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
42
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
43 #region Constructor
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 public MainWindowViewModel()
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
46 {
27
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
47 InitSocketEndPoint(Settings.SocketsPortNumber);
28
4c0dea4760c5 RabbitMq working
adminsh@apollo
parents: 27
diff changeset
48 InitRabbitEndPoint(Settings.RabbitPortNumber, Settings.QueueName);
27
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
49 InitRabbitProtoEndPoint(Settings.RabbitProtoPortNumber);
26
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
50
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
51 CloseCommand = new RelayCommand(CloseCommandExecute);
28
4c0dea4760c5 RabbitMq working
adminsh@apollo
parents: 27
diff changeset
52 }
27
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
53
28
4c0dea4760c5 RabbitMq working
adminsh@apollo
parents: 27
diff changeset
54 #endregion
27
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
55
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
56 private void InitSocketEndPoint(int port)
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
57 {
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
58 IListener listener = new AsyncSocketListener(port);
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
59 SocketEndPoint = new SocketEndPoint(listener)
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
60 {
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
61 DisplayText = "Async Sockets",
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
62 ToolTip = "Listening over TCP/IP on socket localhost:" + port
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
63 };
26
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
64 }
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
65
28
4c0dea4760c5 RabbitMq working
adminsh@apollo
parents: 27
diff changeset
66 private void InitRabbitEndPoint(int port, string queueName)
27
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
67 {
28
4c0dea4760c5 RabbitMq working
adminsh@apollo
parents: 27
diff changeset
68 IListener listener = new RabbitQueueListener(port, queueName);
27
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
69 RabbitEndPoint = new RabbitEndPoint(listener)
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 DisplayText = "RabbitMQ",
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
72 ToolTip = "Listening..." + port
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 }
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
75
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
76 private void InitRabbitProtoEndPoint(int port)
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 IListener listener = null;
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
79 RabbitProtoEndPoint = new RabbitProtoEndPoint(listener)
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
80 {
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
81 DisplayText = "RabbitMQ with Protobuf-net",
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
82 ToolTip = "Listening...." + port
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 }
26
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
85 private void CloseCommandExecute()
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
86 {
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
87 Log.Write("Closing command executed");
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
88 Application.Current.Shutdown();
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
89 }
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
90 }
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
91 }