2010-04-07 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System.Messaging / System.Messaging / MessageQueue.cs
blob4fc940334feb3657f887df4efe455fbc8304d8e5
1 //
2 // System.Messaging
3 //
4 // Authors:
5 // Peter Van Isacker (sclytrack@planetinternet.be)
6 // Rafael Teixeira (rafaelteixeirabr@hotmail.com)
7 //
8 // (C) 2003 Peter Van Isacker
9 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System;
33 using System.Collections;
34 using System.ComponentModel;
35 using System.Drawing;
36 using System.Messaging.Design;
37 using System.Threading;
39 using Mono.Messaging;
41 namespace System.Messaging
43 [TypeConverter (typeof(MessageQueueConverter))]
44 [Editor ("System.Messaging.Design.QueuePathEditor", "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
45 [Designer ("Microsoft.VisualStudio.Install.MessageQueueInstallableComponentDesigner, " + Consts.AssemblyMicrosoft_VisualStudio)]
46 [InstallerType (typeof(MessageQueueInstaller))]
47 [DefaultEvent ("ReceiveCompleted")]
48 public class MessageQueue : Component, IEnumerable
50 #region Fields
52 public static readonly long InfiniteQueueSize;
53 public static readonly TimeSpan InfiniteTimeout = MessagingProviderLocator.InfiniteTimeout;
54 private IMessageFormatter formatter;
55 private MessagePropertyFilter messageReadPropertyFilter = new MessagePropertyFilter ();
56 private readonly IMessageQueue delegateQueue;
58 #endregion //Fields
61 #region Constructor
63 public MessageQueue () : this (GetMessageQueue ())
67 public MessageQueue (string path) : this (path, false)
71 public MessageQueue (string path, bool sharedModeDenyReceive) :
72 this (GetMessageQueue (path))
76 public MessageQueue (string path, QueueAccessMode accessMode) :
77 this (GetMessageQueue (path))
81 internal MessageQueue (IMessageQueue delegateQueue)
83 this.delegateQueue = delegateQueue;
84 formatter = new XmlMessageFormatter ();
85 delegateQueue.PeekCompleted += new CompletedEventHandler (DelegatePeekCompleted);
88 #endregion //Constructor
90 #region Properties
92 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
93 [MessagingDescription ("MQ_Authenticate")]
94 public bool Authenticate {
95 get {
96 return delegateQueue.Authenticate;
98 set {
99 delegateQueue.Authenticate = value;
103 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
104 [MessagingDescription ("MQ_BasePriority")]
105 public short BasePriority {
106 get {
107 return delegateQueue.BasePriority;
109 set {
110 delegateQueue.BasePriority = value;
114 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
115 [Browsable (false)]
116 [MessagingDescription ("MQ_CanRead")]
117 public bool CanRead {
118 get {
119 return delegateQueue.CanRead;
123 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
124 [Browsable (false)]
125 [MessagingDescription ("MQ_CanWrite")]
126 public bool CanWrite {
127 get {
128 return delegateQueue.CanWrite;
132 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
133 [MessagingDescription ("MQ_Category")]
134 public Guid Category {
135 get {
136 return delegateQueue.Category;
138 set {
139 delegateQueue.Category = value;
143 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
144 [MessagingDescription ("MQ_CreateTime")]
145 public DateTime CreateTime {
146 get {
147 return delegateQueue.CreateTime;
151 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
152 [Browsable (false)]
153 [MessagingDescription ("MQ_DefaultPropertiesToSend")]
154 public DefaultPropertiesToSend DefaultPropertiesToSend {
155 get {
156 throw new NotImplementedException ();
158 set {
159 throw new NotImplementedException ();
163 [Browsable (false)]
164 [DefaultValue (false)]
165 [MessagingDescription ("MQ_DenySharedReceive")]
166 public bool DenySharedReceive {
167 get {
168 return delegateQueue.DenySharedReceive;
170 set {
171 delegateQueue.DenySharedReceive = value;
175 [Browsable (false)]
176 public static bool EnableConnectionCache {
177 get {
178 throw new NotImplementedException ();
180 set {
181 throw new NotImplementedException ();
185 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
186 [MessagingDescription ("MQ_EncryptionRequired")]
187 public EncryptionRequired EncryptionRequired {
188 get {
189 return (EncryptionRequired) delegateQueue.EncryptionRequired;
191 set {
192 delegateQueue.EncryptionRequired = (Mono.Messaging.EncryptionRequired) value;
196 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
197 [MessagingDescription ("MQ_FormatName")]
198 public string FormatName {
199 get {
200 throw new NotImplementedException ();
204 [Browsable (false)]
205 [DefaultValue (null)]
206 [TypeConverter (typeof(MessageFormatterConverter))]
207 [MessagingDescription ("MQ_Formatter")]
208 public IMessageFormatter Formatter {
209 get {
210 return formatter;
212 set {
213 formatter = value;
217 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
218 [MessagingDescription ("MQ_GuidId")]
219 public Guid Id {
220 get {
221 return delegateQueue.Id;
225 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
226 [MessagingDescription ("MQ_Label")]
227 public string Label {
228 [MonoTODO]
229 get {
230 //return delegateQueue.Label;
231 throw new NotImplementedException ();
233 [MonoTODO]
234 set {
235 //delegateQueue.Label = value;
236 throw new NotImplementedException ();
240 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
241 [MessagingDescription ("MQ_LastModifyTime")]
242 public DateTime LastModifyTime {
243 get {
244 return delegateQueue.LastModifyTime;
248 [Browsable (false)]
249 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
250 [MessagingDescription ("MQ_MachineName")]
251 public string MachineName {
252 get {
253 return delegateQueue.QRef.Host;
255 set {
256 delegateQueue.QRef = delegateQueue.QRef.SetHost (value);
260 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
261 [TypeConverter (typeof(SizeConverter))]
262 [MessagingDescription ("MQ_MaximumJournalSize")]
263 public long MaximumJournalSize {
264 get {
265 return delegateQueue.MaximumJournalSize;
267 set {
268 delegateQueue.MaximumJournalSize = value;
272 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
273 [TypeConverter (typeof(SizeConverter))]
274 [MessagingDescription ("MQ_MaximumQueueSize")]
275 public long MaximumQueueSize {
276 get {
277 return delegateQueue.MaximumQueueSize;
279 set {
280 delegateQueue.MaximumQueueSize = value;
284 [Browsable (false)]
285 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
286 [MessagingDescription ("MQ_MessageReadPropertyFilter")]
287 public MessagePropertyFilter MessageReadPropertyFilter {
288 get {
289 return messageReadPropertyFilter;
291 set {
292 messageReadPropertyFilter = value;
296 [RecommendedAsConfigurable (true)]
297 [Editor ("System.Messaging.Design.QueuePathEditor", "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
298 [Browsable (false)]
299 [DefaultValue ("")]
300 [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
301 [MessagingDescription ("MQ_Path")]
302 public string Path {
303 get {
304 return delegateQueue.QRef.ToString ();
306 set {
307 delegateQueue.QRef = QueueReference.Parse (value);
311 [Browsable (false)]
312 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
313 [MessagingDescription ("MQ_QueueName")]
314 public string QueueName {
315 get {
316 return delegateQueue.QRef.Queue;
318 set {
319 delegateQueue.QRef = delegateQueue.QRef.SetQueue (value);
323 [Browsable (false)]
324 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
325 [MessagingDescription ("MQ_ReadHandle")]
326 public IntPtr ReadHandle {
327 get {
328 return delegateQueue.ReadHandle;
332 [Browsable (false)]
333 [DefaultValue (null)]
334 [MessagingDescription ("MQ_SynchronizingObject")]
335 public ISynchronizeInvoke SynchronizingObject {
336 get {
337 return delegateQueue.SynchronizingObject;
339 set {
340 delegateQueue.SynchronizingObject = value;
344 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
345 [MessagingDescription ("MQ_Transactional")]
346 public bool Transactional {
347 get {
348 return delegateQueue.Transactional;
352 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
353 [MessagingDescription ("MQ_WriteHandle")]
354 public bool UseJournalQueue {
355 get {
356 return delegateQueue.UseJournalQueue;
358 set {
359 delegateQueue.UseJournalQueue = value;
363 [Browsable (false)]
364 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
365 [MessagingDescription ("MQ_WriteHandle")]
366 public IntPtr WriteHandle {
367 get {
368 return delegateQueue.WriteHandle;
372 internal IMessageQueue DelegateQueue {
373 get {
374 return delegateQueue;
378 #endregion //Properties
380 #region Methods
382 public IAsyncResult BeginPeek ()
384 return delegateQueue.BeginPeek ();
387 public IAsyncResult BeginPeek (TimeSpan timeout)
389 return delegateQueue.BeginPeek (timeout);
392 public IAsyncResult BeginPeek (TimeSpan timeout, object stateObject)
394 return delegateQueue.BeginPeek (timeout, stateObject);
397 public IAsyncResult BeginPeek (TimeSpan timeout,
398 object stateObject,
399 AsyncCallback callback)
401 return delegateQueue.BeginPeek (timeout, stateObject, callback);
404 public IAsyncResult BeginReceive ()
406 return delegateQueue.BeginReceive ();
409 public IAsyncResult BeginReceive (TimeSpan timeout)
411 return delegateQueue.BeginReceive (timeout);
414 public IAsyncResult BeginReceive (TimeSpan timeout, object stateObject)
416 return delegateQueue.BeginReceive (timeout, stateObject);
419 public IAsyncResult BeginReceive (TimeSpan timeout, object stateObject, AsyncCallback callback)
421 return delegateQueue.BeginReceive (timeout, stateObject, callback);
423 [MonoTODO]
424 public static void ClearConnectionCache ()
426 throw new NotImplementedException ();
429 public void Close ()
431 delegateQueue.Close ();
434 public static MessageQueue Create (string path)
436 QueueReference qRef = QueueReference.Parse (path);
437 IMessageQueue iMessageQueue = CreateMessageQueue (qRef, false);
438 return new MessageQueue (iMessageQueue);
441 public static MessageQueue Create (string path, bool transactional)
443 QueueReference qRef = QueueReference.Parse (path);
444 IMessageQueue iMessageQueue = CreateMessageQueue (qRef,
445 transactional);
446 return new MessageQueue (iMessageQueue);
449 public static void Delete (string path)
451 QueueReference qRef = QueueReference.Parse (path);
452 MessagingProviderLocator.GetProvider ().DeleteQueue (qRef);
455 public Message EndPeek (IAsyncResult asyncResult)
457 if (asyncResult == null)
458 throw new ArgumentNullException ();
460 try {
461 IMessage iMsg = delegateQueue.EndPeek (asyncResult);
462 if (iMsg == null)
463 return null;
465 return new Message (iMsg, null, Formatter);
467 } catch (ConnectionException e) {
468 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
469 } catch (MessageUnavailableException e) {
470 throw new InvalidOperationException (e.Message, e);
471 } catch (MonoMessagingException e) {
472 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
476 public Message EndReceive (IAsyncResult asyncResult)
478 if (asyncResult == null)
479 throw new ArgumentNullException ();
481 try {
482 IMessage iMsg = delegateQueue.EndReceive (asyncResult);
483 if (iMsg == null)
484 return null;
486 return new Message (iMsg, null, Formatter);
488 } catch (ConnectionException e) {
489 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
490 } catch (MessageUnavailableException e) {
491 throw new InvalidOperationException (e.Message, e);
492 } catch (MonoMessagingException e) {
493 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
497 public static bool Exists (string path)
499 return Exists (QueueReference.Parse (path));
501 [MonoTODO]
502 public Message[] GetAllMessages ()
504 throw new NotImplementedException ();
507 public IEnumerator GetEnumerator ()
509 return GetMessageEnumerator ();
511 [MonoTODO]
512 public static Guid GetMachineId (string machineName)
514 throw new NotImplementedException ();
517 public MessageEnumerator GetMessageEnumerator ()
519 return new MessageEnumerator (delegateQueue.GetMessageEnumerator (), Formatter);
521 [MonoTODO]
522 public static MessageQueueEnumerator GetMessageQueueEnumerator ()
524 throw new NotImplementedException ();
526 [MonoTODO]
527 private static ArrayList filteredQueueList (MessageQueueCriteria criteria)
529 throw new NotImplementedException ();
531 [MonoTODO]
532 public static MessageQueueEnumerator GetMessageQueueEnumerator (MessageQueueCriteria criteria)
534 throw new NotImplementedException ();
536 [MonoTODO]
537 public static MessageQueue[] GetPrivateQueuesByMachine (string machineName)
539 throw new NotImplementedException ();
542 public static MessageQueue[] GetPublicQueues ()
544 IMessagingProvider provider = MessagingProviderLocator.GetProvider ();
545 IMessageQueue[] imqs = provider.GetPublicQueues ();
546 MessageQueue[] mqs = new MessageQueue[imqs.Length];
547 for (int i = 0; i < imqs.Length; i++)
548 mqs[i] = new MessageQueue (imqs[i]);
549 return mqs;
551 [MonoTODO]
552 public static MessageQueue[] GetPublicQueues (MessageQueueCriteria criteria)
554 throw new NotImplementedException ();
556 [MonoTODO]
557 public static MessageQueue[] GetPublicQueuesByCategory (Guid category)
559 throw new NotImplementedException ();
561 [MonoTODO]
562 public static MessageQueue[] GetPublicQueuesByLabel (string label)
564 throw new NotImplementedException ();
566 [MonoTODO]
567 public static MessageQueue[] GetPublicQueuesByMachine (string machineName)
569 throw new NotImplementedException ();
572 public Message Peek ()
574 try {
575 IMessage iMsg = delegateQueue.Peek ();
576 if (iMsg == null)
577 return null;
579 return new Message (iMsg, null, Formatter);
581 } catch (ConnectionException e) {
582 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
583 } catch (MessageUnavailableException e) {
584 throw new InvalidOperationException (e.Message, e);
585 } catch (MonoMessagingException e) {
586 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
590 public Message Peek (TimeSpan timeout)
592 try {
593 IMessage iMsg = delegateQueue.Peek (timeout);
594 if (iMsg == null)
595 return null;
597 return new Message (iMsg, null, Formatter);
599 } catch (ConnectionException e) {
600 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
601 } catch (MessageUnavailableException e) {
602 throw new InvalidOperationException (e.Message, e);
603 } catch (MonoMessagingException e) {
604 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
608 public Message PeekByCorrelationId (string correlationId)
610 try {
611 IMessage iMsg = delegateQueue.PeekByCorrelationId (correlationId);
612 if (iMsg == null)
613 return null;
615 return new Message (iMsg, null, Formatter);
617 } catch (ConnectionException e) {
618 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
619 } catch (MessageUnavailableException e) {
620 throw new InvalidOperationException (e.Message, e);
621 } catch (MonoMessagingException e) {
622 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
626 public Message PeekByCorrelationId (string correlationId, TimeSpan timeout)
628 try {
629 IMessage iMsg = delegateQueue.PeekByCorrelationId (correlationId, timeout);
630 if (iMsg == null)
631 return null;
633 return new Message (iMsg, null, Formatter);
635 } catch (ConnectionException e) {
636 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
637 } catch (MessageUnavailableException e) {
638 throw new InvalidOperationException (e.Message, e);
639 } catch (MonoMessagingException e) {
640 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
644 public Message PeekById (string id)
646 try {
647 IMessage iMsg = delegateQueue.PeekById (id);
648 if (iMsg == null)
649 return null;
651 return new Message (iMsg, null, Formatter);
653 } catch (ConnectionException e) {
654 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
655 } catch (MessageUnavailableException e) {
656 throw new InvalidOperationException (e.Message, e);
657 } catch (MonoMessagingException e) {
658 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
662 public Message PeekById (string id, TimeSpan timeout)
664 try {
665 IMessage iMsg = delegateQueue.PeekById (id, timeout);
666 if (iMsg == null)
667 return null;
669 return new Message (iMsg, null, Formatter);
671 } catch (ConnectionException e) {
672 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
673 } catch (MessageUnavailableException e) {
674 throw new InvalidOperationException (e.Message, e);
675 } catch (MonoMessagingException e) {
676 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
680 public void Purge ()
682 delegateQueue.Purge ();
685 public Message Receive ()
687 try {
688 IMessage iMsg = delegateQueue.Receive ();
689 if (iMsg == null)
690 return null;
692 return new Message (iMsg, null, Formatter);
694 } catch (ConnectionException e) {
695 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
696 } catch (MonoMessagingException e) {
697 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
701 public Message Receive (MessageQueueTransaction transaction)
703 try {
704 IMessage iMsg = delegateQueue.Receive (transaction.DelegateTx);
705 if (iMsg == null)
706 return null;
708 return new Message (iMsg, null, Formatter);
710 } catch (ConnectionException e) {
711 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
712 } catch (MessageUnavailableException e) {
713 throw new InvalidOperationException (e.Message, e);
714 } catch (MonoMessagingException e) {
715 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
719 public Message Receive (MessageQueueTransactionType transactionType)
721 try {
722 IMessage iMsg = delegateQueue.Receive ((Mono.Messaging.MessageQueueTransactionType) transactionType);
723 if (iMsg == null)
724 return null;
726 return new Message (iMsg, null, Formatter);
728 } catch (ConnectionException e) {
729 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
730 } catch (MessageUnavailableException e) {
731 throw new InvalidOperationException (e.Message, e);
732 } catch (MonoMessagingException e) {
733 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
737 public Message Receive (TimeSpan timeout)
739 try {
740 IMessage iMsg = delegateQueue.Receive (timeout);
741 if (iMsg == null)
742 return null;
744 return new Message (iMsg, null, Formatter);
746 } catch (ConnectionException e) {
747 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
748 } catch (MessageUnavailableException e) {
749 throw new InvalidOperationException (e.Message, e);
750 } catch (MonoMessagingException e) {
751 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
755 public Message Receive (TimeSpan timeout, MessageQueueTransaction transaction)
757 try {
758 IMessage iMsg = delegateQueue.Receive (timeout, transaction.DelegateTx);
759 if (iMsg == null)
760 return null;
762 return new Message (iMsg, null, Formatter);
764 } catch (ConnectionException e) {
765 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
766 } catch (MessageUnavailableException e) {
767 throw new InvalidOperationException (e.Message, e);
768 } catch (MonoMessagingException e) {
769 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
773 public Message Receive (TimeSpan timeout, MessageQueueTransactionType transactionType)
775 try {
776 IMessage iMsg = delegateQueue.Receive (timeout,
777 (Mono.Messaging.MessageQueueTransactionType) transactionType);
778 if (iMsg == null)
779 return null;
781 return new Message (iMsg, null, Formatter);
783 } catch (ConnectionException e) {
784 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
785 } catch (MessageUnavailableException e) {
786 throw new InvalidOperationException (e.Message, e);
787 } catch (MonoMessagingException e) {
788 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
792 public Message ReceiveByCorrelationId (string correlationId)
794 try {
795 IMessage iMsg = delegateQueue.ReceiveByCorrelationId (correlationId);
796 if (iMsg == null)
797 return null;
799 return new Message (iMsg, null, Formatter);
801 } catch (ConnectionException e) {
802 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
803 } catch (MessageUnavailableException e) {
804 throw new InvalidOperationException (e.Message, e);
805 } catch (MonoMessagingException e) {
806 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
810 public Message ReceiveByCorrelationId (string correlationId, MessageQueueTransaction transaction)
812 try {
813 IMessage iMsg = delegateQueue.ReceiveByCorrelationId (correlationId, transaction.DelegateTx);
814 if (iMsg == null)
815 return null;
817 return new Message (iMsg, null, Formatter);
819 } catch (ConnectionException e) {
820 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
821 } catch (MessageUnavailableException e) {
822 throw new InvalidOperationException (e.Message, e);
823 } catch (MonoMessagingException e) {
824 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
828 public Message ReceiveByCorrelationId (string correlationId, MessageQueueTransactionType transactionType)
830 try {
831 IMessage iMsg = delegateQueue.ReceiveByCorrelationId (correlationId, (Mono.Messaging.MessageQueueTransactionType) transactionType);
832 if (iMsg == null)
833 return null;
835 return new Message (iMsg, null, Formatter);
837 } catch (ConnectionException e) {
838 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
839 } catch (MessageUnavailableException e) {
840 throw new InvalidOperationException (e.Message, e);
841 } catch (MonoMessagingException e) {
842 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
846 public Message ReceiveByCorrelationId (string correlationId, TimeSpan timeout)
848 try {
849 IMessage iMsg = delegateQueue.ReceiveByCorrelationId (correlationId,
850 timeout);
851 if (iMsg == null)
852 return null;
854 return new Message (iMsg, null, Formatter);
856 } catch (ConnectionException e) {
857 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
858 } catch (MessageUnavailableException e) {
859 throw new InvalidOperationException (e.Message, e);
860 } catch (MonoMessagingException e) {
861 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
865 public Message ReceiveByCorrelationId (string correlationId, TimeSpan timeout, MessageQueueTransaction transaction)
867 try {
868 IMessage iMsg = delegateQueue.ReceiveByCorrelationId (correlationId, timeout, transaction.DelegateTx);
869 if (iMsg == null)
870 return null;
872 return new Message (iMsg, null, Formatter);
874 } catch (ConnectionException e) {
875 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
876 } catch (MessageUnavailableException e) {
877 throw new InvalidOperationException (e.Message, e);
878 } catch (MonoMessagingException e) {
879 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
883 public Message ReceiveByCorrelationId (string correlationId, TimeSpan timeout, MessageQueueTransactionType transactionType)
885 try {
886 IMessage iMsg = delegateQueue.ReceiveByCorrelationId (correlationId, timeout, (Mono.Messaging.MessageQueueTransactionType) transactionType);
887 if (iMsg == null)
888 return null;
890 return new Message (iMsg, null, Formatter);
892 } catch (ConnectionException e) {
893 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
894 } catch (MessageUnavailableException e) {
895 throw new InvalidOperationException (e.Message, e);
896 } catch (MonoMessagingException e) {
897 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
901 public Message ReceiveById (string id)
903 try {
904 IMessage iMsg = delegateQueue.ReceiveById (id);
905 if (iMsg == null)
906 return null;
908 return new Message (iMsg, null, Formatter);
910 } catch (ConnectionException e) {
911 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
912 } catch (MessageUnavailableException e) {
913 throw new InvalidOperationException (e.Message, e);
914 } catch (MonoMessagingException e) {
915 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
919 public Message ReceiveById (string id, MessageQueueTransaction transaction)
921 try {
922 IMessage iMsg = delegateQueue.ReceiveById (id, transaction.DelegateTx);
923 if (iMsg == null)
924 return null;
926 return new Message (iMsg, null, Formatter);
928 } catch (ConnectionException e) {
929 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
930 } catch (MessageUnavailableException e) {
931 throw new InvalidOperationException (e.Message, e);
932 } catch (MonoMessagingException e) {
933 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
937 public Message ReceiveById (string id, MessageQueueTransactionType transactionType)
939 try {
940 IMessage iMsg = delegateQueue.ReceiveById (id, (Mono.Messaging.MessageQueueTransactionType) transactionType);
941 if (iMsg == null)
942 return null;
944 return new Message (iMsg, null, Formatter);
946 } catch (ConnectionException e) {
947 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
948 } catch (MessageUnavailableException e) {
949 throw new InvalidOperationException (e.Message, e);
950 } catch (MonoMessagingException e) {
951 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
955 public Message ReceiveById (string id, TimeSpan timeout)
957 try {
958 IMessage iMsg = delegateQueue.ReceiveById (id, timeout);
959 if (iMsg == null)
960 return null;
962 return new Message (iMsg, null, Formatter);
964 } catch (ConnectionException e) {
965 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
966 } catch (MessageUnavailableException e) {
967 throw new InvalidOperationException (e.Message, e);
968 } catch (MonoMessagingException e) {
969 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
973 public Message ReceiveById (string id, TimeSpan timeout, MessageQueueTransaction transaction)
975 try {
976 IMessage iMsg = delegateQueue.ReceiveById (id, timeout, transaction.DelegateTx);
977 if (iMsg == null)
978 return null;
980 return new Message (iMsg, null, Formatter);
982 } catch (ConnectionException e) {
983 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
984 } catch (MessageUnavailableException e) {
985 throw new InvalidOperationException (e.Message, e);
986 } catch (MonoMessagingException e) {
987 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
991 public Message ReceiveById (string id, TimeSpan timeout, MessageQueueTransactionType transactionType)
993 try {
994 IMessage iMsg = delegateQueue.ReceiveById (id, timeout, (Mono.Messaging.MessageQueueTransactionType) transactionType);
995 if (iMsg == null)
996 return null;
998 return new Message (iMsg, null, Formatter);
1000 } catch (ConnectionException e) {
1001 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
1002 } catch (MessageUnavailableException e) {
1003 throw new InvalidOperationException (e.Message, e);
1004 } catch (MonoMessagingException e) {
1005 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
1008 [MonoTODO]
1009 public void Refresh ()
1011 throw new NotImplementedException ();
1013 [MonoTODO]
1014 public void ResetPermissions ()
1016 throw new NotImplementedException ();
1019 public void Send (object obj)
1021 if (typeof (Message) == obj.GetType ()) {
1022 Message m = (Message) obj;
1023 if (m.BodyStream == null) {
1024 IMessageFormatter f = (m.Formatter == null) ? Formatter : m.Formatter;
1025 f.Write (m, m.Body);
1028 try {
1029 delegateQueue.Send (m.DelegateMessage);
1030 } catch (ConnectionException e) {
1031 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
1032 } catch (MonoMessagingException e) {
1033 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
1035 } else {
1036 Message m = new Message (obj);
1037 Send (m);
1041 public void Send (object obj, MessageQueueTransaction transaction)
1043 if (typeof (Message) == obj.GetType ()) {
1044 Message m = (Message) obj;
1045 if (m.BodyStream == null) {
1046 IMessageFormatter f = (m.Formatter == null) ? Formatter : m.Formatter;
1047 f.Write (m, m.Body);
1050 try {
1051 delegateQueue.Send (m.DelegateMessage, transaction.DelegateTx);
1052 } catch (ConnectionException e) {
1053 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
1054 } catch (MonoMessagingException e) {
1055 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
1057 } else {
1058 Message m = new Message (obj);
1059 Send (m, transaction);
1063 public void Send (object obj, MessageQueueTransactionType transactionType)
1065 if (typeof (Message) == obj.GetType ()) {
1066 Message m = (Message) obj;
1067 if (m.BodyStream == null) {
1068 IMessageFormatter f = (m.Formatter == null) ? Formatter : m.Formatter;
1069 f.Write (m, m.Body);
1072 try {
1073 delegateQueue.Send (m.DelegateMessage, (Mono.Messaging.MessageQueueTransactionType) transactionType);
1074 } catch (ConnectionException e) {
1075 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
1076 } catch (MonoMessagingException e) {
1077 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
1079 } else {
1080 Message m = new Message (obj);
1081 Send (m, transactionType);
1085 public void Send (object obj, string label)
1087 if (typeof (Message) == obj.GetType ()) {
1088 Message m = (Message) obj;
1089 m.Label = label;
1091 Send (m);
1092 } else {
1093 Message m = new Message (obj);
1094 Send (m, label);
1098 public void Send (object obj, string label, MessageQueueTransaction transaction)
1100 if (typeof (Message) == obj.GetType ()) {
1101 Message m = (Message) obj;
1102 m.Label = label;
1104 if (m.BodyStream == null) {
1105 IMessageFormatter f = (m.Formatter == null) ? Formatter : m.Formatter;
1106 f.Write (m, m.Body);
1109 try {
1110 delegateQueue.Send (m.DelegateMessage, transaction.DelegateTx);
1111 } catch (ConnectionException e) {
1112 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
1113 } catch (MonoMessagingException e) {
1114 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
1116 } else {
1117 Message m = new Message (obj);
1118 Send (m, label, transaction);
1122 public void Send (object obj, string label, MessageQueueTransactionType transactionType)
1124 if (typeof (Message) == obj.GetType ()) {
1125 Message m = (Message) obj;
1126 m.Label = label;
1127 Send (m, transactionType);
1128 } else {
1129 Message m = new Message (obj);
1130 Send (m, label, transactionType);
1133 [MonoTODO]
1134 public void SetPermissions (AccessControlList dacl)
1136 throw new NotImplementedException ();
1138 [MonoTODO]
1139 public void SetPermissions (MessageQueueAccessControlEntry ace)
1141 throw new NotImplementedException ();
1143 [MonoTODO]
1144 public void SetPermissions (string user, MessageQueueAccessRights rights)
1146 throw new NotImplementedException ();
1148 [MonoTODO]
1149 public void SetPermissions (string user, MessageQueueAccessRights rights, AccessControlEntryType entryType)
1151 throw new NotImplementedException ();
1154 protected override void Dispose (bool disposing)
1156 //delegateQueue.Dispose ();
1159 #endregion //Methods
1161 [MessagingDescription ("MQ_PeekCompleted")]
1162 public event PeekCompletedEventHandler PeekCompleted;
1164 private void DelegatePeekCompleted (object sender, CompletedEventArgs args)
1166 if (PeekCompleted == null)
1167 return;
1169 PeekCompletedEventArgs newArgs = new PeekCompletedEventArgs (this, args.AsyncResult);
1170 PeekCompleted (sender, newArgs);
1173 [MessagingDescription ("MQ_ReceiveCompleted")]
1174 public event ReceiveCompletedEventHandler ReceiveCompleted;
1176 private void DelegateReceiveCompleted (object sender, CompletedEventArgs args)
1178 if (ReceiveCompleted == null)
1179 return;
1181 ReceiveCompletedEventArgs newArgs = new ReceiveCompletedEventArgs (this, args.AsyncResult);
1182 ReceiveCompleted (sender, newArgs);
1185 private static IMessageQueue GetMessageQueue (string path)
1187 QueueReference qRef = QueueReference.Parse (path);
1188 IMessageQueue q = MessagingProviderLocator
1189 .GetProvider ()
1190 .GetMessageQueue (qRef);
1191 return q;
1194 private static IMessageQueue GetMessageQueue ()
1196 return MessagingProviderLocator.GetProvider ()
1197 .GetMessageQueue (QueueReference.DEFAULT);
1200 private static IMessageQueue CreateMessageQueue (QueueReference qRef,
1201 bool transactional)
1203 return MessagingProviderLocator.GetProvider ()
1204 .CreateMessageQueue (qRef, transactional);
1207 private static bool Exists (QueueReference qRef)
1209 return MessagingProviderLocator.GetProvider ().Exists (qRef);