annotate Messaging/Client/MainWindow.xaml.cs @ 29:9919ee227c93

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