diff Messaging/Client/UI/MainWindow.xaml.cs @ 30:8d574f2d4174

Cleaned up client
author adminsh@apollo
date Wed, 21 Mar 2012 22:26:48 +0000
parents
children 7d9de5746f18
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Messaging/Client/UI/MainWindow.xaml.cs	Wed Mar 21 22:26:48 2012 +0000
@@ -0,0 +1,82 @@
+using System;
+using System.Messaging;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using Common;
+using RabbitMQ.Client;
+
+namespace Client.UI
+{
+    /// <summary>
+    /// Interaction logic for MainWindow.xaml
+    /// </summary>
+    public partial class MainWindow
+    {
+        public const int MessageCount = 10000;
+
+        public MainWindow()
+        {
+            InitializeComponent();
+        }
+
+        private void BtnRabbitClick(object sender, RoutedEventArgs e)
+        {
+            Task.Factory.StartNew(() =>
+            {
+                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!"));
+                    }
+                }
+            });
+        }
+
+        private void btnMsmq_Click(object sender, RoutedEventArgs e)
+        {
+            Task.Factory.StartNew(() =>
+            {
+                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();
+                }
+            });
+        }
+
+        private void btnZeroMq_Click(object sender, RoutedEventArgs e)
+        {
+
+        }
+
+        private void btnSockets_Click(object sender, RoutedEventArgs e)
+        {
+
+        }
+    }
+}
\ No newline at end of file