annotate 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
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(() =>
31
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
26 {
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
27 var cf = new ConnectionFactory
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
28 {Address = "localhost:" + Settings.RabbitPortNumber};
30
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
29
31
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
30 using (var conn = cf.CreateConnection())
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
31 using (var channel = conn.CreateModel())
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
32 {
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
33 for (var i = 0; i < MessageCount; i++)
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
34 {
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
35 channel.BasicPublish("amq.direct", Settings.RabbitQueueName, null,
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
36 Encoding.UTF8.GetBytes("hello from the client!"));
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
37 }
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
38 }
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
39 });
30
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
40 }
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
41
31
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
42 private void BtnMsmqClick(object sender, RoutedEventArgs e)
30
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
43 {
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
44 Task.Factory.StartNew(() =>
31
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
45 {
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
46 var msMq
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
47 = !MessageQueue.Exists(Settings.MsmqQueueName)
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
48 ? MessageQueue.Create(Settings.MsmqQueueName)
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
49 : new MessageQueue(Settings.MsmqQueueName);
30
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
50
31
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
51 try
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
52 {
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
53 for (var i = 0; i < MessageCount; i++)
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
54 {
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
55 msMq.Send("Sending data to MSMQ at " + DateTime.Now.ToString());
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
56 }
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
57 }
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
58 catch (MessageQueueException ee)
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
59 {
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
60 Console.Write(ee.ToString());
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
61 }
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
62 catch (Exception eee)
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
63 {
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
64 Console.Write(eee.ToString());
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
65 }
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
66 finally
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
67 {
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
68 msMq.Close();
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
69 }
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
70 });
30
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
71 }
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
72
31
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
73 private void BtnZeroMqClick(object sender, RoutedEventArgs e)
30
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
74 {
31
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
75 Task.Factory.StartNew(() =>
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
76 {
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
77 using (var ctx = new ZMQ.Context(1))
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
78 {
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
79 var socket = ctx.Socket(ZMQ.REQ);
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
80 socket.Connect("tcp://localhost:5555");
30
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
81
31
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
82 for (var i = 0; i < MessageCount; i++)
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
83 {
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
84 socket.Send(Encoding.ASCII.GetBytes("Hello"));
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
85
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
86 byte[] message;
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
87 socket.Recv(out message);
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
88 }
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
89 }
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
90 });
30
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
91 }
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
92
31
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
93 private void BtnSendAllClick(object sender, RoutedEventArgs e)
30
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
94 {
31
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
95 Task.Factory.StartNew(() => BtnMsmqClick(this, null));
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
96 Task.Factory.StartNew(() => BtnRabbitClick(this, null));
7d9de5746f18 Working version
adminsh@apollo
parents: 30
diff changeset
97 Task.Factory.StartNew(() => BtnZeroMqClick(this, null));
30
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
98 }
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
99 }
8d574f2d4174 Cleaned up client
adminsh@apollo
parents:
diff changeset
100 }