comparison 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
comparison
equal deleted inserted replaced
29:9919ee227c93 30:8d574f2d4174
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(() =>
26 {
27 var cf = new ConnectionFactory {Address = "localhost:" + Settings.RabbitPortNumber};
28
29 using (var conn = cf.CreateConnection())
30 using (var channel = conn.CreateModel())
31 {
32 for (var i = 0; i < MessageCount; i++)
33 {
34 channel.BasicPublish("amq.direct", Settings.RabbitQueueName, null,
35 Encoding.UTF8.GetBytes("hello from the client!"));
36 }
37 }
38 });
39 }
40
41 private void btnMsmq_Click(object sender, RoutedEventArgs e)
42 {
43 Task.Factory.StartNew(() =>
44 {
45 var msMq
46 = !MessageQueue.Exists(Settings.MsmqQueueName)
47 ? MessageQueue.Create(Settings.MsmqQueueName)
48 : new MessageQueue(Settings.MsmqQueueName);
49
50 try
51 {
52 for (var i = 0; i < MessageCount; i++)
53 {
54 msMq.Send("Sending data to MSMQ at " + DateTime.Now.ToString());
55 }
56 }
57 catch (MessageQueueException ee)
58 {
59 Console.Write(ee.ToString());
60 }
61 catch (Exception eee)
62 {
63 Console.Write(eee.ToString());
64 }
65 finally
66 {
67 msMq.Close();
68 }
69 });
70 }
71
72 private void btnZeroMq_Click(object sender, RoutedEventArgs e)
73 {
74
75 }
76
77 private void btnSockets_Click(object sender, RoutedEventArgs e)
78 {
79
80 }
81 }
82 }