changeset 31:7d9de5746f18

Working version
author adminsh@apollo
date Thu, 22 Mar 2012 08:09:41 +0000
parents 8d574f2d4174
children 2df455021a91
files Messaging/Client/Client.csproj Messaging/Client/UI/MainWindow.xaml Messaging/Client/UI/MainWindow.xaml.cs Messaging/Common/Common.csproj Messaging/Common/Controls/MessageTile.xaml.cs Messaging/Common/Logger/Log.cs Messaging/Common/Messages/ClientMessages.cs Messaging/Common/Messages/LogMessages.cs Messaging/Common/Messages/OverrideSwitchMessage.cs Messaging/Common/Settings.cs Messaging/Libs/ZeroMq/clrzmq.dll Messaging/Libs/ZeroMq/clrzmq.pdb Messaging/Libs/ZeroMq/libzmq.dll Messaging/Server/EndPoints/MessageEndPoint.cs Messaging/Server/Interfaces/IListener.cs Messaging/Server/Listeners/AsyncSocketListener.cs Messaging/Server/Listeners/IListener.cs Messaging/Server/Listeners/MsmqListener.cs Messaging/Server/Listeners/RabbitQueueListener.cs Messaging/Server/Listeners/ZeroMqListener.cs Messaging/Server/Server.csproj Messaging/Server/UI/MainWindow.xaml Messaging/Server/UI/MainWindowViewModel.cs
diffstat 23 files changed, 231 insertions(+), 379 deletions(-) [+]
line wrap: on
line diff
--- a/Messaging/Client/Client.csproj	Wed Mar 21 22:26:48 2012 +0000
+++ b/Messaging/Client/Client.csproj	Thu Mar 22 08:09:41 2012 +0000
@@ -40,6 +40,9 @@
     </ApplicationIcon>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="clrzmq">
+      <HintPath>..\Libs\ZeroMq\clrzmq.dll</HintPath>
+    </Reference>
     <Reference Include="Elysium.Theme">
       <HintPath>..\Libs\Elysium.Theme.1.3\Elysium.Theme.dll</HintPath>
     </Reference>
@@ -110,6 +113,9 @@
     <Resource Include="UI\upload.ico" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <PropertyGroup>
+    <PostBuildEvent>copy $(SolutionDir)Libs\zeromq\libzmq.dll $(TargetDir)</PostBuildEvent>
+  </PropertyGroup>
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.
   <Target Name="BeforeBuild">
--- a/Messaging/Client/UI/MainWindow.xaml	Wed Mar 21 22:26:48 2012 +0000
+++ b/Messaging/Client/UI/MainWindow.xaml	Thu Mar 22 08:09:41 2012 +0000
@@ -22,7 +22,7 @@
                         Grid.Row="0"
                         Grid.Column="0"
                         Margin="10"
-                        Click="btnMsmq_Click"
+                        Click="BtnMsmqClick"
                         Content="Msmq" />
                 <Button Name="btnRabbit"
                         Grid.Row="1"
@@ -34,12 +34,14 @@
                         Grid.Row="2"
                         Grid.Column="0"
                         Margin="10"
-                        Content="0MQ" Click="btnZeroMq_Click" />
-                <Button Name="btnSockets"
+                        Click="BtnZeroMqClick"
+                        Content="0MQ" />
+                <Button Name="btnSendAll"
                         Grid.Row="3"
                         Grid.Column="0"
                         Margin="10"
-                        Content="Send All" Click="btnSockets_Click" />
+                        Click="BtnSendAllClick"
+                        Content="Send All" />
             </Grid>
         </TabItem>
     </TabControl>
--- a/Messaging/Client/UI/MainWindow.xaml.cs	Wed Mar 21 22:26:48 2012 +0000
+++ b/Messaging/Client/UI/MainWindow.xaml.cs	Thu Mar 22 08:09:41 2012 +0000
@@ -23,60 +23,78 @@
         private void BtnRabbitClick(object sender, RoutedEventArgs e)
         {
             Task.Factory.StartNew(() =>
-            {
-                var cf = new ConnectionFactory {Address = "localhost:" + Settings.RabbitPortNumber};
+                                      {
+                                          var cf = new ConnectionFactory
+                                                       {Address = "localhost:" + Settings.RabbitPortNumber};
 
-                using (var conn = cf.CreateConnection())
-                using (var channel = conn.CreateModel())
-                {
-                    for (var i = 0; i < MessageCount; i++)
-                    {
-                        channel.BasicPublish("amq.direct", Settings.RabbitQueueName, null,
-                                             Encoding.UTF8.GetBytes("hello from the client!"));
-                    }
-                }
-            });
+                                          using (var conn = cf.CreateConnection())
+                                          using (var channel = conn.CreateModel())
+                                          {
+                                              for (var i = 0; i < MessageCount; i++)
+                                              {
+                                                  channel.BasicPublish("amq.direct", Settings.RabbitQueueName, null,
+                                                                       Encoding.UTF8.GetBytes("hello from the client!"));
+                                              }
+                                          }
+                                      });
         }
 
-        private void btnMsmq_Click(object sender, RoutedEventArgs e)
+        private void BtnMsmqClick(object sender, RoutedEventArgs e)
         {
             Task.Factory.StartNew(() =>
-            {
-                var msMq 
-                    = !MessageQueue.Exists(Settings.MsmqQueueName) 
-                    ? MessageQueue.Create(Settings.MsmqQueueName) 
-                    : new MessageQueue(Settings.MsmqQueueName);
+                                      {
+                                          var msMq
+                                              = !MessageQueue.Exists(Settings.MsmqQueueName)
+                                                    ? MessageQueue.Create(Settings.MsmqQueueName)
+                                                    : new MessageQueue(Settings.MsmqQueueName);
 
-                try
-                {
-                    for (var i = 0; i < MessageCount; i++)
-                    {
-                        msMq.Send("Sending data to MSMQ at " + DateTime.Now.ToString());
-                    }
-                }
-                catch (MessageQueueException ee)
-                {
-                    Console.Write(ee.ToString());
-                }
-                catch (Exception eee)
-                {
-                    Console.Write(eee.ToString());
-                }
-                finally
-                {
-                    msMq.Close();
-                }
-            });
+                                          try
+                                          {
+                                              for (var i = 0; i < MessageCount; i++)
+                                              {
+                                                  msMq.Send("Sending data to MSMQ at " + DateTime.Now.ToString());
+                                              }
+                                          }
+                                          catch (MessageQueueException ee)
+                                          {
+                                              Console.Write(ee.ToString());
+                                          }
+                                          catch (Exception eee)
+                                          {
+                                              Console.Write(eee.ToString());
+                                          }
+                                          finally
+                                          {
+                                              msMq.Close();
+                                          }
+                                      });
         }
 
-        private void btnZeroMq_Click(object sender, RoutedEventArgs e)
+        private void BtnZeroMqClick(object sender, RoutedEventArgs e)
         {
+            Task.Factory.StartNew(() =>
+                                      {
+                                          using (var ctx = new ZMQ.Context(1))
+                                          {
+                                              var socket = ctx.Socket(ZMQ.REQ);
+                                              socket.Connect("tcp://localhost:5555");
 
+                                              for (var i = 0; i < MessageCount; i++)
+                                              {
+                                                  socket.Send(Encoding.ASCII.GetBytes("Hello"));
+
+                                                  byte[] message;
+                                                  socket.Recv(out message);
+                                              }
+                                          }
+                                      });
         }
 
-        private void btnSockets_Click(object sender, RoutedEventArgs e)
+        private void BtnSendAllClick(object sender, RoutedEventArgs e)
         {
-
+            Task.Factory.StartNew(() => BtnMsmqClick(this, null));
+            Task.Factory.StartNew(() => BtnRabbitClick(this, null));
+            Task.Factory.StartNew(() => BtnZeroMqClick(this, null));
         }
     }
 }
\ No newline at end of file
--- a/Messaging/Common/Common.csproj	Wed Mar 21 22:26:48 2012 +0000
+++ b/Messaging/Common/Common.csproj	Thu Mar 22 08:09:41 2012 +0000
@@ -43,8 +43,8 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Messages\ClientMessages.cs" />
+    <Compile Include="Messages\OverrideSwitchMessage.cs" />
     <Compile Include="Xaml\BindingErrorTraceListener.cs" />
-    <Compile Include="Logger\Log.cs" />
     <Compile Include="Messages\LogMessages.cs" />
     <Compile Include="Controls\MessageTile.xaml.cs">
       <DependentUpon>MessageTile.xaml</DependentUpon>
--- a/Messaging/Common/Controls/MessageTile.xaml.cs	Wed Mar 21 22:26:48 2012 +0000
+++ b/Messaging/Common/Controls/MessageTile.xaml.cs	Thu Mar 22 08:09:41 2012 +0000
@@ -1,7 +1,5 @@
-using System;
-using System.ComponentModel;
+using System.ComponentModel;
 using System.Windows;
-using System.Windows.Media;
 using System.Windows.Media.Imaging;
 
 namespace Common.Controls
@@ -16,7 +14,7 @@
             InitializeComponent();
         }
 
-        #region Dependency Properties
+        // Dependency Properties
 
         #region DisplayIcon
 
@@ -74,7 +72,5 @@
             set { this.SetValue(DisplayTextProperty, value); }
         }
         #endregion
-
-        #endregion
     }
 }
--- a/Messaging/Common/Logger/Log.cs	Wed Mar 21 22:26:48 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-using Common.Messages;
-using GalaSoft.MvvmLight.Messaging;
-
-namespace Common.Logger
-{
-    public class Log
-    {
-        public static void Write(string body)
-        {
-            Messenger.Default.Send(new LogMessage() { Body = body });
-        }
-    }
-}
--- a/Messaging/Common/Messages/ClientMessages.cs	Wed Mar 21 22:26:48 2012 +0000
+++ b/Messaging/Common/Messages/ClientMessages.cs	Thu Mar 22 08:09:41 2012 +0000
@@ -2,8 +2,9 @@
 
 namespace Common.Messages
 {
-    public class MsmqClientMessage : MessageBase {}
-    public class SocketClientMessage : MessageBase {}
-    public class RabbitClientMessage : MessageBase {}
-    public class RabbitProtoClientMessage : MessageBase {}
+    public class ClientMessage : MessageBase {}
+
+    public class MsmqClientMessage : ClientMessage {}
+    public class RabbitClientMessage : ClientMessage {}
+    public class ZeroMqClientMessage : ClientMessage {}
 }
--- a/Messaging/Common/Messages/LogMessages.cs	Wed Mar 21 22:26:48 2012 +0000
+++ b/Messaging/Common/Messages/LogMessages.cs	Thu Mar 22 08:09:41 2012 +0000
@@ -8,7 +8,6 @@
     }
 
     public class MsmqLogMessage : LogMessage {}
-    public class SocketLogMessage : LogMessage {}
     public class RabbitLogMessage : LogMessage {}
-    public class RabbitProtoLogMessage : LogMessage {}
+    public class ZeroMqLogMessage : LogMessage {}
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Messaging/Common/Messages/OverrideSwitchMessage.cs	Thu Mar 22 08:09:41 2012 +0000
@@ -0,0 +1,15 @@
+using GalaSoft.MvvmLight.Messaging;
+
+namespace Common.Messages
+{
+    public enum Switch
+    {
+        Off = 0,
+        On
+    }
+
+    public class OverrideSwitchMessage : MessageBase
+    {
+        public Switch Switch { get; set; }
+    }
+}
--- a/Messaging/Common/Settings.cs	Wed Mar 21 22:26:48 2012 +0000
+++ b/Messaging/Common/Settings.cs	Thu Mar 22 08:09:41 2012 +0000
@@ -2,11 +2,9 @@
 {
     public class Settings
     {
-        public const int SocketsPortNumber = 5671;
+        public const string MsmqQueueName = @".\private$\Queue#1";
         public const int RabbitPortNumber = 5672;
-        public const int RabbitProtoPortNumber = 5673;
-        public const string MsmqQueueName = @".\private$\Queue#1";
         public const string RabbitQueueName = "Queue#2";
-        //public const string Uri = @"amqp://user:pass@localhost:5672/vhost\";
+        public const string ZeroMqAddress = "tcp://*:5555";
     }
 }
Binary file Messaging/Libs/ZeroMq/clrzmq.dll has changed
Binary file Messaging/Libs/ZeroMq/clrzmq.pdb has changed
Binary file Messaging/Libs/ZeroMq/libzmq.dll has changed
--- a/Messaging/Server/EndPoints/MessageEndPoint.cs	Wed Mar 21 22:26:48 2012 +0000
+++ b/Messaging/Server/EndPoints/MessageEndPoint.cs	Thu Mar 22 08:09:41 2012 +0000
@@ -3,18 +3,18 @@
 using Common.Messages;
 using GalaSoft.MvvmLight;
 using GalaSoft.MvvmLight.Messaging;
-using Server.Interfaces;
+using Server.Listeners;
 
 namespace Server.EndPoints
 {
-    public class MessageEndPoint<T, TV> : ObservableObject
-        where T : MessageBase
-        where TV : LogMessage
-        
+    public class MessageEndPoint<T, TY> : ObservableObject
+        where T : ClientMessage
+        where TY : LogMessage
     {
         #region Fields
 
         private readonly IListener _listener;
+        private readonly object _locker;
 
         #endregion
 
@@ -23,18 +23,34 @@
         public MessageEndPoint(IListener listener)
         {
             _listener = listener;
+            _locker = new object();
             Init();
         }
 
         #endregion
 
+        #region Messaging
+
         public void Init()
         {
             Messenger.Default.Register<T>(this, ClientMessageReceived);
-            Messenger.Default.Register<TV>(this, LogMessageReceived);
+            Messenger.Default.Register<TY>(this, LogMessageReceived);
+            Messenger.Default.Register<OverrideSwitchMessage>(this, SwitchMessageReceived);
         }
 
-        protected void LogMessageReceived(TV message)
+        private void SwitchMessageReceived(OverrideSwitchMessage message)
+        {
+            if (message.Switch == Switch.Off)
+            {
+                IsListening = false;
+            }
+            else
+            {
+                IsListening = true;
+            }
+        }
+
+        protected void LogMessageReceived(TY message)
         {
             this.DisplayLog = DisplayLog + Environment.NewLine + message.Body;
         }
@@ -42,7 +58,9 @@
         protected void ClientMessageReceived(T message)
         {
             this.DisplayCount++;
-        }
+         }
+
+        #endregion
 
         #region Properties
 
@@ -84,15 +102,18 @@
         #region DisplayCount
 
         public const string DisplayCountPropertyName = "DisplayCount";
-        private volatile int _displayCount;
+        private int _displayCount;
         public int DisplayCount
         {
             get { return _displayCount; }
             set
             {
-                if (_displayCount == value) return;
-                _displayCount = value;
-                RaisePropertyChanged(() => DisplayCount);
+                lock (_locker)
+                {
+                    if (_displayCount == value) return;
+                    _displayCount = value;
+                    RaisePropertyChanged(() => DisplayCount);
+                }
             }
         }
         #endregion
@@ -153,21 +174,16 @@
 
         #region Commands
 
-
         private void ToggleListener()
         {
             if (null == _listener) return;
 
             if (_listener.IsListening)
-            {
                 Task.Factory.StartNew(_listener.Stop);
-            } 
             else
-            {
                 Task.Factory.StartNew(_listener.Start);
-            }
         }
 
         #endregion
     }
-}
+}
\ No newline at end of file
--- a/Messaging/Server/Interfaces/IListener.cs	Wed Mar 21 22:26:48 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
-namespace Server.Interfaces
-{
-    public interface IListener
-    {
-        bool IsListening { get; set; }
-        void Start();
-        void Stop();
-    }
-}
--- a/Messaging/Server/Listeners/AsyncSocketListener.cs	Wed Mar 21 22:26:48 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,232 +0,0 @@
-using System;
-using System.Net;
-using System.Net.Sockets;
-using System.Text;
-using System.Threading;
-using Common.Messages;
-using GalaSoft.MvvmLight.Messaging;
-using Server.Interfaces;
-
-namespace Server.Listeners
-{ 
-    public class AsyncSocketListener : IListener
-    {
-        public bool IsListening { get; set; }
-        private readonly int _portNumber;
-
-        // Thread signal.
-        public static ManualResetEvent AllDone = new ManualResetEvent(false);
-
-        public AsyncSocketListener(int portNumber)
-        {
-            IsListening = false;
-            _portNumber = portNumber;
-        }
-
-        public void Start()
-        {
-            if (IsListening)
-            {
-                Messenger.Default.Send(new SocketLogMessage() { Body = "Already listening..." });
-                return;
-            }
-            Messenger.Default.Send(new SocketLogMessage() { Body = "Opening listener..." });
-
-            // Data buffer for incoming data.
-            var bytes = new Byte[1024];
-
-            // Establish the local endpoint for the socket
-            var ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
-            var ipAddress = ipHostInfo.AddressList[2];
-            var localEndPoint = new IPEndPoint(ipAddress, _portNumber);
-
-            // Create a TCP/IP socket.
-            using(var listener = new Socket(
-                AddressFamily.InterNetwork,
-                SocketType.Stream, 
-                ProtocolType.Tcp))
-                {
-
-                // Bind the socket to the local endpoint and listen for incoming connections.
-                    try
-                    {
-                        listener.Bind(localEndPoint);
-                        listener.Listen(100);
-                        IsListening = true;
-
-                        Messenger.Default.Send(new SocketLogMessage() { Body = "Listener opened" });
-
-                        while (IsListening)
-                        {
-                            // Set the event to nonsignaled state.
-                            AllDone.Reset();
-
-                            // Start an asynchronous socket to listen for connections.
-                            Messenger.Default.Send(new SocketLogMessage() { Body = "Waiting for a connection..." });
-
-                            listener.BeginAccept(
-                                AcceptCallback,
-                                listener);
-
-                            // Wait until a connection is made before continuing.
-                            AllDone.WaitOne();
-                        }
-
-                        if (listener.Connected)
-                        {
-                            Messenger.Default.Send(new SocketLogMessage() { Body = "Shutting down listener..." });
-                            listener.Shutdown(SocketShutdown.Both);
-
-                            Messenger.Default.Send(new SocketLogMessage() { Body = "Disconnecting listener..." });
-                            listener.Disconnect(true);
-                        }
-
-                    }
-                    catch (Exception e)
-                    {
-                        Messenger.Default.Send(new SocketLogMessage() { Body = e.Message });
-                    }
-                    finally
-                    {
-                        Messenger.Default.Send(new SocketLogMessage() { Body = "Connection closed." });
-                    }
-            }
-        }
-
-        public void AcceptCallback(IAsyncResult ar)
-        {
-            // Signal the main thread to continue.
-            AllDone.Set();
-
-            // Get the socket that handles the client request.
-            var listener = (Socket) ar.AsyncState;
-            var handler = listener.EndAccept(ar);
-
-            // Create the state object.
-            var state = new StateObject {WorkSocket = handler};
-
-            handler.BeginReceive(
-                state.Buffer, 
-                0, 
-                StateObject.BufferSize, 
-                0,
-                ReadCallback, 
-                state);
-        }
-
-        public void ReadCallback(IAsyncResult ar)
-        {
-            var content = String.Empty;
-
-            // Retrieve the state object and the handler socket
-            // from the asynchronous state object.
-            var state = (StateObject)ar.AsyncState;
-            var handler = state.WorkSocket;
-
-            // Read data from the client socket. 
-            var bytesRead = handler.EndReceive(ar);
-
-            if (bytesRead <= 0) return;
-
-            // There  might be more data, so store the data received so far.
-            state.Sb.Append(
-                Encoding.ASCII.GetString(
-                    state.Buffer, 
-                    0, 
-                    bytesRead));
-
-            // Check for end-of-file tag. If it is not there, read 
-            // more data.
-            content = state.Sb.ToString();
-            if (content.IndexOf("<EOF>") > -1)
-            {
-                // All the data has been read from the 
-                // client. Display it on the console.
-
-                Messenger.Default.Send(
-                    new SocketLogMessage() 
-                    { 
-                        Body = string.Format(
-                            "Read {0} bytes from socket. \n Data : {1}",
-                            content.Length, 
-                            content)
-                    });
-                
-                // Echo the data back to the client.
-                Send(handler, "The following message was received: " + content);
-            }
-            else
-            {
-                // Not all data received. Get more.
-                handler.BeginReceive(
-                    state.Buffer, 
-                    0, 
-                    StateObject.BufferSize, 
-                    0,
-                    ReadCallback,
-                    state);
-            }
-        }
-
-        private void Send(Socket handler, String data)
-        {
-            // Convert the string data to byte data using ASCII encoding.
-            var byteData = Encoding.ASCII.GetBytes(data);
-
-            // Begin sending the data to the remote device.
-            handler.BeginSend(
-                byteData, 
-                0, 
-                byteData.Length, 
-                0,
-                SendCallback,
-                handler);
-        }
-
-        private void SendCallback(IAsyncResult ar)
-        {
-            try
-            {
-                // Retrieve the socket from the state object.
-                var handler = (Socket)ar.AsyncState;
-
-                // Complete sending the data to the remote device.
-                var bytesSent = handler.EndSend(ar);
-
-                Messenger.Default.Send(new SocketLogMessage() { Body = string.Format("Sent {0} bytes to client.", bytesSent) });
-
-                handler.Shutdown(SocketShutdown.Both);
-                handler.Close();
-            }
-            catch (Exception e)
-            {
-                Messenger.Default.Send(new SocketLogMessage() { Body = e.Message });
-            }
-        }
-
-        public void Stop()
-        {
-            if (IsListening == false) return;
-
-            Messenger.Default.Send(new SocketLogMessage() { Body = "Closing connection..." });
-            IsListening = false;
-            AllDone.Set();
-        }
-    }
-
-    // State object for reading client data asynchronously
-    public class StateObject
-    {
-        // Client  socket.
-        public Socket WorkSocket;
-
-        // Size of receive buffer.
-        public const int BufferSize = 1024;
-
-        // Receive buffer.
-        public byte[] Buffer = new byte[BufferSize];
-
-        // Received data string.
-        public StringBuilder Sb = new StringBuilder();
-    }
-}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Messaging/Server/Listeners/IListener.cs	Thu Mar 22 08:09:41 2012 +0000
@@ -0,0 +1,9 @@
+namespace Server.Listeners
+{
+    public interface IListener
+    {
+        bool IsListening { get; set; }
+        void Start();
+        void Stop();
+    }
+}
--- a/Messaging/Server/Listeners/MsmqListener.cs	Wed Mar 21 22:26:48 2012 +0000
+++ b/Messaging/Server/Listeners/MsmqListener.cs	Thu Mar 22 08:09:41 2012 +0000
@@ -2,7 +2,6 @@
 using System.Messaging;
 using Common.Messages;
 using GalaSoft.MvvmLight.Messaging;
-using Server.Interfaces;
 
 namespace Server.Listeners
 {
@@ -25,7 +24,7 @@
         {
             if (IsListening) return;
 
-            Messenger.Default.Send(new MsmqLogMessage() { Body = "Opening listener..." });
+            Messenger.Default.Send(new MsmqLogMessage() { Body = "Opening listener" });
             IsListening = true;
             while (IsListening)
             {
@@ -48,10 +47,9 @@
         public void Stop()
         {
             if (!IsListening) return;
-            Messenger.Default.Send(new MsmqLogMessage() { Body = "Closing listener..." });
             _mq.Close();
             IsListening = false;
-            Messenger.Default.Send(new MsmqLogMessage() { Body = "Closed." });
+            Messenger.Default.Send(new MsmqLogMessage() { Body = "Listener closed." });
         }
     }
 }
--- a/Messaging/Server/Listeners/RabbitQueueListener.cs	Wed Mar 21 22:26:48 2012 +0000
+++ b/Messaging/Server/Listeners/RabbitQueueListener.cs	Thu Mar 22 08:09:41 2012 +0000
@@ -6,7 +6,6 @@
 using RabbitMQ.Client;
 using RabbitMQ.Client.Events;
 using RabbitMQ.Client.MessagePatterns;
-using Server.Interfaces;
 
 namespace Server.Listeners
 {
@@ -37,11 +36,9 @@
                 {
                     using (var channel = connection.CreateModel())
                     {
-                        Log(string.Format("Creating a queue {0} and binding it to amq.direct", _queueName));
+                        Log("Opening listener");
                         string queueName = channel.QueueDeclare(_queueName, false, false, false, null);
-
                         channel.QueueBind(queueName, "amq.direct", queueName, null);
-                        Log("Done.");
 
                         using (_subscription = new Subscription(channel, queueName))
                         {
@@ -67,10 +64,10 @@
 
         public void Stop()
         {
-            Log("Closing listener...");
+            if (!IsListening) return;
             _subscription.Close();
             IsListening = false;
-            Log("Done.");
+            Log("Listener closed.");
         }
 
         private void Log(string message)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Messaging/Server/Listeners/ZeroMqListener.cs	Thu Mar 22 08:09:41 2012 +0000
@@ -0,0 +1,55 @@
+using System;
+using System.Text;
+using Common.Messages;
+using GalaSoft.MvvmLight.Messaging;
+
+namespace Server.Listeners
+{
+    public class ZeroMqListener : IListener
+    {
+        public bool IsListening { get; set; }
+        private readonly string _zeroMqAddress;
+        public ZeroMqListener(string zeroMqAddress)
+        {
+            _zeroMqAddress = zeroMqAddress;
+        }
+
+        public void Start()
+        {
+            if (IsListening) return;
+
+            Messenger.Default.Send(new ZeroMqLogMessage() { Body = "Opening listener" });
+            IsListening = true;
+            
+            try
+            {
+                using (var ctx = new ZMQ.Context(1))
+                {
+                    
+                    var socket = ctx.Socket(ZMQ.REP);
+                    socket.Bind(_zeroMqAddress);
+
+                    while (IsListening)
+                    {
+                        byte[] message;
+                        socket.Recv(out message);
+                        Messenger.Default.Send(new ZeroMqClientMessage());
+
+                        socket.Send(Encoding.ASCII.GetBytes(""));
+                    }
+                }
+            }
+            catch (Exception e)
+            {
+                Messenger.Default.Send(new ZeroMqLogMessage() { Body = e.Message });
+            }
+        }
+
+        public void Stop()
+        {
+            if (!IsListening) return;
+            IsListening = false;
+            Messenger.Default.Send(new ZeroMqLogMessage() { Body = "Listener closed." });
+        }
+    }
+}
--- a/Messaging/Server/Server.csproj	Wed Mar 21 22:26:48 2012 +0000
+++ b/Messaging/Server/Server.csproj	Thu Mar 22 08:09:41 2012 +0000
@@ -39,6 +39,9 @@
     <ApplicationIcon>UI\mail.ico</ApplicationIcon>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="clrzmq">
+      <HintPath>..\Libs\ZeroMq\clrzmq.dll</HintPath>
+    </Reference>
     <Reference Include="Elysium.Theme">
       <HintPath>..\Libs\Elysium.Theme.1.3\Elysium.Theme.dll</HintPath>
     </Reference>
@@ -81,8 +84,9 @@
       <SubType>Designer</SubType>
     </ApplicationDefinition>
     <Compile Include="Converters\ToggleButtonToTextConverter.cs" />
-    <Compile Include="Interfaces\IListener.cs" />
+    <Compile Include="Listeners\IListener.cs" />
     <Compile Include="Listeners\MsmqListener.cs" />
+    <Compile Include="Listeners\ZeroMqListener.cs" />
     <Compile Include="Locator.cs" />
     <Compile Include="Listeners\RabbitQueueListener.cs" />
     <Compile Include="UI\MainWindowViewModel.cs" />
@@ -95,7 +99,6 @@
       <DependentUpon>App.xaml</DependentUpon>
       <SubType>Code</SubType>
     </Compile>
-    <Compile Include="Listeners\AsyncSocketListener.cs" />
     <Compile Include="UI\MainWindow.xaml.cs">
       <DependentUpon>MainWindow.xaml</DependentUpon>
       <SubType>Code</SubType>
@@ -136,6 +139,9 @@
   </ItemGroup>
   <ItemGroup />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <PropertyGroup>
+    <PostBuildEvent>copy $(SolutionDir)Libs\zeromq\libzmq.dll $(TargetDir)</PostBuildEvent>
+  </PropertyGroup>
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.
   <Target Name="BeforeBuild">
--- a/Messaging/Server/UI/MainWindow.xaml	Wed Mar 21 22:26:48 2012 +0000
+++ b/Messaging/Server/UI/MainWindow.xaml	Thu Mar 22 08:09:41 2012 +0000
@@ -49,9 +49,9 @@
                 <ToggleButton Grid.Row="0"
                               Grid.Column="2"
                               Margin="10,10,10,0"
-                              Content="{Binding RabbitProtoEndPoint.IsListening,
+                              Content="{Binding ZeroMqEndPoint.IsListening,
                                                 Converter={converters:ToggleButtonToTextConverter}}"
-                              IsChecked="{Binding RabbitProtoEndPoint.IsListening}"
+                              IsChecked="{Binding ZeroMqEndPoint.IsListening}"
                               IsEnabled="True" />
 
                 <c:MessageTile Grid.Row="1"
@@ -77,11 +77,11 @@
                 <c:MessageTile Grid.Row="1"
                                Grid.Column="2"
                                Background="{StaticResource MetroOrangeBrush}"
-                               DisplayCount="{Binding RabbitProtoEndPoint.DisplayCount}"
+                               DisplayCount="{Binding ZeroMqEndPoint.DisplayCount}"
                                DisplayIcon="{StaticResource Mail}"
-                               DisplayText="{Binding RabbitProtoEndPoint.DisplayText}"
+                               DisplayText="{Binding ZeroMqEndPoint.DisplayText}"
                                Foreground="White"
-                               ToolTip="{Binding RabbitProtoEndPoint.ToolTip}" />
+                               ToolTip="{Binding ZeroMqEndPoint.ToolTip}" />
                 <ScrollViewer Grid.Row="2"
                               Grid.Column="0"
                               Xaml:XamlHelper.AutoScroll="{Binding MsmqEndPoint.IsLogChanged}">
@@ -102,13 +102,13 @@
                 </ScrollViewer>
                 <ScrollViewer Grid.Row="2"
                               Grid.Column="2"
-                              Xaml:XamlHelper.AutoScroll="{Binding RabbitProtoEndPoint.IsLogChanged}">
+                              Xaml:XamlHelper.AutoScroll="{Binding ZeroMqEndPoint.IsLogChanged}">
                     <TextBlock Grid.Row="2"
                                Grid.Column="2"
                                Margin="10"
                                Background="{StaticResource MetroGrayBrush}"
                                Padding="10"
-                               Text="{Binding RabbitProtoEndPoint.DisplayLog}"
+                               Text="{Binding ZeroMqEndPoint.DisplayLog}"
                                TextWrapping="WrapWithOverflow" />
                 </ScrollViewer>
                 <metro:ToggleSwitch Grid.Row="3"
--- a/Messaging/Server/UI/MainWindowViewModel.cs	Wed Mar 21 22:26:48 2012 +0000
+++ b/Messaging/Server/UI/MainWindowViewModel.cs	Thu Mar 22 08:09:41 2012 +0000
@@ -1,12 +1,11 @@
 using System.Windows.Input;
 using Common;
-using Common.Logger;
 using Common.Messages;
 using GalaSoft.MvvmLight;
 using GalaSoft.MvvmLight.Command;
 using System.Windows;
+using GalaSoft.MvvmLight.Messaging;
 using Server.EndPoints;
-using Server.Interfaces;
 using Server.Listeners;
 
 namespace Server.UI
@@ -25,9 +24,13 @@
             set
             {
                 if (_overrideSwitch == value) return;
-                var oldValue = _overrideSwitch;
                 _overrideSwitch = value;
-                RaisePropertyChanged(() => OverrideSwitch, oldValue, value, false);
+                RaisePropertyChanged(() => OverrideSwitch);
+                if (OverrideSwitch == null) return;
+
+                Messenger.Default.Send((bool) OverrideSwitch
+                    ? new OverrideSwitchMessage() {Switch = Switch.On}
+                    : new OverrideSwitchMessage() {Switch = Switch.Off});
             }
         }
 
@@ -38,18 +41,16 @@
         public ICommand CloseCommand { get; set; }
 
         public MessageEndPoint<MsmqClientMessage, MsmqLogMessage> MsmqEndPoint { get; set; }
-        public MessageEndPoint<SocketClientMessage, SocketLogMessage> SocketEndPoint { get; set; }
         public MessageEndPoint<RabbitClientMessage, RabbitLogMessage> RabbitEndPoint { get; set; }
-        public MessageEndPoint<RabbitProtoClientMessage, RabbitProtoLogMessage> RabbitProtoEndPoint { get; set; }
+        public MessageEndPoint<ZeroMqClientMessage, ZeroMqLogMessage> ZeroMqEndPoint { get; set; }
 
         #region Constructor
 
         public MainWindowViewModel()
         {
             InitMsmqEndPoint(Settings.MsmqQueueName);
-            //InitSocketEndPoint(Settings.SocketsPortNumber);
             InitRabbitEndPoint(Settings.RabbitPortNumber, Settings.RabbitQueueName);
-            InitRabbitProtoEndPoint(Settings.RabbitProtoPortNumber);
+            InitZeroMqEndPoint(Settings.ZeroMqAddress);
 
             CloseCommand = new RelayCommand(CloseCommandExecute);
         }
@@ -66,40 +67,29 @@
             };
         }
 
-        private void InitSocketEndPoint(int port)
-        {
-            IListener listener = new AsyncSocketListener(port);
-            SocketEndPoint = new MessageEndPoint<SocketClientMessage, SocketLogMessage>(listener)
-            {
-                DisplayText = "Async Sockets",
-                ToolTip = "Listening over TCP/IP on socket localhost:" + port
-            };
-        }
-
         private void InitRabbitEndPoint(int port, string queueName)
         {
             IListener listener = new RabbitQueueListener(port, queueName);
             RabbitEndPoint = new MessageEndPoint<RabbitClientMessage, RabbitLogMessage>(listener)
             {
                 DisplayText = "RabbitMQ",
-                ToolTip = "Listening..." + port
+                ToolTip = string.Format("Listening on port {0} to queue {1} and binding it to amq.direct", port, queueName)
             };
         }
 
-        private void InitRabbitProtoEndPoint(int port)
+        private void InitZeroMqEndPoint(string address)
         {
-            IListener listener = null;
-            RabbitProtoEndPoint = new MessageEndPoint<RabbitProtoClientMessage, RabbitProtoLogMessage>(listener)
+            IListener listener = new ZeroMqListener(address);
+            ZeroMqEndPoint = new MessageEndPoint<ZeroMqClientMessage, ZeroMqLogMessage>(listener)
             {
-                DisplayText = "RabbitMQ with Protobuf-net",
-                ToolTip = "Listening...." + port
+                DisplayText = "ZeroMq",
+                ToolTip = "Listening on " + address
             };
         }
 
         private void CloseCommandExecute()
         {
-            Log.Write("Closing command executed");
             Application.Current.Shutdown();
         }
     }
-}
+}
\ No newline at end of file