diff Messaging/Client/UI/MainWindow.xaml.cs @ 31:7d9de5746f18

Working version
author adminsh@apollo
date Thu, 22 Mar 2012 08:09:41 +0000
parents 8d574f2d4174
children 874e51b94623
line wrap: on
line diff
--- 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