annotate 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
rev   line source
30
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
1 using System;
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
2 using System.Messaging;
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
3 using System.Text;
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
4 using System.Threading.Tasks;
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
5 using System.Windows;
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
6 using Common;
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
7 using RabbitMQ.Client;
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
8
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
9 namespace Client.UI
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
10 {
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
11 /// <summary>
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
12 /// Interaction logic for MainWindow.xaml
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
13 /// </summary>
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
14 public partial class MainWindow
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
15 {
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
16 public const int MessageCount = 10000;
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
17
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
18 public MainWindow()
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
19 {
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
20 InitializeComponent();
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
21 }
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
22
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
23 private void BtnRabbitClick(object sender, RoutedEventArgs e)
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
24 {
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
25 Task.Factory.StartNew(() =>
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
26 {
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
27 var cf = new ConnectionFactory {Address = "localhost:" + Settings.RabbitPortNumber};
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
28
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
29 using (var conn = cf.CreateConnection())
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
30 using (var channel = conn.CreateModel())
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
31 {
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
32 for (var i = 0; i < MessageCount; i++)
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
33 {
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
34 channel.BasicPublish("amq.direct", Settings.RabbitQueueName, null,
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
35 Encoding.UTF8.GetBytes("hello from the client!"));
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
36 }
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
37 }
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
38 });
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
39 }
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
40
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
41 private void btnMsmq_Click(object sender, RoutedEventArgs e)
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
42 {
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
43 Task.Factory.StartNew(() =>
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
44 {
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
45 var msMq
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
46 = !MessageQueue.Exists(Settings.MsmqQueueName)
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
47 ? MessageQueue.Create(Settings.MsmqQueueName)
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
48 : new MessageQueue(Settings.MsmqQueueName);
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
49
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
50 try
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
51 {
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
52 for (var i = 0; i < MessageCount; i++)
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
53 {
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
54 msMq.Send("Sending data to MSMQ at " + DateTime.Now.ToString());
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
55 }
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
56 }
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
57 catch (MessageQueueException ee)
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
58 {
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
59 Console.Write(ee.ToString());
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
60 }
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
61 catch (Exception eee)
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
62 {
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
63 Console.Write(eee.ToString());
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
64 }
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
65 finally
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
66 {
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
67 msMq.Close();
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
68 }
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
69 });
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
70 }
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
71
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
72 private void btnZeroMq_Click(object sender, RoutedEventArgs e)
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
73 {
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
74
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
75 }
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
76
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
77 private void btnSockets_Click(object sender, RoutedEventArgs e)
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
78 {
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
79
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
80 }
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
81 }
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
82 }