5 // Peter Van Isacker (sclytrack@planetinternet.be)
6 // Rafael Teixeira (rafaelteixeirabr@hotmail.com)
8 // (C) 2003 Peter Van Isacker
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:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
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.
33 using System.Collections;
34 using System.ComponentModel;
36 using System.Messaging.Design;
37 using System.Threading;
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
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;
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
92 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
93 [MessagingDescription ("MQ_Authenticate")]
94 public bool Authenticate {
96 return delegateQueue.Authenticate;
99 delegateQueue.Authenticate = value;
103 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
104 [MessagingDescription ("MQ_BasePriority")]
105 public short BasePriority {
107 return delegateQueue.BasePriority;
110 delegateQueue.BasePriority = value;
114 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
116 [MessagingDescription ("MQ_CanRead")]
117 public bool CanRead {
119 return delegateQueue.CanRead;
123 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
125 [MessagingDescription ("MQ_CanWrite")]
126 public bool CanWrite {
128 return delegateQueue.CanWrite;
132 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
133 [MessagingDescription ("MQ_Category")]
134 public Guid Category {
136 return delegateQueue.Category;
139 delegateQueue.Category = value;
143 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
144 [MessagingDescription ("MQ_CreateTime")]
145 public DateTime CreateTime {
147 return delegateQueue.CreateTime;
151 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
153 [MessagingDescription ("MQ_DefaultPropertiesToSend")]
154 public DefaultPropertiesToSend DefaultPropertiesToSend {
156 throw new NotImplementedException ();
159 throw new NotImplementedException ();
164 [DefaultValue (false)]
165 [MessagingDescription ("MQ_DenySharedReceive")]
166 public bool DenySharedReceive {
168 return delegateQueue.DenySharedReceive;
171 delegateQueue.DenySharedReceive = value;
176 public static bool EnableConnectionCache {
178 throw new NotImplementedException ();
181 throw new NotImplementedException ();
185 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
186 [MessagingDescription ("MQ_EncryptionRequired")]
187 public EncryptionRequired EncryptionRequired {
189 return (EncryptionRequired) delegateQueue.EncryptionRequired;
192 delegateQueue.EncryptionRequired = (Mono.Messaging.EncryptionRequired) value;
196 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
197 [MessagingDescription ("MQ_FormatName")]
198 public string FormatName {
200 throw new NotImplementedException ();
205 [DefaultValue (null)]
206 [TypeConverter (typeof(MessageFormatterConverter))]
207 [MessagingDescription ("MQ_Formatter")]
208 public IMessageFormatter Formatter {
217 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
218 [MessagingDescription ("MQ_GuidId")]
221 return delegateQueue.Id;
225 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
226 [MessagingDescription ("MQ_Label")]
227 public string Label {
230 //return delegateQueue.Label;
231 throw new NotImplementedException ();
235 //delegateQueue.Label = value;
236 throw new NotImplementedException ();
240 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
241 [MessagingDescription ("MQ_LastModifyTime")]
242 public DateTime LastModifyTime {
244 return delegateQueue.LastModifyTime;
249 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
250 [MessagingDescription ("MQ_MachineName")]
251 public string MachineName {
253 return delegateQueue.QRef.Host;
256 delegateQueue.QRef = delegateQueue.QRef.SetHost (value);
260 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
261 [TypeConverter (typeof(SizeConverter))]
262 [MessagingDescription ("MQ_MaximumJournalSize")]
263 public long MaximumJournalSize {
265 return delegateQueue.MaximumJournalSize;
268 delegateQueue.MaximumJournalSize = value;
272 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
273 [TypeConverter (typeof(SizeConverter))]
274 [MessagingDescription ("MQ_MaximumQueueSize")]
275 public long MaximumQueueSize {
277 return delegateQueue.MaximumQueueSize;
280 delegateQueue.MaximumQueueSize = value;
285 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
286 [MessagingDescription ("MQ_MessageReadPropertyFilter")]
287 public MessagePropertyFilter MessageReadPropertyFilter {
289 return messageReadPropertyFilter;
292 messageReadPropertyFilter = value;
296 [RecommendedAsConfigurable (true)]
297 [Editor ("System.Messaging.Design.QueuePathEditor", "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
300 [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
301 [MessagingDescription ("MQ_Path")]
304 return delegateQueue.QRef.ToString ();
307 delegateQueue.QRef = QueueReference.Parse (value);
312 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
313 [MessagingDescription ("MQ_QueueName")]
314 public string QueueName {
316 return delegateQueue.QRef.Queue;
319 delegateQueue.QRef = delegateQueue.QRef.SetQueue (value);
324 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
325 [MessagingDescription ("MQ_ReadHandle")]
326 public IntPtr ReadHandle {
328 return delegateQueue.ReadHandle;
333 [DefaultValue (null)]
334 [MessagingDescription ("MQ_SynchronizingObject")]
335 public ISynchronizeInvoke SynchronizingObject {
337 return delegateQueue.SynchronizingObject;
340 delegateQueue.SynchronizingObject = value;
344 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
345 [MessagingDescription ("MQ_Transactional")]
346 public bool Transactional {
348 return delegateQueue.Transactional;
352 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
353 [MessagingDescription ("MQ_WriteHandle")]
354 public bool UseJournalQueue {
356 return delegateQueue.UseJournalQueue;
359 delegateQueue.UseJournalQueue = value;
364 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
365 [MessagingDescription ("MQ_WriteHandle")]
366 public IntPtr WriteHandle {
368 return delegateQueue.WriteHandle;
372 internal IMessageQueue DelegateQueue {
374 return delegateQueue;
378 #endregion //Properties
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,
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);
424 public static void ClearConnectionCache ()
426 throw new NotImplementedException ();
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,
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 ();
461 IMessage iMsg = delegateQueue.EndPeek (asyncResult);
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 ();
482 IMessage iMsg = delegateQueue.EndReceive (asyncResult);
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));
502 public Message[] GetAllMessages ()
504 throw new NotImplementedException ();
507 public IEnumerator GetEnumerator ()
509 return GetMessageEnumerator ();
512 public static Guid GetMachineId (string machineName)
514 throw new NotImplementedException ();
517 public MessageEnumerator GetMessageEnumerator ()
519 return new MessageEnumerator (delegateQueue.GetMessageEnumerator (), Formatter);
522 public static MessageQueueEnumerator GetMessageQueueEnumerator ()
524 throw new NotImplementedException ();
527 private static ArrayList filteredQueueList (MessageQueueCriteria criteria)
529 throw new NotImplementedException ();
532 public static MessageQueueEnumerator GetMessageQueueEnumerator (MessageQueueCriteria criteria)
534 throw new NotImplementedException ();
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]);
552 public static MessageQueue[] GetPublicQueues (MessageQueueCriteria criteria)
554 throw new NotImplementedException ();
557 public static MessageQueue[] GetPublicQueuesByCategory (Guid category)
559 throw new NotImplementedException ();
562 public static MessageQueue[] GetPublicQueuesByLabel (string label)
564 throw new NotImplementedException ();
567 public static MessageQueue[] GetPublicQueuesByMachine (string machineName)
569 throw new NotImplementedException ();
572 public Message Peek ()
575 IMessage iMsg = delegateQueue.Peek ();
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)
593 IMessage iMsg = delegateQueue.Peek (timeout);
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)
611 IMessage iMsg = delegateQueue.PeekByCorrelationId (correlationId);
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)
629 IMessage iMsg = delegateQueue.PeekByCorrelationId (correlationId, timeout);
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)
647 IMessage iMsg = delegateQueue.PeekById (id);
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)
665 IMessage iMsg = delegateQueue.PeekById (id, timeout);
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);
682 delegateQueue.Purge ();
685 public Message Receive ()
688 IMessage iMsg = delegateQueue.Receive ();
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)
704 IMessage iMsg = delegateQueue.Receive (transaction.DelegateTx);
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)
722 IMessage iMsg = delegateQueue.Receive ((Mono.Messaging.MessageQueueTransactionType) transactionType);
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)
740 IMessage iMsg = delegateQueue.Receive (timeout);
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)
758 IMessage iMsg = delegateQueue.Receive (timeout, transaction.DelegateTx);
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)
776 IMessage iMsg = delegateQueue.Receive (timeout,
777 (Mono.Messaging.MessageQueueTransactionType) transactionType);
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)
795 IMessage iMsg = delegateQueue.ReceiveByCorrelationId (correlationId);
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)
813 IMessage iMsg = delegateQueue.ReceiveByCorrelationId (correlationId, transaction.DelegateTx);
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)
831 IMessage iMsg = delegateQueue.ReceiveByCorrelationId (correlationId, (Mono.Messaging.MessageQueueTransactionType) transactionType);
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)
849 IMessage iMsg = delegateQueue.ReceiveByCorrelationId (correlationId,
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)
868 IMessage iMsg = delegateQueue.ReceiveByCorrelationId (correlationId, timeout, transaction.DelegateTx);
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)
886 IMessage iMsg = delegateQueue.ReceiveByCorrelationId (correlationId, timeout, (Mono.Messaging.MessageQueueTransactionType) transactionType);
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)
904 IMessage iMsg = delegateQueue.ReceiveById (id);
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)
922 IMessage iMsg = delegateQueue.ReceiveById (id, transaction.DelegateTx);
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)
940 IMessage iMsg = delegateQueue.ReceiveById (id, (Mono.Messaging.MessageQueueTransactionType) transactionType);
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)
958 IMessage iMsg = delegateQueue.ReceiveById (id, timeout);
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)
976 IMessage iMsg = delegateQueue.ReceiveById (id, timeout, transaction.DelegateTx);
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)
994 IMessage iMsg = delegateQueue.ReceiveById (id, timeout, (Mono.Messaging.MessageQueueTransactionType) transactionType);
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);
1009 public void Refresh ()
1011 throw new NotImplementedException ();
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);
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);
1036 Message m = new Message (obj);
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);
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);
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);
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);
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;
1093 Message m = new Message (obj);
1098 public void Send (object obj, string label, MessageQueueTransaction transaction)
1100 if (typeof (Message) == obj.GetType ()) {
1101 Message m = (Message) obj;
1104 if (m.BodyStream == null) {
1105 IMessageFormatter f = (m.Formatter == null) ? Formatter : m.Formatter;
1106 f.Write (m, m.Body);
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);
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;
1127 Send (m, transactionType);
1129 Message m = new Message (obj);
1130 Send (m, label, transactionType);
1134 public void SetPermissions (AccessControlList dacl)
1136 throw new NotImplementedException ();
1139 public void SetPermissions (MessageQueueAccessControlEntry ace)
1141 throw new NotImplementedException ();
1144 public void SetPermissions (string user, MessageQueueAccessRights rights)
1146 throw new NotImplementedException ();
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)
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)
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
1190 .GetMessageQueue (qRef);
1194 private static IMessageQueue GetMessageQueue ()
1196 return MessagingProviderLocator.GetProvider ()
1197 .GetMessageQueue (QueueReference.DEFAULT);
1200 private static IMessageQueue CreateMessageQueue (QueueReference qRef,
1203 return MessagingProviderLocator.GetProvider ()
1204 .CreateMessageQueue (qRef, transactional);
1207 private static bool Exists (QueueReference qRef)
1209 return MessagingProviderLocator.GetProvider ().Exists (qRef);