Mercurial > silverbladetech
annotate Messaging/Client/UI/MainWindow.xaml.cs @ 97:1adc1ae981ea
Tests added to SilverlightValidation.Tests
author | stevenhollidge <stevenhollidge@hotmail.com> |
---|---|
date | Sat, 05 May 2012 16:39:00 +0100 |
parents | 874e51b94623 |
children |
rev | line source |
---|---|
30 | 1 using System; |
2 using System.Messaging; | |
3 using System.Text; | |
4 using System.Threading.Tasks; | |
5 using System.Windows; | |
6 using Common; | |
7 using RabbitMQ.Client; | |
8 | |
9 namespace Client.UI | |
10 { | |
11 /// <summary> | |
12 /// Interaction logic for MainWindow.xaml | |
13 /// </summary> | |
14 public partial class MainWindow | |
15 { | |
16 public const int MessageCount = 10000; | |
17 | |
18 public MainWindow() | |
19 { | |
20 InitializeComponent(); | |
21 } | |
22 | |
23 private void BtnRabbitClick(object sender, RoutedEventArgs e) | |
24 { | |
25 Task.Factory.StartNew(() => | |
31 | 26 { |
27 var cf = new ConnectionFactory | |
28 {Address = "localhost:" + Settings.RabbitPortNumber}; | |
30 | 29 |
31 | 30 using (var conn = cf.CreateConnection()) |
31 using (var channel = conn.CreateModel()) | |
32 { | |
33 for (var i = 0; i < MessageCount; i++) | |
34 { | |
35 channel.BasicPublish("amq.direct", Settings.RabbitQueueName, null, | |
36 Encoding.UTF8.GetBytes("hello from the client!")); | |
37 } | |
38 } | |
39 }); | |
30 | 40 } |
41 | |
31 | 42 private void BtnMsmqClick(object sender, RoutedEventArgs e) |
30 | 43 { |
44 Task.Factory.StartNew(() => | |
31 | 45 { |
46 var msMq | |
47 = !MessageQueue.Exists(Settings.MsmqQueueName) | |
48 ? MessageQueue.Create(Settings.MsmqQueueName) | |
49 : new MessageQueue(Settings.MsmqQueueName); | |
30 | 50 |
31 | 51 try |
52 { | |
53 for (var i = 0; i < MessageCount; i++) | |
54 { | |
55 msMq.Send("Sending data to MSMQ at " + DateTime.Now.ToString()); | |
56 } | |
57 } | |
58 catch (MessageQueueException ee) | |
59 { | |
60 Console.Write(ee.ToString()); | |
61 } | |
62 catch (Exception eee) | |
63 { | |
64 Console.Write(eee.ToString()); | |
65 } | |
66 finally | |
67 { | |
68 msMq.Close(); | |
69 } | |
70 }); | |
30 | 71 } |
72 | |
31 | 73 private void BtnZeroMqClick(object sender, RoutedEventArgs e) |
30 | 74 { |
31 | 75 Task.Factory.StartNew(() => |
76 { | |
77 using (var ctx = new ZMQ.Context(1)) | |
78 { | |
79 var socket = ctx.Socket(ZMQ.REQ); | |
34
874e51b94623
ZeroMq uses different style of address for client and server
adminsh@apollo
parents:
31
diff
changeset
|
80 socket.Connect(Settings.ZeroMqClientAddress); |
30 | 81 |
31 | 82 for (var i = 0; i < MessageCount; i++) |
83 { | |
84 socket.Send(Encoding.ASCII.GetBytes("Hello")); | |
85 | |
86 byte[] message; | |
87 socket.Recv(out message); | |
88 } | |
89 } | |
90 }); | |
30 | 91 } |
92 | |
31 | 93 private void BtnSendAllClick(object sender, RoutedEventArgs e) |
30 | 94 { |
31 | 95 Task.Factory.StartNew(() => BtnMsmqClick(this, null)); |
96 Task.Factory.StartNew(() => BtnRabbitClick(this, null)); | |
97 Task.Factory.StartNew(() => BtnZeroMqClick(this, null)); | |
30 | 98 } |
99 } | |
100 } |