1 using System;
2 using System.Drawing;
3 using System.Collections;
4 using System.ComponentModel;
5 using System.Windows.Forms;
6 using System.Data;
7 using System.Runtime.InteropServices; // DllImport pour autoscroll du richtextbox
8 using System.Threading ;
9 using System.Text ;
10
11 using XmlBlasterLib ;
12 using SimpleLogLib ;
13
14 namespace XmlBlasterMessagesManager
15 {
16 /// <summary>
17 /// Description résumée de XmlBlasterMessagesManagerFrm.
18 /// </summary>
19 public class XmlBlasterMessagesManagerFrm : System.Windows.Forms.Form
20 {
21 #region Code généré par le Concepteur Windows Form
22
23 private System.Windows.Forms.GroupBox groupBox1;
24 private System.Windows.Forms.Button connect;
25 private System.Windows.Forms.Label label3;
26 private System.Windows.Forms.TextBox password;
27 private System.Windows.Forms.Label label2;
28 private System.Windows.Forms.Label label1;
29 private System.Windows.Forms.TextBox server;
30 private System.Windows.Forms.TextBox user;
31 private System.Windows.Forms.Button getMessages;
32 private System.Windows.Forms.TreeView messages;
33 private System.Windows.Forms.GroupBox groupBox2;
34 private System.Windows.Forms.GroupBox groupBox3;
35 private System.Windows.Forms.Label label4;
36 private System.Windows.Forms.Label label5;
37 private System.Windows.Forms.Label label6;
38 private System.Windows.Forms.TextBox msgsend_key;
39 private System.Windows.Forms.TextBox msgsend_qos;
40 private System.Windows.Forms.TextBox msgsend_content;
41 private System.Windows.Forms.Button msgsend_send;
42 private System.Windows.Forms.Button msgsend_clear;
43 private System.Windows.Forms.Label label8;
44 private System.Windows.Forms.Label label9;
45 private System.Windows.Forms.TextBox msgview_key;
46 private System.Windows.Forms.TextBox msgview_qos;
47 private System.Windows.Forms.TextBox msgview_content;
48 private System.Windows.Forms.Button msgsend_sendTo;
49 private System.Windows.Forms.Button msgsend_copySelected;
50 private System.Windows.Forms.RichTextBox report;
51 private System.Windows.Forms.ListBox users;
52 private System.Windows.Forms.ToolTip message_toolTip;
53 private System.Windows.Forms.Panel connectStatusLed;
54 private System.Windows.Forms.Timer connectStatusTimer;
55 private System.Windows.Forms.Button msgview_erase;
56 private System.ComponentModel.IContainer components;
57
58 /// <summary>
59 /// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
60 /// le contenu de cette méthode avec l'éditeur de code.
61 /// </summary>
62 private void InitializeComponent()
63 {
64 this.components = new System.ComponentModel.Container();
65 this.groupBox1 = new System.Windows.Forms.GroupBox();
66 this.connect = new System.Windows.Forms.Button();
67 this.server = new System.Windows.Forms.TextBox();
68 this.label3 = new System.Windows.Forms.Label();
69 this.password = new System.Windows.Forms.TextBox();
70 this.label2 = new System.Windows.Forms.Label();
71 this.user = new System.Windows.Forms.TextBox();
72 this.label1 = new System.Windows.Forms.Label();
73 this.messages = new System.Windows.Forms.TreeView();
74 this.getMessages = new System.Windows.Forms.Button();
75 this.groupBox2 = new System.Windows.Forms.GroupBox();
76 this.msgview_content = new System.Windows.Forms.TextBox();
77 this.msgview_qos = new System.Windows.Forms.TextBox();
78 this.msgview_key = new System.Windows.Forms.TextBox();
79 this.label8 = new System.Windows.Forms.Label();
80 this.label9 = new System.Windows.Forms.Label();
81 this.groupBox3 = new System.Windows.Forms.GroupBox();
82 this.msgsend_copySelected = new System.Windows.Forms.Button();
83 this.msgsend_sendTo = new System.Windows.Forms.Button();
84 this.users = new System.Windows.Forms.ListBox();
85 this.msgsend_clear = new System.Windows.Forms.Button();
86 this.msgsend_send = new System.Windows.Forms.Button();
87 this.msgsend_content = new System.Windows.Forms.TextBox();
88 this.msgsend_qos = new System.Windows.Forms.TextBox();
89 this.msgsend_key = new System.Windows.Forms.TextBox();
90 this.label6 = new System.Windows.Forms.Label();
91 this.label5 = new System.Windows.Forms.Label();
92 this.label4 = new System.Windows.Forms.Label();
93 this.report = new System.Windows.Forms.RichTextBox();
94 this.message_toolTip = new System.Windows.Forms.ToolTip(this.components);
95 this.connectStatusLed = new System.Windows.Forms.Panel();
96 this.connectStatusTimer = new System.Windows.Forms.Timer(this.components);
97 this.msgview_erase = new System.Windows.Forms.Button();
98 this.groupBox1.SuspendLayout();
99 this.groupBox2.SuspendLayout();
100 this.groupBox3.SuspendLayout();
101 this.SuspendLayout();
102 //
103 // groupBox1
104 //
105 this.groupBox1.Controls.Add(this.connectStatusLed);
106 this.groupBox1.Controls.Add(this.connect);
107 this.groupBox1.Controls.Add(this.server);
108 this.groupBox1.Controls.Add(this.label3);
109 this.groupBox1.Controls.Add(this.password);
110 this.groupBox1.Controls.Add(this.label2);
111 this.groupBox1.Controls.Add(this.user);
112 this.groupBox1.Controls.Add(this.label1);
113 this.groupBox1.Location = new System.Drawing.Point(8, 4);
114 this.groupBox1.Name = "groupBox1";
115 this.groupBox1.Size = new System.Drawing.Size(548, 40);
116 this.groupBox1.TabIndex = 2;
117 this.groupBox1.TabStop = false;
118 //
119 // connect
120 //
121 this.connect.Location = new System.Drawing.Point(404, 12);
122 this.connect.Name = "connect";
123 this.connect.Size = new System.Drawing.Size(84, 20);
124 this.connect.TabIndex = 6;
125 this.connect.Text = "Connect";
126 this.connect.Click += new System.EventHandler(this.connect_Click);
127 //
128 // server
129 //
130 this.server.Location = new System.Drawing.Point(44, 12);
131 this.server.Name = "server";
132 this.server.Size = new System.Drawing.Size(84, 20);
133 this.server.TabIndex = 5;
134 this.server.Text = "127.0.0.1";
135 //
136 // label3
137 //
138 this.label3.AutoSize = true;
139 this.label3.Location = new System.Drawing.Point(8, 16);
140 this.label3.Name = "label3";
141 this.label3.Size = new System.Drawing.Size(36, 16);
142 this.label3.TabIndex = 4;
143 this.label3.Text = "server";
144 //
145 // password
146 //
147 this.password.Location = new System.Drawing.Point(308, 12);
148 this.password.Name = "password";
149 this.password.Size = new System.Drawing.Size(84, 20);
150 this.password.TabIndex = 3;
151 this.password.Text = "guest";
152 //
153 // label2
154 //
155 this.label2.AutoSize = true;
156 this.label2.Location = new System.Drawing.Point(256, 16);
157 this.label2.Name = "label2";
158 this.label2.Size = new System.Drawing.Size(53, 16);
159 this.label2.TabIndex = 2;
160 this.label2.Text = "password";
161 //
162 // user
163 //
164 this.user.Location = new System.Drawing.Point(164, 12);
165 this.user.Name = "user";
166 this.user.Size = new System.Drawing.Size(84, 20);
167 this.user.TabIndex = 1;
168 this.user.Text = "xbmMsgMng";
169 //
170 // label1
171 //
172 this.label1.AutoSize = true;
173 this.label1.Location = new System.Drawing.Point(136, 16);
174 this.label1.Name = "label1";
175 this.label1.Size = new System.Drawing.Size(26, 16);
176 this.label1.TabIndex = 0;
177 this.label1.Text = "user";
178 //
179 // messages
180 //
181 this.messages.HideSelection = false;
182 this.messages.ImageIndex = -1;
183 this.messages.Location = new System.Drawing.Point(8, 56);
184 this.messages.Name = "messages";
185 this.messages.SelectedImageIndex = -1;
186 this.messages.Size = new System.Drawing.Size(216, 172);
187 this.messages.TabIndex = 3;
188 this.messages.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.messages_AfterSelect);
189 //
190 // getMessages
191 //
192 this.getMessages.Location = new System.Drawing.Point(64, 236);
193 this.getMessages.Name = "getMessages";
194 this.getMessages.Size = new System.Drawing.Size(112, 24);
195 this.getMessages.TabIndex = 4;
196 this.getMessages.Text = "Get Messages";
197 this.getMessages.Click += new System.EventHandler(this.getMessages_Click);
198 //
199 // groupBox2
200 //
201 this.groupBox2.Controls.Add(this.msgview_erase);
202 this.groupBox2.Controls.Add(this.msgview_content);
203 this.groupBox2.Controls.Add(this.msgview_qos);
204 this.groupBox2.Controls.Add(this.msgview_key);
205 this.groupBox2.Controls.Add(this.label8);
206 this.groupBox2.Controls.Add(this.label9);
207 this.groupBox2.Location = new System.Drawing.Point(228, 48);
208 this.groupBox2.Name = "groupBox2";
209 this.groupBox2.Size = new System.Drawing.Size(328, 228);
210 this.groupBox2.TabIndex = 5;
211 this.groupBox2.TabStop = false;
212 this.groupBox2.Text = " selected message ";
213 //
214 // msgview_content
215 //
216 this.msgview_content.AcceptsReturn = true;
217 this.msgview_content.AcceptsTab = true;
218 this.msgview_content.Location = new System.Drawing.Point(8, 104);
219 this.msgview_content.Multiline = true;
220 this.msgview_content.Name = "msgview_content";
221 this.msgview_content.ReadOnly = true;
222 this.msgview_content.ScrollBars = System.Windows.Forms.ScrollBars.Both;
223 this.msgview_content.Size = new System.Drawing.Size(312, 88);
224 this.msgview_content.TabIndex = 8;
225 this.msgview_content.Text = "msgview_content";
226 //
227 // msgview_qos
228 //
229 this.msgview_qos.AcceptsReturn = true;
230 this.msgview_qos.AcceptsTab = true;
231 this.msgview_qos.Location = new System.Drawing.Point(32, 52);
232 this.msgview_qos.Multiline = true;
233 this.msgview_qos.Name = "msgview_qos";
234 this.msgview_qos.ReadOnly = true;
235 this.msgview_qos.ScrollBars = System.Windows.Forms.ScrollBars.Both;
236 this.msgview_qos.Size = new System.Drawing.Size(288, 48);
237 this.msgview_qos.TabIndex = 7;
238 this.msgview_qos.Text = "msgview_qos";
239 //
240 // msgview_key
241 //
242 this.msgview_key.AcceptsReturn = true;
243 this.msgview_key.AcceptsTab = true;
244 this.msgview_key.Location = new System.Drawing.Point(32, 16);
245 this.msgview_key.Multiline = true;
246 this.msgview_key.Name = "msgview_key";
247 this.msgview_key.ReadOnly = true;
248 this.msgview_key.ScrollBars = System.Windows.Forms.ScrollBars.Both;
249 this.msgview_key.Size = new System.Drawing.Size(288, 32);
250 this.msgview_key.TabIndex = 6;
251 this.msgview_key.Text = "msgview_key";
252 this.message_toolTip.SetToolTip(this.msgview_key, "coucou");
253 //
254 // label8
255 //
256 this.label8.AutoSize = true;
257 this.label8.Location = new System.Drawing.Point(8, 52);
258 this.label8.Name = "label8";
259 this.label8.Size = new System.Drawing.Size(22, 16);
260 this.label8.TabIndex = 4;
261 this.label8.Text = "qos";
262 //
263 // label9
264 //
265 this.label9.AutoSize = true;
266 this.label9.Location = new System.Drawing.Point(8, 16);
267 this.label9.Name = "label9";
268 this.label9.Size = new System.Drawing.Size(22, 16);
269 this.label9.TabIndex = 3;
270 this.label9.Text = "key";
271 //
272 // groupBox3
273 //
274 this.groupBox3.Controls.Add(this.msgsend_copySelected);
275 this.groupBox3.Controls.Add(this.msgsend_sendTo);
276 this.groupBox3.Controls.Add(this.users);
277 this.groupBox3.Controls.Add(this.msgsend_clear);
278 this.groupBox3.Controls.Add(this.msgsend_send);
279 this.groupBox3.Controls.Add(this.msgsend_content);
280 this.groupBox3.Controls.Add(this.msgsend_qos);
281 this.groupBox3.Controls.Add(this.msgsend_key);
282 this.groupBox3.Controls.Add(this.label6);
283 this.groupBox3.Controls.Add(this.label5);
284 this.groupBox3.Controls.Add(this.label4);
285 this.groupBox3.Location = new System.Drawing.Point(4, 276);
286 this.groupBox3.Name = "groupBox3";
287 this.groupBox3.Size = new System.Drawing.Size(552, 220);
288 this.groupBox3.TabIndex = 6;
289 this.groupBox3.TabStop = false;
290 this.groupBox3.Text = " send a message ";
291 //
292 // msgsend_copySelected
293 //
294 this.msgsend_copySelected.Location = new System.Drawing.Point(100, 188);
295 this.msgsend_copySelected.Name = "msgsend_copySelected";
296 this.msgsend_copySelected.Size = new System.Drawing.Size(96, 24);
297 this.msgsend_copySelected.TabIndex = 10;
298 this.msgsend_copySelected.Text = "Copy Selected";
299 this.msgsend_copySelected.Click += new System.EventHandler(this.msgsend_copySelected_Click);
300 //
301 // msgsend_sendTo
302 //
303 this.msgsend_sendTo.Location = new System.Drawing.Point(452, 188);
304 this.msgsend_sendTo.Name = "msgsend_sendTo";
305 this.msgsend_sendTo.Size = new System.Drawing.Size(68, 24);
306 this.msgsend_sendTo.TabIndex = 9;
307 this.msgsend_sendTo.Text = "Send To";
308 //
309 // users
310 //
311 this.users.Location = new System.Drawing.Point(436, 20);
312 this.users.Name = "users";
313 this.users.Size = new System.Drawing.Size(104, 160);
314 this.users.TabIndex = 8;
315 //
316 // msgsend_clear
317 //
318 this.msgsend_clear.Location = new System.Drawing.Point(204, 188);
319 this.msgsend_clear.Name = "msgsend_clear";
320 this.msgsend_clear.Size = new System.Drawing.Size(68, 24);
321 this.msgsend_clear.TabIndex = 7;
322 this.msgsend_clear.Text = "Clear";
323 //
324 // msgsend_send
325 //
326 this.msgsend_send.Location = new System.Drawing.Point(360, 188);
327 this.msgsend_send.Name = "msgsend_send";
328 this.msgsend_send.Size = new System.Drawing.Size(68, 24);
329 this.msgsend_send.TabIndex = 6;
330 this.msgsend_send.Text = "Send";
331 this.msgsend_send.Click += new System.EventHandler(this.msgsend_send_Click);
332 //
333 // msgsend_content
334 //
335 this.msgsend_content.AcceptsReturn = true;
336 this.msgsend_content.AcceptsTab = true;
337 this.msgsend_content.Location = new System.Drawing.Point(8, 92);
338 this.msgsend_content.Multiline = true;
339 this.msgsend_content.Name = "msgsend_content";
340 this.msgsend_content.ScrollBars = System.Windows.Forms.ScrollBars.Both;
341 this.msgsend_content.Size = new System.Drawing.Size(420, 88);
342 this.msgsend_content.TabIndex = 5;
343 this.msgsend_content.Text = "msgsend_content";
344 //
345 // msgsend_qos
346 //
347 this.msgsend_qos.AcceptsReturn = true;
348 this.msgsend_qos.AcceptsTab = true;
349 this.msgsend_qos.Location = new System.Drawing.Point(56, 56);
350 this.msgsend_qos.Multiline = true;
351 this.msgsend_qos.Name = "msgsend_qos";
352 this.msgsend_qos.ScrollBars = System.Windows.Forms.ScrollBars.Both;
353 this.msgsend_qos.Size = new System.Drawing.Size(372, 32);
354 this.msgsend_qos.TabIndex = 4;
355 this.msgsend_qos.Text = "msgsend_qos";
356 //
357 // msgsend_key
358 //
359 this.msgsend_key.AcceptsReturn = true;
360 this.msgsend_key.AcceptsTab = true;
361 this.msgsend_key.Location = new System.Drawing.Point(56, 20);
362 this.msgsend_key.Multiline = true;
363 this.msgsend_key.Name = "msgsend_key";
364 this.msgsend_key.ScrollBars = System.Windows.Forms.ScrollBars.Both;
365 this.msgsend_key.Size = new System.Drawing.Size(372, 32);
366 this.msgsend_key.TabIndex = 3;
367 this.msgsend_key.Text = "msgsend_key";
368 //
369 // label6
370 //
371 this.label6.AutoSize = true;
372 this.label6.Location = new System.Drawing.Point(8, 76);
373 this.label6.Name = "label6";
374 this.label6.Size = new System.Drawing.Size(41, 16);
375 this.label6.TabIndex = 2;
376 this.label6.Text = "content";
377 //
378 // label5
379 //
380 this.label5.AutoSize = true;
381 this.label5.Location = new System.Drawing.Point(28, 56);
382 this.label5.Name = "label5";
383 this.label5.Size = new System.Drawing.Size(22, 16);
384 this.label5.TabIndex = 1;
385 this.label5.Text = "qos";
386 //
387 // label4
388 //
389 this.label4.AutoSize = true;
390 this.label4.Location = new System.Drawing.Point(28, 20);
391 this.label4.Name = "label4";
392 this.label4.Size = new System.Drawing.Size(22, 16);
393 this.label4.TabIndex = 0;
394 this.label4.Text = "key";
395 //
396 // report
397 //
398 this.report.CausesValidation = false;
399 this.report.DetectUrls = false;
400 this.report.Dock = System.Windows.Forms.DockStyle.Bottom;
401 this.report.Location = new System.Drawing.Point(0, 501);
402 this.report.Name = "report";
403 this.report.ReadOnly = true;
404 this.report.Size = new System.Drawing.Size(560, 52);
405 this.report.TabIndex = 7;
406 this.report.Text = "report";
407 this.report.WordWrap = false;
408 //
409 // message_toolTip
410 //
411 this.message_toolTip.ShowAlways = true;
412 //
413 // connectStatusLed
414 //
415 this.connectStatusLed.BackColor = System.Drawing.Color.Red;
416 this.connectStatusLed.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
417 this.connectStatusLed.CausesValidation = false;
418 this.connectStatusLed.Cursor = System.Windows.Forms.Cursors.WaitCursor;
419 this.connectStatusLed.ForeColor = System.Drawing.Color.Black;
420 this.connectStatusLed.Location = new System.Drawing.Point(504, 16);
421 this.connectStatusLed.Name = "connectStatusLed";
422 this.connectStatusLed.Size = new System.Drawing.Size(24, 12);
423 this.connectStatusLed.TabIndex = 7;
424 this.message_toolTip.SetToolTip(this.connectStatusLed, "connection LED");
425 //
426 // connectStatusTimer
427 //
428 this.connectStatusTimer.Enabled = true;
429 this.connectStatusTimer.Interval = 2000;
430 this.connectStatusTimer.Tick += new System.EventHandler(this.connectStatusTimer_Tick);
431 //
432 // msgview_erase
433 //
434 this.msgview_erase.Location = new System.Drawing.Point(120, 196);
435 this.msgview_erase.Name = "msgview_erase";
436 this.msgview_erase.Size = new System.Drawing.Size(72, 24);
437 this.msgview_erase.TabIndex = 9;
438 this.msgview_erase.Text = "Erase";
439 this.msgview_erase.Click += new System.EventHandler(this.msgview_erase_Click);
440 //
441 // XmlBlasterMessagesManagerFrm
442 //
443 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
444 this.ClientSize = new System.Drawing.Size(560, 553);
445 this.Controls.Add(this.report);
446 this.Controls.Add(this.groupBox3);
447 this.Controls.Add(this.groupBox2);
448 this.Controls.Add(this.getMessages);
449 this.Controls.Add(this.messages);
450 this.Controls.Add(this.groupBox1);
451 this.Name = "XmlBlasterMessagesManagerFrm";
452 this.Text = "XmlBlaster Messages Manager";
453 this.Closing += new System.ComponentModel.CancelEventHandler(this.XmlBlasterMessagesManagerFrm_Closing);
454 this.Load += new System.EventHandler(this.XmlBlasterMessagesManagerFrm_Load);
455 this.groupBox1.ResumeLayout(false);
456 this.groupBox2.ResumeLayout(false);
457 this.groupBox3.ResumeLayout(false);
458 this.ResumeLayout(false);
459
460 }
461 #endregion
462
463 [STAThread]
464 static void Main()
465 {
466 Application.Run(new XmlBlasterMessagesManagerFrm());
467 }
468
469 static readonly string CRLF = Environment.NewLine ;
470 static readonly string cr = new string( '\r', 1 );
471 static readonly string lf = new string( '\n', 1 );
472 static readonly string crlf = new string( new char[] {'\r','\n'} );
473
474 static SimpleLog logger = SimpleLogManager.GetLog( "Frm", LogLevel.Debug );
475
476 XmlBlasterClient xmlBlaster ;
477 int xmlBlaster_port = 8080 ;
478
479 #region richtextbox print error
480
481 [DllImport("user32.dll", EntryPoint="SendMessageA")]
482 static extern uint SendMessage(System.IntPtr hwnd, uint wMsg, uint wParam, uint lParam);
483 private const int WM_VSCROLL = 0x115;
484 private const int SB_BOTTOM = 7;
485
486 public void PrintReport( string msg )
487 {
488 this.report.AppendText( msg + CRLF );
489 }
490
491 /// <summary>
492 /// Imprime un message d'erreur.
493 /// La mise en couleur fonctionne qu'après un 1er AppendText (voir le Form Load)
494 /// Et le scroll auto, faut il vraiment faire l'import et le send message ???
495 /// </summary>
496 /// <param name="msg"></param>
497 public void PrintError( string msg )
498 {
499 // Change some text properties
500
501 Color fc = this.report.SelectionColor ;
502 Font currentFont = this.report.SelectionFont ;
503 FontStyle newFontStyle;
504 newFontStyle = FontStyle.Bold;
505 this.report.SelectionColor = Color.Red ;
506 this.report.SelectionFont = new Font(
507 currentFont.FontFamily,
508 currentFont.Size,
509 newFontStyle
510 );
511
512 this.report.AppendText( "[ERROR] " );
513
514 // restore text properties
515 this.report.SelectionColor = fc ;
516 this.report.SelectionFont = currentFont ;
517
518 this.report.AppendText( msg + CRLF );
519
520 // auto scroll
521 SendMessage(this.report.Handle, WM_VSCROLL, SB_BOTTOM, 0);
522 }
523
524 #endregion
525
526 public XmlBlasterMessagesManagerFrm()
527 {
528 //
529 // Requis pour la prise en charge du Concepteur Windows Forms
530 //
531 InitializeComponent();
532
533 }
534
535 private void XmlBlasterMessagesManagerFrm_Load(object sender, System.EventArgs e)
536 {
537 logger.errorCallback += new SimpleLogLib.SimpleLog.ErrorCallbackDelegate( this.PrintError );
538
539 report.Text = "" ;
540 report.AppendText( System.Windows.Forms.Application.ProductName
541 + " " + System.Windows.Forms.Application.ProductVersion
542 + CRLF );
543
544 this.msgsend_key.Text = "";
545 this.msgview_key.Text ="";
546 this.msgsend_qos.Text = "";
547 this.msgview_qos.Text ="";
548 this.msgsend_content.Text = "";
549 this.msgview_content.Text ="";
550 this.messages.Nodes.Clear();
551 this.users.Items.Clear();
552
553 this.messagesFillDelegate += new MessagesFillDelegate(this.messagesFill);
554 }
555
556
557 protected override void Dispose( bool disposing )
558 {
559 if( disposing )
560 {
561 if (components != null)
562 {
563 components.Dispose();
564 }
565 }
566 base.Dispose( disposing );
567 }
568
569 private void XmlBlasterMessagesManagerFrm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
570 {
571 try
572 {
573 this.xmlBlaster.Disconnect();
574 }
575 catch(Exception ex)
576 {
577 logger.Error("Failed to Disconnect. Ex: "+ex.Message );
578 }
579 }
580
581
582 public void OnMessageArrived( XmlBlasterLib.MessageUnit mu )
583 {
584 logger.Debug( "OnMessageArrived()" );
585 try
586 {
587 // Appel asynchrone pour repasser sur le thread du Form...
588 IAsyncResult ar = this.BeginInvoke( this.messagesFillDelegate, new object[] { new MessageUnit[1] { mu } } );
589 }
590 catch(Exception ex)
591 {
592 logger.Debug("OnMessageArrived() Ex: "+ex.Message );
593 }
594 }
595
596
597 private void connect_Click(object sender, System.EventArgs e)
598 {
599 string me="connect_Click()";
600
601 try
602 {
603 string url = "http://"+this.server.Text+":"+this.xmlBlaster_port.ToString() ;
604
605 if( this.xmlBlaster != null )
606 {
607 try
608 {
609 this.xmlBlaster.Disconnect();
610 this.xmlBlaster = null ;
611 }
612 catch( Exception ex )
613 {
614 logger.Error( "{0} Failed to disconnect before connect. Ex: {1}", me, ex.Message );
615 }
616 }
617
618 this.xmlBlaster = new XmlBlasterClient();
619
620 // Check if we are already subscribed
621 bool alreadySubscribed = false ;
622 if( XmlBlasterCallback.messageArrived != null )
623 {
624 foreach( Delegate d in XmlBlasterCallback.messageArrived.GetInvocationList() )
625 {
626 if( d.Target == this )
627 {
628 alreadySubscribed = true ;
629 }
630 }
631 }
632 // not, subscribe to messageArrived.
633 if( ! alreadySubscribed )
634 {
635 XmlBlasterCallback.messageArrived += new XmlBlasterCallback.MessageArrivedDelegate( this.OnMessageArrived );
636 }
637 //XmlBlasterCallback.pingArrived += new XmlBlasterCallback.PingArrivedDelegate( this.OnPingArrived );
638
639 this.xmlBlaster.Connect( url, this.user.Text, this.password.Text );
640
641 this.PrintReport( "OK, connected to url: "+url );
642
643 MessagesViewsClear();
644
645 string query = "/*" ;
646 string key = "<key oid='' queryType='XPATH'>"+query+"</key>";
647
648 string qos = "<qos>";
649 qos += "<local>true</local>" ; // get our messages
650 qos += "<history numEntries='1000' newestFirst='true'/>"; // get all messages for a topic
651 qos += "<content>true</content>"; // get messages content
652 qos += "</qos>";
653
654 this.xmlBlaster.Subscribe( key, qos );
655
656 this.PrintReport( "OK, subscribtion done with query: "+query );
657
658 }
659 catch(Exception ex)
660 {
661 logger.Error("Failed to Connect. Ex: "+ex.Message );
662 this.xmlBlaster = null ;
663 }
664 }
665
666 private void connectStatusTimer_Tick(object sender, System.EventArgs e)
667 {
668 switch( XmlBlasterCallback.XmlBlasterServerHealth )
669 {
670 case XmlBlasterCallback.XmlBlasterServerHealthStatus.VERYGOOD:
671 this.connectStatusLed.BackColor = Color.LightGreen ;
672 break;
673 case XmlBlasterCallback.XmlBlasterServerHealthStatus.GOOD:
674 this.connectStatusLed.BackColor = Color.Green ;
675 break;
676 case XmlBlasterCallback.XmlBlasterServerHealthStatus.BAD:
677 this.connectStatusLed.BackColor = Color.Orange ;
678 break;
679 case XmlBlasterCallback.XmlBlasterServerHealthStatus.VERY_BAD:
680 this.connectStatusLed.BackColor = Color.OrangeRed ;
681 break;
682 case XmlBlasterCallback.XmlBlasterServerHealthStatus.DEAD:
683 default:
684 this.connectStatusLed.BackColor = Color.Red ;
685 break;
686 }
687 }
688
689
690 private void msgsend_send_Click(object sender, System.EventArgs e)
691 {
692 try
693 {
694 this.xmlBlaster.Publish( this.msgsend_key.Text, this.msgsend_qos.Text, this.msgsend_content.Text );
695 }
696 catch(Exception ex )
697 {
698 logger.Error( "Failed to publish message. Ex: "+ex.Message );
699 }
700 }
701
702
703 private void getMessages_Click(object sender, System.EventArgs e)
704 {
705 if( this.xmlBlaster == null )
706 {
707 MessageBox.Show( "You must connect before operate.", "Not Connected" );
708 return ;
709 }
710
711 MessagesViewsClear();
712
713 //MessageUnit[] msgs = this.xmlBlaster.Get( "/*", true );
714
715 string query = "/*" ;
716
717 // exemple: <key oid='' queryType='XPATH'> /xmlBlaster/key[starts-with(@oid,'radar.')] </key>
718 string key = "<key oid='' queryType='XPATH'>"+query+"</key>";
719
720 string qos = "<qos>";
721 qos += "<history numEntries='1000' newestFirst='true'/>";
722 qos += "<content>true</content>";
723 qos += "</qos>";
724
725 MessageUnit[] msgs = this.xmlBlaster.Get( key, qos );
726
727 messagesFill( msgs );
728 }
729
730
731 private void msgview_erase_Click(object sender, System.EventArgs e)
732 {
733 MessageTreeNode node = null ;
734 try
735 {
736 node = (MessageTreeNode) this.messages.SelectedNode ;
737 }
738 catch{ return; }
739
740 string key = null ;
741 string theKey = node.msg.KeyOid ;
742 if( theKey==null || theKey==string.Empty )
743 {
744 theKey = node.msg.KeyQuery ;
745 if( theKey==null || theKey==string.Empty )
746 {
747 logger.Error( "Could not compute the OID for this message. Erase aborted." );
748 return ;
749 }
750 key = "<key oid='' queryType='XPATH'>"+theKey+"</key>";
751 }
752 else
753 {
754 key = "<key oid=\""+theKey+"\" />\n" ;
755 }
756
757 QosErase qos = new QosErase();
758
759 this.xmlBlaster.Erase( key, qos.ToString() );
760 }
761
762
763 public delegate void MessagesFillDelegate( MessageUnit[] mus );
764 public MessagesFillDelegate messagesFillDelegate ;
765 public void messagesFill( MessageUnit[] msgs )
766 {
767 string me="messagesFill()";
768 logger.Debug(me);
769
770 //System.Threading.Monitor.Enter(this.messages);
771 //try
772 //{
773 lock (this.messages)
774 {
775 logger.Debug("{0} entering lock", me);
776 try
777 {
778 //messages.BeginUpdate();
779 foreach( MessageUnit msg in msgs )
780 {
781 MessageTreeNode mtn = new MessageTreeNode(msg) ;
782 MessageTreeNode topicNode = SearchForLabel( mtn.Text );
783 if( topicNode == null )
784 {
785 logger.Debug("messagesFill() new topic: "+mtn.Text);
786 messages.Nodes.Add( mtn );
787 }
788 else
789 {
790 logger.Debug("messagesFill() add message to topic: "+mtn.Text );
791 topicNode.Nodes.Add( mtn );
792 }
793 }
794 //messages.EndUpdate();
795 }
796 catch( Exception ex )
797 {
798 logger.Error("{0} Failed: {1}",me, ex.Message );
799 }
800 logger.Debug("{0} releasing lock", me);
801 }
802 //}
803 //finally
804 //{
805 // Always use Finally to ensure that you exit the Monitor.
806 // The following line creates another object containing
807 // the value of x, and throws SynchronizationLockException
808 // because the two objects do not match.
809 // System.Threading.Monitor.Exit(this.messages);
810 //}
811 }
812
813 MessageTreeNode SearchForLabel( string label )
814 {
815 if( messages.Nodes == null )
816 {
817 return null ;
818 }
819 // pas besoin de récurtion
820 foreach( TreeNode node in messages.Nodes )
821 {
822 if( node.Text == label )
823 {
824 return (MessageTreeNode) node ;
825 }
826 }
827 return null ;
828 }
829
830
831 void MessagesViewsClear()
832 {
833 // Clear messages and msgview
834 this.messages.Nodes.Clear();
835 this.msgview_key.Text = "" ;
836 this.msgview_qos.Text = "" ;
837 this.msgview_content.Text = "" ;
838 }
839
840
841 public static string FormatNiceXml( string xml )
842 {
843 StringBuilder sb = new StringBuilder( xml.Trim() );
844 sb.Replace( crlf, CRLF );
845 sb.Replace( lf, CRLF );
846 sb.Replace( cr, CRLF );
847 sb.Replace( "><", ">"+CRLF+"<" );
848 return sb.ToString() ;
849 }
850
851
852 private void messages_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
853 {
854 logger.Debug("messages_AfterSelect() Node.Text: "+e.Node.Text );
855
856 MessageUnit msg = ((MessageTreeNode) e.Node ).msg ;
857
858 this.msgview_key.Text = FormatNiceXml(msg.KeyStr) ;
859 this.message_toolTip.SetToolTip( this.msgview_key, this.msgview_key.Text );
860
861 this.msgview_qos.Text = FormatNiceXml(msg.Qos.OuterXml) ;
862 this.message_toolTip.SetToolTip( this.msgview_qos, this.msgview_qos.Text );
863
864 this.msgview_content.Text = FormatNiceXml(msg.ContentStr) ;
865 this.message_toolTip.SetToolTip( this.msgview_content, this.msgview_content.Text );
866 }
867
868 private void msgsend_copySelected_Click(object sender, System.EventArgs e)
869 {
870 this.msgsend_key.Text = this.msgview_key.Text ;
871 this.msgsend_qos.Text = this.msgview_qos.Text ;
872 this.msgsend_content.Text = this.msgview_content.Text ;
873 }
874
875
876 public class MessageTreeNode : TreeNode
877 {
878 public MessageUnit msg ;
879 public static string ComputeLabel( string keyoid )
880 {
881 return keyoid==null?"Unknow":keyoid ;
882 }
883 public MessageTreeNode( MessageUnit msg )
884 : base( ComputeLabel(msg.KeyOid) )
885 {
886 this.msg = msg ;
887 }
888 }
889
890 }
891 }
syntax highlighted by Code2HTML, v. 0.9.1