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 internal MessageQueue (IMessageQueue delegateQueue)
78 this.delegateQueue = delegateQueue;
79 formatter = new XmlMessageFormatter ();
80 delegateQueue.PeekCompleted += new CompletedEventHandler (DelegatePeekCompleted);
83 #endregion //Constructor
87 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
88 [MessagingDescription ("MQ_Authenticate")]
89 public bool Authenticate {
91 return delegateQueue.Authenticate;
94 delegateQueue.Authenticate = value;
98 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
99 [MessagingDescription ("MQ_BasePriority")]
100 public short BasePriority {
102 return delegateQueue.BasePriority;
105 delegateQueue.BasePriority = value;
109 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
111 [MessagingDescription ("MQ_CanRead")]
112 public bool CanRead {
114 return delegateQueue.CanRead;
118 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
120 [MessagingDescription ("MQ_CanWrite")]
121 public bool CanWrite {
123 return delegateQueue.CanWrite;
127 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
128 [MessagingDescription ("MQ_Category")]
129 public Guid Category {
131 return delegateQueue.Category;
134 delegateQueue.Category = value;
138 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
139 [MessagingDescription ("MQ_CreateTime")]
140 public DateTime CreateTime {
142 return delegateQueue.CreateTime;
146 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
148 [MessagingDescription ("MQ_DefaultPropertiesToSend")]
149 public DefaultPropertiesToSend DefaultPropertiesToSend {
151 throw new NotImplementedException ();
154 throw new NotImplementedException ();
159 [DefaultValue (false)]
160 [MessagingDescription ("MQ_DenySharedReceive")]
161 public bool DenySharedReceive {
163 return delegateQueue.DenySharedReceive;
166 delegateQueue.DenySharedReceive = value;
171 public static bool EnableConnectionCache {
173 throw new NotImplementedException ();
176 throw new NotImplementedException ();
180 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
181 [MessagingDescription ("MQ_EncryptionRequired")]
182 public EncryptionRequired EncryptionRequired {
184 return (EncryptionRequired) delegateQueue.EncryptionRequired;
187 delegateQueue.EncryptionRequired = (Mono.Messaging.EncryptionRequired) value;
191 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
192 [MessagingDescription ("MQ_FormatName")]
193 public string FormatName {
195 throw new NotImplementedException ();
200 [DefaultValue (null)]
201 [TypeConverter (typeof(MessageFormatterConverter))]
202 [MessagingDescription ("MQ_Formatter")]
203 public IMessageFormatter Formatter {
212 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
213 [MessagingDescription ("MQ_GuidId")]
216 return delegateQueue.Id;
220 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
221 [MessagingDescription ("MQ_Label")]
222 public string Label {
225 //return delegateQueue.Label;
226 throw new NotImplementedException ();
230 //delegateQueue.Label = value;
231 throw new NotImplementedException ();
235 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
236 [MessagingDescription ("MQ_LastModifyTime")]
237 public DateTime LastModifyTime {
239 return delegateQueue.LastModifyTime;
244 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
245 [MessagingDescription ("MQ_MachineName")]
246 public string MachineName {
248 return delegateQueue.QRef.Host;
251 delegateQueue.QRef = delegateQueue.QRef.SetHost (value);
255 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
256 [TypeConverter (typeof(SizeConverter))]
257 [MessagingDescription ("MQ_MaximumJournalSize")]
258 public long MaximumJournalSize {
260 return delegateQueue.MaximumJournalSize;
263 delegateQueue.MaximumJournalSize = value;
267 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
268 [TypeConverter (typeof(SizeConverter))]
269 [MessagingDescription ("MQ_MaximumQueueSize")]
270 public long MaximumQueueSize {
272 return delegateQueue.MaximumQueueSize;
275 delegateQueue.MaximumQueueSize = value;
280 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
281 [MessagingDescription ("MQ_MessageReadPropertyFilter")]
282 public MessagePropertyFilter MessageReadPropertyFilter {
284 return messageReadPropertyFilter;
287 messageReadPropertyFilter = value;
291 [RecommendedAsConfigurable (true)]
292 [Editor ("System.Messaging.Design.QueuePathEditor", "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
295 [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
296 [MessagingDescription ("MQ_Path")]
299 return delegateQueue.QRef.ToString ();
302 delegateQueue.QRef = QueueReference.Parse (value);
307 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
308 [MessagingDescription ("MQ_QueueName")]
309 public string QueueName {
311 return delegateQueue.QRef.Queue;
314 delegateQueue.QRef = delegateQueue.QRef.SetQueue (value);
319 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
320 [MessagingDescription ("MQ_ReadHandle")]
321 public IntPtr ReadHandle {
323 return delegateQueue.ReadHandle;
328 [DefaultValue (null)]
329 [MessagingDescription ("MQ_SynchronizingObject")]
330 public ISynchronizeInvoke SynchronizingObject {
332 return delegateQueue.SynchronizingObject;
335 delegateQueue.SynchronizingObject = value;
339 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
340 [MessagingDescription ("MQ_Transactional")]
341 public bool Transactional {
343 return delegateQueue.Transactional;
347 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
348 [MessagingDescription ("MQ_WriteHandle")]
349 public bool UseJournalQueue {
351 return delegateQueue.UseJournalQueue;
354 delegateQueue.UseJournalQueue = value;
359 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
360 [MessagingDescription ("MQ_WriteHandle")]
361 public IntPtr WriteHandle {
363 return delegateQueue.WriteHandle;
367 internal IMessageQueue DelegateQueue {
369 return delegateQueue;
373 #endregion //Properties
377 public IAsyncResult BeginPeek ()
379 return delegateQueue.BeginPeek ();
382 public IAsyncResult BeginPeek (TimeSpan timeout)
384 return delegateQueue.BeginPeek (timeout);
387 public IAsyncResult BeginPeek (TimeSpan timeout, object stateObject)
389 return delegateQueue.BeginPeek (timeout, stateObject);
392 public IAsyncResult BeginPeek (TimeSpan timeout,
394 AsyncCallback callback)
396 return delegateQueue.BeginPeek (timeout, stateObject, callback);
399 public IAsyncResult BeginReceive ()
401 return delegateQueue.BeginReceive ();
404 public IAsyncResult BeginReceive (TimeSpan timeout)
406 return delegateQueue.BeginReceive (timeout);
409 public IAsyncResult BeginReceive (TimeSpan timeout, object stateObject)
411 return delegateQueue.BeginReceive (timeout, stateObject);
414 public IAsyncResult BeginReceive (TimeSpan timeout, object stateObject, AsyncCallback callback)
416 return delegateQueue.BeginReceive (timeout, stateObject, callback);
419 public static void ClearConnectionCache ()
421 throw new NotImplementedException ();
426 delegateQueue.Close ();
429 public static MessageQueue Create (string path)
431 QueueReference qRef = QueueReference.Parse (path);
432 IMessageQueue iMessageQueue = CreateMessageQueue (qRef, false);
433 return new MessageQueue (iMessageQueue);
436 public static MessageQueue Create (string path, bool transactional)
438 QueueReference qRef = QueueReference.Parse (path);
439 IMessageQueue iMessageQueue = CreateMessageQueue (qRef,
441 return new MessageQueue (iMessageQueue);
444 public static void Delete (string path)
446 QueueReference qRef = QueueReference.Parse (path);
447 MessagingProviderLocator.GetProvider ().DeleteQueue (qRef);
450 public Message EndPeek (IAsyncResult asyncResult)
452 if (asyncResult == null)
453 throw new ArgumentNullException ();
456 IMessage iMsg = delegateQueue.EndPeek (asyncResult);
460 return new Message (iMsg, null, Formatter);
462 } catch (ConnectionException e) {
463 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
464 } catch (MessageUnavailableException e) {
465 throw new InvalidOperationException (e.Message, e);
466 } catch (MonoMessagingException e) {
467 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
471 public Message EndReceive (IAsyncResult asyncResult)
473 if (asyncResult == null)
474 throw new ArgumentNullException ();
477 IMessage iMsg = delegateQueue.EndReceive (asyncResult);
481 return new Message (iMsg, null, Formatter);
483 } catch (ConnectionException e) {
484 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
485 } catch (MessageUnavailableException e) {
486 throw new InvalidOperationException (e.Message, e);
487 } catch (MonoMessagingException e) {
488 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
492 public static bool Exists (string path)
494 return Exists (QueueReference.Parse (path));
497 public Message[] GetAllMessages ()
499 throw new NotImplementedException ();
502 public IEnumerator GetEnumerator ()
504 return GetMessageEnumerator ();
507 public static Guid GetMachineId (string machineName)
509 throw new NotImplementedException ();
512 public MessageEnumerator GetMessageEnumerator ()
514 return new MessageEnumerator (delegateQueue.GetMessageEnumerator (), Formatter);
517 public static MessageQueueEnumerator GetMessageQueueEnumerator ()
519 throw new NotImplementedException ();
522 private static ArrayList filteredQueueList (MessageQueueCriteria criteria)
524 throw new NotImplementedException ();
527 public static MessageQueueEnumerator GetMessageQueueEnumerator (MessageQueueCriteria criteria)
529 throw new NotImplementedException ();
532 public static MessageQueue[] GetPrivateQueuesByMachine (string machineName)
534 throw new NotImplementedException ();
537 public static MessageQueue[] GetPublicQueues ()
539 IMessagingProvider provider = MessagingProviderLocator.GetProvider ();
540 IMessageQueue[] imqs = provider.GetPublicQueues ();
541 MessageQueue[] mqs = new MessageQueue[imqs.Length];
542 for (int i = 0; i < imqs.Length; i++)
543 mqs[i] = new MessageQueue (imqs[i]);
547 public static MessageQueue[] GetPublicQueues (MessageQueueCriteria criteria)
549 throw new NotImplementedException ();
552 public static MessageQueue[] GetPublicQueuesByCategory (Guid category)
554 throw new NotImplementedException ();
557 public static MessageQueue[] GetPublicQueuesByLabel (string label)
559 throw new NotImplementedException ();
562 public static MessageQueue[] GetPublicQueuesByMachine (string machineName)
564 throw new NotImplementedException ();
567 public Message Peek ()
570 IMessage iMsg = delegateQueue.Peek ();
574 return new Message (iMsg, null, Formatter);
576 } catch (ConnectionException e) {
577 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
578 } catch (MessageUnavailableException e) {
579 throw new InvalidOperationException (e.Message, e);
580 } catch (MonoMessagingException e) {
581 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
585 public Message Peek (TimeSpan timeout)
588 IMessage iMsg = delegateQueue.Peek (timeout);
592 return new Message (iMsg, null, Formatter);
594 } catch (ConnectionException e) {
595 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
596 } catch (MessageUnavailableException e) {
597 throw new InvalidOperationException (e.Message, e);
598 } catch (MonoMessagingException e) {
599 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
603 public Message PeekByCorrelationId (string correlationId)
606 IMessage iMsg = delegateQueue.PeekByCorrelationId (correlationId);
610 return new Message (iMsg, null, Formatter);
612 } catch (ConnectionException e) {
613 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
614 } catch (MessageUnavailableException e) {
615 throw new InvalidOperationException (e.Message, e);
616 } catch (MonoMessagingException e) {
617 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
621 public Message PeekByCorrelationId (string correlationId, TimeSpan timeout)
624 IMessage iMsg = delegateQueue.PeekByCorrelationId (correlationId, timeout);
628 return new Message (iMsg, null, Formatter);
630 } catch (ConnectionException e) {
631 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
632 } catch (MessageUnavailableException e) {
633 throw new InvalidOperationException (e.Message, e);
634 } catch (MonoMessagingException e) {
635 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
639 public Message PeekById (string id)
642 IMessage iMsg = delegateQueue.PeekById (id);
646 return new Message (iMsg, null, Formatter);
648 } catch (ConnectionException e) {
649 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
650 } catch (MessageUnavailableException e) {
651 throw new InvalidOperationException (e.Message, e);
652 } catch (MonoMessagingException e) {
653 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
657 public Message PeekById (string id, TimeSpan timeout)
660 IMessage iMsg = delegateQueue.PeekById (id, timeout);
664 return new Message (iMsg, null, Formatter);
666 } catch (ConnectionException e) {
667 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
668 } catch (MessageUnavailableException e) {
669 throw new InvalidOperationException (e.Message, e);
670 } catch (MonoMessagingException e) {
671 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
677 delegateQueue.Purge ();
680 public Message Receive ()
683 IMessage iMsg = delegateQueue.Receive ();
687 return new Message (iMsg, null, Formatter);
689 } catch (ConnectionException e) {
690 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
691 } catch (MonoMessagingException e) {
692 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
696 public Message Receive (MessageQueueTransaction transaction)
699 IMessage iMsg = delegateQueue.Receive (transaction.DelegateTx);
703 return new Message (iMsg, null, Formatter);
705 } catch (ConnectionException e) {
706 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
707 } catch (MessageUnavailableException e) {
708 throw new InvalidOperationException (e.Message, e);
709 } catch (MonoMessagingException e) {
710 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
714 public Message Receive (MessageQueueTransactionType transactionType)
717 IMessage iMsg = delegateQueue.Receive ((Mono.Messaging.MessageQueueTransactionType) transactionType);
721 return new Message (iMsg, null, Formatter);
723 } catch (ConnectionException e) {
724 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
725 } catch (MessageUnavailableException e) {
726 throw new InvalidOperationException (e.Message, e);
727 } catch (MonoMessagingException e) {
728 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
732 public Message Receive (TimeSpan timeout)
735 IMessage iMsg = delegateQueue.Receive (timeout);
739 return new Message (iMsg, null, Formatter);
741 } catch (ConnectionException e) {
742 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
743 } catch (MessageUnavailableException e) {
744 throw new InvalidOperationException (e.Message, e);
745 } catch (MonoMessagingException e) {
746 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
750 public Message Receive (TimeSpan timeout, MessageQueueTransaction transaction)
753 IMessage iMsg = delegateQueue.Receive (timeout, transaction.DelegateTx);
757 return new Message (iMsg, null, Formatter);
759 } catch (ConnectionException e) {
760 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
761 } catch (MessageUnavailableException e) {
762 throw new InvalidOperationException (e.Message, e);
763 } catch (MonoMessagingException e) {
764 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
768 public Message Receive (TimeSpan timeout, MessageQueueTransactionType transactionType)
771 IMessage iMsg = delegateQueue.Receive (timeout,
772 (Mono.Messaging.MessageQueueTransactionType) transactionType);
776 return new Message (iMsg, null, Formatter);
778 } catch (ConnectionException e) {
779 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
780 } catch (MessageUnavailableException e) {
781 throw new InvalidOperationException (e.Message, e);
782 } catch (MonoMessagingException e) {
783 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
787 public Message ReceiveByCorrelationId (string correlationId)
790 IMessage iMsg = delegateQueue.ReceiveByCorrelationId (correlationId);
794 return new Message (iMsg, null, Formatter);
796 } catch (ConnectionException e) {
797 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
798 } catch (MessageUnavailableException e) {
799 throw new InvalidOperationException (e.Message, e);
800 } catch (MonoMessagingException e) {
801 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
805 public Message ReceiveByCorrelationId (string correlationId, MessageQueueTransaction transaction)
808 IMessage iMsg = delegateQueue.ReceiveByCorrelationId (correlationId, transaction.DelegateTx);
812 return new Message (iMsg, null, Formatter);
814 } catch (ConnectionException e) {
815 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
816 } catch (MessageUnavailableException e) {
817 throw new InvalidOperationException (e.Message, e);
818 } catch (MonoMessagingException e) {
819 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
823 public Message ReceiveByCorrelationId (string correlationId, MessageQueueTransactionType transactionType)
826 IMessage iMsg = delegateQueue.ReceiveByCorrelationId (correlationId, (Mono.Messaging.MessageQueueTransactionType) transactionType);
830 return new Message (iMsg, null, Formatter);
832 } catch (ConnectionException e) {
833 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
834 } catch (MessageUnavailableException e) {
835 throw new InvalidOperationException (e.Message, e);
836 } catch (MonoMessagingException e) {
837 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
841 public Message ReceiveByCorrelationId (string correlationId, TimeSpan timeout)
844 IMessage iMsg = delegateQueue.ReceiveByCorrelationId (correlationId,
849 return new Message (iMsg, null, Formatter);
851 } catch (ConnectionException e) {
852 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
853 } catch (MessageUnavailableException e) {
854 throw new InvalidOperationException (e.Message, e);
855 } catch (MonoMessagingException e) {
856 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
860 public Message ReceiveByCorrelationId (string correlationId, TimeSpan timeout, MessageQueueTransaction transaction)
863 IMessage iMsg = delegateQueue.ReceiveByCorrelationId (correlationId, timeout, transaction.DelegateTx);
867 return new Message (iMsg, null, Formatter);
869 } catch (ConnectionException e) {
870 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
871 } catch (MessageUnavailableException e) {
872 throw new InvalidOperationException (e.Message, e);
873 } catch (MonoMessagingException e) {
874 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
878 public Message ReceiveByCorrelationId (string correlationId, TimeSpan timeout, MessageQueueTransactionType transactionType)
881 IMessage iMsg = delegateQueue.ReceiveByCorrelationId (correlationId, timeout, (Mono.Messaging.MessageQueueTransactionType) transactionType);
885 return new Message (iMsg, null, Formatter);
887 } catch (ConnectionException e) {
888 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
889 } catch (MessageUnavailableException e) {
890 throw new InvalidOperationException (e.Message, e);
891 } catch (MonoMessagingException e) {
892 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
896 public Message ReceiveById (string id)
899 IMessage iMsg = delegateQueue.ReceiveById (id);
903 return new Message (iMsg, null, Formatter);
905 } catch (ConnectionException e) {
906 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
907 } catch (MessageUnavailableException e) {
908 throw new InvalidOperationException (e.Message, e);
909 } catch (MonoMessagingException e) {
910 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
914 public Message ReceiveById (string id, MessageQueueTransaction transaction)
917 IMessage iMsg = delegateQueue.ReceiveById (id, transaction.DelegateTx);
921 return new Message (iMsg, null, Formatter);
923 } catch (ConnectionException e) {
924 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
925 } catch (MessageUnavailableException e) {
926 throw new InvalidOperationException (e.Message, e);
927 } catch (MonoMessagingException e) {
928 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
932 public Message ReceiveById (string id, MessageQueueTransactionType transactionType)
935 IMessage iMsg = delegateQueue.ReceiveById (id, (Mono.Messaging.MessageQueueTransactionType) transactionType);
939 return new Message (iMsg, null, Formatter);
941 } catch (ConnectionException e) {
942 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
943 } catch (MessageUnavailableException e) {
944 throw new InvalidOperationException (e.Message, e);
945 } catch (MonoMessagingException e) {
946 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
950 public Message ReceiveById (string id, TimeSpan timeout)
953 IMessage iMsg = delegateQueue.ReceiveById (id, timeout);
957 return new Message (iMsg, null, Formatter);
959 } catch (ConnectionException e) {
960 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
961 } catch (MessageUnavailableException e) {
962 throw new InvalidOperationException (e.Message, e);
963 } catch (MonoMessagingException e) {
964 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
968 public Message ReceiveById (string id, TimeSpan timeout, MessageQueueTransaction transaction)
971 IMessage iMsg = delegateQueue.ReceiveById (id, timeout, transaction.DelegateTx);
975 return new Message (iMsg, null, Formatter);
977 } catch (ConnectionException e) {
978 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
979 } catch (MessageUnavailableException e) {
980 throw new InvalidOperationException (e.Message, e);
981 } catch (MonoMessagingException e) {
982 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
986 public Message ReceiveById (string id, TimeSpan timeout, MessageQueueTransactionType transactionType)
989 IMessage iMsg = delegateQueue.ReceiveById (id, timeout, (Mono.Messaging.MessageQueueTransactionType) transactionType);
993 return new Message (iMsg, null, Formatter);
995 } catch (ConnectionException e) {
996 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
997 } catch (MessageUnavailableException e) {
998 throw new InvalidOperationException (e.Message, e);
999 } catch (MonoMessagingException e) {
1000 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
1004 public void Refresh ()
1006 throw new NotImplementedException ();
1009 public void ResetPermissions ()
1011 throw new NotImplementedException ();
1014 public void Send (object obj)
1016 if (typeof (Message) == obj.GetType ()) {
1017 Message m = (Message) obj;
1018 if (m.BodyStream == null) {
1019 IMessageFormatter f = (m.Formatter == null) ? Formatter : m.Formatter;
1020 f.Write (m, m.Body);
1024 delegateQueue.Send (m.DelegateMessage);
1025 } catch (ConnectionException e) {
1026 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
1027 } catch (MonoMessagingException e) {
1028 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
1031 Message m = new Message (obj);
1036 public void Send (object obj, MessageQueueTransaction transaction)
1038 if (typeof (Message) == obj.GetType ()) {
1039 Message m = (Message) obj;
1040 if (m.BodyStream == null) {
1041 IMessageFormatter f = (m.Formatter == null) ? Formatter : m.Formatter;
1042 f.Write (m, m.Body);
1046 delegateQueue.Send (m.DelegateMessage, transaction.DelegateTx);
1047 } catch (ConnectionException e) {
1048 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
1049 } catch (MonoMessagingException e) {
1050 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
1053 Message m = new Message (obj);
1054 Send (m, transaction);
1058 public void Send (object obj, MessageQueueTransactionType transactionType)
1060 if (typeof (Message) == obj.GetType ()) {
1061 Message m = (Message) obj;
1062 if (m.BodyStream == null) {
1063 IMessageFormatter f = (m.Formatter == null) ? Formatter : m.Formatter;
1064 f.Write (m, m.Body);
1068 delegateQueue.Send (m.DelegateMessage, (Mono.Messaging.MessageQueueTransactionType) transactionType);
1069 } catch (ConnectionException e) {
1070 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
1071 } catch (MonoMessagingException e) {
1072 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
1075 Message m = new Message (obj);
1076 Send (m, transactionType);
1080 public void Send (object obj, string label)
1082 if (typeof (Message) == obj.GetType ()) {
1083 Message m = (Message) obj;
1088 Message m = new Message (obj);
1093 public void Send (object obj, string label, MessageQueueTransaction transaction)
1095 if (typeof (Message) == obj.GetType ()) {
1096 Message m = (Message) obj;
1099 if (m.BodyStream == null) {
1100 IMessageFormatter f = (m.Formatter == null) ? Formatter : m.Formatter;
1101 f.Write (m, m.Body);
1105 delegateQueue.Send (m.DelegateMessage, transaction.DelegateTx);
1106 } catch (ConnectionException e) {
1107 throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
1108 } catch (MonoMessagingException e) {
1109 throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
1112 Message m = new Message (obj);
1113 Send (m, label, transaction);
1117 public void Send (object obj, string label, MessageQueueTransactionType transactionType)
1119 if (typeof (Message) == obj.GetType ()) {
1120 Message m = (Message) obj;
1122 Send (m, transactionType);
1124 Message m = new Message (obj);
1125 Send (m, label, transactionType);
1129 public void SetPermissions (AccessControlList dacl)
1131 throw new NotImplementedException ();
1134 public void SetPermissions (MessageQueueAccessControlEntry ace)
1136 throw new NotImplementedException ();
1139 public void SetPermissions (string user, MessageQueueAccessRights rights)
1141 throw new NotImplementedException ();
1144 public void SetPermissions (string user, MessageQueueAccessRights rights, AccessControlEntryType entryType)
1146 throw new NotImplementedException ();
1149 protected override void Dispose (bool disposing)
1151 //delegateQueue.Dispose ();
1154 #endregion //Methods
1156 [MessagingDescription ("MQ_PeekCompleted")]
1157 public event PeekCompletedEventHandler PeekCompleted;
1159 private void DelegatePeekCompleted (object sender, CompletedEventArgs args)
1161 if (PeekCompleted == null)
1164 PeekCompletedEventArgs newArgs = new PeekCompletedEventArgs (this, args.AsyncResult);
1165 PeekCompleted (sender, newArgs);
1168 [MessagingDescription ("MQ_ReceiveCompleted")]
1169 public event ReceiveCompletedEventHandler ReceiveCompleted;
1171 private void DelegateReceiveCompleted (object sender, CompletedEventArgs args)
1173 if (ReceiveCompleted == null)
1176 ReceiveCompletedEventArgs newArgs = new ReceiveCompletedEventArgs (this, args.AsyncResult);
1177 ReceiveCompleted (sender, newArgs);
1180 private static IMessageQueue GetMessageQueue (string path)
1182 QueueReference qRef = QueueReference.Parse (path);
1183 IMessageQueue q = MessagingProviderLocator
1185 .GetMessageQueue (qRef);
1189 private static IMessageQueue GetMessageQueue ()
1191 return MessagingProviderLocator.GetProvider ()
1192 .GetMessageQueue (QueueReference.DEFAULT);
1195 private static IMessageQueue CreateMessageQueue (QueueReference qRef,
1198 return MessagingProviderLocator.GetProvider ()
1199 .CreateMessageQueue (qRef, transactional);
1202 private static bool Exists (QueueReference qRef)
1204 return MessagingProviderLocator.GetProvider ().Exists (qRef);