annotate Messaging/Server/UI/MainWindowViewModel.cs @ 27:96fdf58e05b4

Server working with sockets and rabbitmq
author adminsh@apollo
date Wed, 21 Mar 2012 19:00:59 +0000
parents 045dac571339
children 4c0dea4760c5
rev   line source
27
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
1 using System;
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
2 using System.Windows.Input;
26
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
3 using Common;
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
4 using Common.Logger;
27
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
5 using Common.Messages;
26
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
6 using GalaSoft.MvvmLight;
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
7 using GalaSoft.MvvmLight.Command;
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
8 using System.Windows;
27
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
9 using GalaSoft.MvvmLight.Messaging;
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
10 using Server.EndPoints;
26
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
11 using Server.Interfaces;
27
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
12 using Server.Listeners;
26
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 namespace Server.UI
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 public class MainWindowViewModel : ViewModelBase
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 Properties
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 #region OverrideSwitch
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
21
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
22 public const string OverrideSwitchPropertyName = "OverrideSwitch";
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
23 private bool? _overrideSwitch = false;
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
24 public bool? OverrideSwitch
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 get { return _overrideSwitch; }
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
27 set
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
28 {
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
29 if (_overrideSwitch == value) return;
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
30 var oldValue = _overrideSwitch;
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
31 _overrideSwitch = value;
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
32 RaisePropertyChanged(() => OverrideSwitch, oldValue, value, false);
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 }
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 #endregion
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
39
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
40 public ICommand CloseCommand { get; set; }
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
41
27
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
42 public BaseEndPoint SocketEndPoint { get; set; }
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
43 public BaseEndPoint RabbitEndPoint { get; set; }
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
44 public BaseEndPoint RabbitProtoEndPoint { get; set; }
26
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
45
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
46 #region Constructor
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
47
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
48 public MainWindowViewModel()
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
49 {
27
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
50 InitSocketEndPoint(Settings.SocketsPortNumber);
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
51 InitRabbitEndPoint(Settings.RabbitPortNumber);
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);
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 }
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 private void InitSocketEndPoint(int port)
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
59 {
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
60 IListener listener = new AsyncSocketListener(port);
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
61 SocketEndPoint = new SocketEndPoint(listener)
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
62 {
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
63 DisplayText = "Async Sockets",
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
64 ToolTip = "Listening over TCP/IP on socket localhost:" + port
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
65 };
26
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
66 }
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
67
27
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
68 private void InitRabbitEndPoint(int port)
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
69 {
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
70 IListener listener = new RabbitQueueListener(port);
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
71 RabbitEndPoint = new RabbitEndPoint(listener)
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
72 {
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
73 DisplayText = "RabbitMQ",
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
74 ToolTip = "Listening..." + port
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 }
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 private void InitRabbitProtoEndPoint(int port)
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
79 {
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
80 IListener listener = null;
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
81 RabbitProtoEndPoint = new RabbitProtoEndPoint(listener)
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
82 {
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
83 DisplayText = "RabbitMQ with Protobuf-net",
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
84 ToolTip = "Listening...." + port
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
85 };
96fdf58e05b4 Server working with sockets and rabbitmq
adminsh@apollo
parents: 26
diff changeset
86 }
26
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
87 private void CloseCommandExecute()
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
88 {
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
89 Log.Write("Closing command executed");
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
90 Application.Current.Shutdown();
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
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
93 #endregion
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
94 }
045dac571339 Working on data binding to a user control
adminsh@apollo
parents:
diff changeset
95 }