oops, forgot to apply the patch here in bug #457089 by Michael Barker.
authorAtsushi Eno <atsushieno@gmail.com>
Mon, 8 Dec 2008 07:06:43 +0000 (07:06 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Mon, 8 Dec 2008 07:06:43 +0000 (07:06 -0000)
svn path=/branches/messaging-2008/mcs/; revision=120980

mcs/class/System.Messaging/System.Messaging/ChangeLog
mcs/class/System.Messaging/System.Messaging/MessageEnumerator.cs
mcs/class/System.Messaging/System.Messaging/MessageQueue.cs
mcs/class/System.Messaging/System.Messaging/MessageQueueTransaction.cs

index c8be70c581e5d180dafafb42550d99eeaa1aa978..657588ebdd3e90bfb6c13c23fe8f08e31b47f63a 100644 (file)
@@ -1,3 +1,18 @@
+2008-11-23  Michael Barker  <mike@middlesoft.co.uk>
+
+       * MessageQueue.cs:  Added support for MessageQueueTransactionType methods, 
+       ReceiveBy{Id,CorrelationId} and PeekBy{Id,CorrelationId} methods.
+
+2008-11-02  Michael Barker  <mike@middlesoft.co.uk>
+
+       * MessageQueue.cs:  Added implementation for deleting, purging, sending with
+       labels and message transactions.
+
+2008-10-27  Michael Barker  <mike@middlesoft.co.uk>
+
+       * MessageQueueTransaction.cs:  Delegated all methods to IMessageQueueTransaction
+       from Mono.Messaging.
+
 2008-10-12  Michael Barker  <mike@middlesoft.co.uk>
 
        * MessageQueue.cs:  Implemented GetMessageEnumerator().
index 5d870f23ca2a5d9f7354348d09a71698d624e752..a890b5ec8bd824e087b726b90a17c0f70b64b924 100644 (file)
@@ -98,17 +98,24 @@ namespace System.Messaging
                        IMessage iMsg = delegateEnumerator.RemoveCurrent ();
                        if (iMsg == null)
                                return null;
-                       return new Message (iMsg);
+                       return new Message (iMsg, null, formatter);
                }
-               [MonoTODO]
-               public Message RemoveCurrent(MessageQueueTransaction transaction)
+
+               public Message RemoveCurrent (MessageQueueTransaction transaction)
                {
-                       throw new NotImplementedException();
+                       
+                       IMessage iMsg = delegateEnumerator.RemoveCurrent (transaction.DelegateTx);
+                       if (iMsg == null)
+                               return null;
+                       return new Message (iMsg, null, formatter);
                }
-               [MonoTODO]
+
                public Message RemoveCurrent(MessageQueueTransactionType transactionType)
                {
-                       throw new NotImplementedException();
+                       IMessage iMsg = delegateEnumerator.RemoveCurrent ((Mono.Messaging.MessageQueueTransactionType) transactionType);
+                       if (iMsg == null)
+                               return null;
+                       return new Message (iMsg, null, formatter);
                }
                [MonoTODO]
                public Message RemoveCurrent(TimeSpan timeout)
index d118f98cf18b086d2584fd5b4e036f544c904c6d..61918a526af84e1adc8d7bc749b4d2e624360b2f 100644 (file)
@@ -51,7 +51,7 @@ namespace System.Messaging
                public static readonly long InfiniteQueueSize;
                public static readonly TimeSpan InfiniteTimeout;
                private IMessageFormatter formatter;
-
+               private MessagePropertyFilter messageReadPropertyFilter = new MessagePropertyFilter ();
                private readonly IMessageQueue delegateQueue;
 
                #endregion //Fields
@@ -59,17 +59,14 @@ namespace System.Messaging
 
                #region Constructor
 
-               [MonoTODO]
                public MessageQueue () : this (GetMessageQueue ())
                {
                }
 
-               [MonoTODO]
                public MessageQueue (string path) : this (path, false) 
                {
                }
 
-               [MonoTODO]
                public MessageQueue (string path, bool sharedModeDenyReceive) : 
                        this (GetMessageQueue (path))
                {
@@ -281,13 +278,11 @@ namespace System.Messaging
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
                [MessagingDescription ("MQ_MessageReadPropertyFilter")]
                public MessagePropertyFilter MessageReadPropertyFilter {
-                       [MonoTODO]
                        get {
-                               throw new NotImplementedException ();
+                               return messageReadPropertyFilter;
                        }
-                       [MonoTODO]
                        set {
-                               throw new NotImplementedException ();
+                               messageReadPropertyFilter = value;
                        }
                }
 
@@ -424,27 +419,31 @@ namespace System.Messaging
                {
                        throw new NotImplementedException ();
                }
-               [MonoTODO]
+
                public void Close ()
                {
-                       throw new NotImplementedException ();
+                       delegateQueue.Close ();
                }
 
                public static MessageQueue Create (string path)
                {
                        QueueReference qRef = QueueReference.Parse (path);
-                       IMessageQueue iMessageQueue = CreateMessageQueue (qRef);
+                       IMessageQueue iMessageQueue = CreateMessageQueue (qRef, false);
                        return new MessageQueue (iMessageQueue);
                }
-               [MonoTODO]
+
                public static MessageQueue Create (string path, bool transactional)
                {
-                       throw new NotImplementedException ();
+                       QueueReference qRef = QueueReference.Parse (path);
+                       IMessageQueue iMessageQueue = CreateMessageQueue (qRef,
+                                                                         transactional);
+                       return new MessageQueue (iMessageQueue);
                }
-               [MonoTODO]
+
                public static void Delete (string path)
                {
-                       throw new NotImplementedException ();
+                       QueueReference qRef = QueueReference.Parse (path);
+                       MessagingProviderLocator.GetProvider ().DeleteQueue (qRef);
                }
                [MonoTODO]
                public Message EndPeek (IAsyncResult asyncResult)
@@ -466,10 +465,10 @@ namespace System.Messaging
                {
                        throw new NotImplementedException ();
                }
-               [MonoTODO]
+
                public IEnumerator GetEnumerator ()
                {
-                       throw new NotImplementedException ();
+                       return GetMessageEnumerator ();
                }
                [MonoTODO]
                public static Guid GetMachineId (string machineName)
@@ -481,45 +480,35 @@ namespace System.Messaging
                {
                        return new MessageEnumerator (delegateQueue.GetMessageEnumerator (), Formatter);
                }
-
-               private static ArrayList currentQueueList;
-
-               static MessageQueue ()
-               {
-                       currentQueueList = new ArrayList ();
-                       // for testing purposes
-                       //currentQueueList.Add (new MessageQueue (@"localhost:\public\TestQueue"));
-                       //currentQueueList.Add (new MessageQueue (@"\private\AnotherTestQueue", "localhost", true));
-               }
-
+               [MonoTODO]
                public static MessageQueueEnumerator GetMessageQueueEnumerator ()
                {
-                       return new MessageQueueEnumerator (currentQueueList);
+                       throw new NotImplementedException ();
                }
-
+               [MonoTODO]
                private static ArrayList filteredQueueList (MessageQueueCriteria criteria)
                {
-                       ArrayList list = new ArrayList ();
-                       foreach (MessageQueue queue in currentQueueList)
-                               if (criteria.Match (queue.Id, queue.CreateTime, queue.Label, queue.MachineName, queue.LastModifyTime))
-                                       list.Add (queue);
-                       return list;
+                       throw new NotImplementedException ();
                }
-
+               [MonoTODO]
                public static MessageQueueEnumerator GetMessageQueueEnumerator (MessageQueueCriteria criteria)
                {
-                       return new MessageQueueEnumerator (filteredQueueList (criteria));
+                       throw new NotImplementedException ();
                }
-
+               [MonoTODO]
                public static MessageQueue[] GetPrivateQueuesByMachine (string machineName)
                {
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                public static MessageQueue[] GetPublicQueues ()
                {
-                       throw new NotImplementedException ();
+                       IMessagingProvider provider = MessagingProviderLocator.GetProvider ();
+                       IMessageQueue[] imqs = provider.GetPublicQueues ();
+                       MessageQueue[] mqs = new MessageQueue[imqs.Length];
+                       for (int i = 0; i < imqs.Length; i++)
+                               mqs[i] = new MessageQueue (imqs[i]);
+                       return mqs;
                }
                [MonoTODO]
                public static MessageQueue[] GetPublicQueues (MessageQueueCriteria criteria)
@@ -541,46 +530,127 @@ namespace System.Messaging
                {
                        throw new NotImplementedException ();
                }
-               [MonoTODO]
+
                public Message Peek ()
                {
-                       throw new NotImplementedException ();
+                       try {
+                               IMessage iMsg = delegateQueue.Peek ();
+                               if (iMsg == null)
+                                       return null;
+                               
+                               return new Message (iMsg, null, Formatter);
+                               
+                       } catch (ConnectionException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
+                       } catch (MessageUnavailableException e) {
+                               throw new InvalidOperationException (e.Message, e);
+                       } catch (MonoMessagingException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
+                       }                       
                }
-               [MonoTODO]
+
                public Message Peek (TimeSpan timeout)
                {
-                       throw new NotImplementedException ();
+                       try {
+                               IMessage iMsg = delegateQueue.Peek (timeout);
+                               if (iMsg == null)
+                                       return null;
+                               
+                               return new Message (iMsg, null, Formatter);
+                               
+                       } catch (ConnectionException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
+                       } catch (MessageUnavailableException e) {
+                               throw new InvalidOperationException (e.Message, e);
+                       } catch (MonoMessagingException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
+                       }                       
                }
-               [MonoTODO]
+
                public Message PeekByCorrelationId (string correlationId)
                {
-                       throw new NotImplementedException ();
+                       try {
+                               IMessage iMsg = delegateQueue.PeekByCorrelationId (correlationId);
+                               if (iMsg == null)
+                                       return null;
+                               
+                               return new Message (iMsg, null, Formatter);
+                               
+                       } catch (ConnectionException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
+                       } catch (MessageUnavailableException e) {
+                               throw new InvalidOperationException (e.Message, e);
+                       } catch (MonoMessagingException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
+                       }                       
                }
-               [MonoTODO]
+
                public Message PeekByCorrelationId (string correlationId, TimeSpan timeout)
                {
-                       throw new NotImplementedException ();
+                       try {
+                               IMessage iMsg = delegateQueue.PeekByCorrelationId (correlationId, timeout);
+                               if (iMsg == null)
+                                       return null;
+                               
+                               return new Message (iMsg, null, Formatter);
+                               
+                       } catch (ConnectionException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
+                       } catch (MessageUnavailableException e) {
+                               throw new InvalidOperationException (e.Message, e);
+                       } catch (MonoMessagingException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
+                       }                       
                }
-               [MonoTODO]
+
                public Message PeekById (string id)
                {
-                       throw new NotImplementedException ();
+                       try {
+                               IMessage iMsg = delegateQueue.PeekById (id);
+                               if (iMsg == null)
+                                       return null;
+                               
+                               return new Message (iMsg, null, Formatter);
+                               
+                       } catch (ConnectionException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
+                       } catch (MessageUnavailableException e) {
+                               throw new InvalidOperationException (e.Message, e);
+                       } catch (MonoMessagingException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
+                       }                       
                }
-               [MonoTODO]
+
                public Message PeekById (string id, TimeSpan timeout)
                {
-                       throw new NotImplementedException ();
+                       try {
+                               IMessage iMsg = delegateQueue.PeekById (id, timeout);
+                               if (iMsg == null)
+                                       return null;
+                               
+                               return new Message (iMsg, null, Formatter);
+                               
+                       } catch (ConnectionException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
+                       } catch (MessageUnavailableException e) {
+                               throw new InvalidOperationException (e.Message, e);
+                       } catch (MonoMessagingException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
+                       }                       
                }
-               [MonoTODO]
+
                public void Purge ()
                {
-                       throw new NotImplementedException ();
+                       delegateQueue.Purge ();
                }
 
                public Message Receive ()
                {
                        try {
                                IMessage iMsg = delegateQueue.Receive ();
+                               if (iMsg == null)
+                                       return null;
+                               
                                return new Message (iMsg, null, Formatter);
                                
                        } catch (ConnectionException e) {
@@ -589,90 +659,313 @@ namespace System.Messaging
                                throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
                        }
                }
-               [MonoTODO]
+
                public Message Receive (MessageQueueTransaction transaction)
                {
-                       throw new NotImplementedException ();
+                       try {
+                               IMessage iMsg = delegateQueue.Receive (transaction.DelegateTx);
+                               if (iMsg == null)
+                                       return null;
+                               
+                               return new Message (iMsg, null, Formatter);
+                               
+                       } catch (ConnectionException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
+                       } catch (MessageUnavailableException e) {
+                               throw new InvalidOperationException (e.Message, e);
+                       } catch (MonoMessagingException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
+                       }
                }
-               [MonoTODO]
+
                public Message Receive (MessageQueueTransactionType transactionType)
                {
-                       throw new NotImplementedException ();
+                       try {
+                               IMessage iMsg = delegateQueue.Receive ((Mono.Messaging.MessageQueueTransactionType) transactionType);
+                               if (iMsg == null)
+                                       return null;
+                               
+                               return new Message (iMsg, null, Formatter);
+                               
+                       } catch (ConnectionException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
+                       } catch (MessageUnavailableException e) {
+                               throw new InvalidOperationException (e.Message, e);
+                       } catch (MonoMessagingException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
+                       }
                }
-               [MonoTODO]
+               
                public Message Receive (TimeSpan timeout)
                {
-                       throw new NotImplementedException ();
+                       try {
+                               IMessage iMsg = delegateQueue.Receive (timeout);
+                               if (iMsg == null)
+                                       return null;
+                               
+                               return new Message (iMsg, null, Formatter);
+                               
+                       } catch (ConnectionException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
+                       } catch (MessageUnavailableException e) {
+                               throw new InvalidOperationException (e.Message, e);
+                       } catch (MonoMessagingException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
+                       }
                }
-               [MonoTODO]
+
                public Message Receive (TimeSpan timeout, MessageQueueTransaction transaction)
                {
-                       throw new NotImplementedException ();
+                       try {
+                               IMessage iMsg = delegateQueue.Receive (timeout, transaction.DelegateTx);
+                               if (iMsg == null)
+                                       return null;
+                               
+                               return new Message (iMsg, null, Formatter);
+                               
+                       } catch (ConnectionException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
+                       } catch (MessageUnavailableException e) {
+                               throw new InvalidOperationException (e.Message, e);
+                       } catch (MonoMessagingException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
+                       }
                }
-               [MonoTODO]
+
                public Message Receive (TimeSpan timeout, MessageQueueTransactionType transactionType)
                {
-                       throw new NotImplementedException ();
+                       try {
+                               IMessage iMsg = delegateQueue.Receive (timeout, 
+                                                                      (Mono.Messaging.MessageQueueTransactionType) transactionType);
+                               if (iMsg == null)
+                                       return null;
+                               
+                               return new Message (iMsg, null, Formatter);
+                               
+                       } catch (ConnectionException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
+                       } catch (MessageUnavailableException e) {
+                               throw new InvalidOperationException (e.Message, e);
+                       } catch (MonoMessagingException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
+                       }
                }
-               [MonoTODO]
+
                public Message ReceiveByCorrelationId (string correlationId)
                {
-                       throw new NotImplementedException ();
+                       try {
+                               IMessage iMsg = delegateQueue.ReceiveByCorrelationId (correlationId);
+                               if (iMsg == null)
+                                       return null;
+                               
+                               return new Message (iMsg, null, Formatter);
+
+                       } catch (ConnectionException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
+                       } catch (MessageUnavailableException e) {
+                               throw new InvalidOperationException (e.Message, e);
+                       } catch (MonoMessagingException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
+                       }
                }
-               [MonoTODO]
+
                public Message ReceiveByCorrelationId (string correlationId, MessageQueueTransaction transaction)
                {
-                       throw new NotImplementedException ();
+                       try {
+                               IMessage iMsg = delegateQueue.ReceiveByCorrelationId (correlationId, transaction.DelegateTx);
+                               if (iMsg == null)
+                                       return null;
+                               
+                               return new Message (iMsg, null, Formatter);
+                               
+                       } catch (ConnectionException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
+                       } catch (MessageUnavailableException e) {
+                               throw new InvalidOperationException (e.Message, e);
+                       } catch (MonoMessagingException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
+                       }                       
                }
-               [MonoTODO]
+
                public Message ReceiveByCorrelationId (string correlationId, MessageQueueTransactionType transactionType)
                {
-                       throw new NotImplementedException ();
+                       try {
+                               IMessage iMsg = delegateQueue.ReceiveByCorrelationId (correlationId, (Mono.Messaging.MessageQueueTransactionType) transactionType);
+                               if (iMsg == null)
+                                       return null;
+
+                               return new Message (iMsg, null, Formatter);
+
+                       } catch (ConnectionException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
+                       } catch (MessageUnavailableException e) {
+                               throw new InvalidOperationException (e.Message, e);
+                       } catch (MonoMessagingException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
+                       }
                }
-               [MonoTODO]
+
                public Message ReceiveByCorrelationId (string correlationId, TimeSpan timeout)
                {
-                       throw new NotImplementedException ();
+                       try {
+                               IMessage iMsg = delegateQueue.ReceiveByCorrelationId (correlationId, 
+                                                                                     timeout);
+                               if (iMsg == null)
+                                       return null;
+                               
+                               return new Message (iMsg, null, Formatter);
+                               
+                       } catch (ConnectionException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
+                       } catch (MessageUnavailableException e) {
+                               throw new InvalidOperationException (e.Message, e);
+                       } catch (MonoMessagingException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
+                       }
                }
-               [MonoTODO]
+
                public Message ReceiveByCorrelationId (string correlationId, TimeSpan timeout, MessageQueueTransaction transaction)
                {
-                       throw new NotImplementedException ();
+                       try {
+                               IMessage iMsg = delegateQueue.ReceiveByCorrelationId (correlationId, timeout, transaction.DelegateTx);
+                               if (iMsg == null)
+                                       return null;
+
+                               return new Message (iMsg, null, Formatter);
+
+                       } catch (ConnectionException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
+                       } catch (MessageUnavailableException e) {
+                               throw new InvalidOperationException (e.Message, e);
+                       } catch (MonoMessagingException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
+                       }
                }
-               [MonoTODO]
+
                public Message ReceiveByCorrelationId (string correlationId, TimeSpan timeout, MessageQueueTransactionType transactionType)
                {
-                       throw new NotImplementedException ();
+                       try {
+                               IMessage iMsg = delegateQueue.ReceiveByCorrelationId (correlationId, timeout, (Mono.Messaging.MessageQueueTransactionType) transactionType);
+                               if (iMsg == null)
+                                       return null;
+
+                               return new Message (iMsg, null, Formatter);
+
+                       } catch (ConnectionException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
+                       } catch (MessageUnavailableException e) {
+                               throw new InvalidOperationException (e.Message, e);
+                       } catch (MonoMessagingException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
+                       }
                }
-               [MonoTODO]
+
                public Message ReceiveById (string id)
                {
-                       throw new NotImplementedException ();
+                       try {
+                               IMessage iMsg = delegateQueue.ReceiveById (id);
+                               if (iMsg == null)
+                                       return null;
+
+                               return new Message (iMsg, null, Formatter);
+
+                       } catch (ConnectionException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
+                       } catch (MessageUnavailableException e) {
+                               throw new InvalidOperationException (e.Message, e);
+                       } catch (MonoMessagingException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
+                       }
                }
-               [MonoTODO]
+
                public Message ReceiveById (string id, MessageQueueTransaction transaction)
                {
-                       throw new NotImplementedException ();
+                       try {
+                               IMessage iMsg = delegateQueue.ReceiveById (id, transaction.DelegateTx);
+                               if (iMsg == null)
+                                       return null;
+
+                               return new Message (iMsg, null, Formatter);
+
+                       } catch (ConnectionException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
+                       } catch (MessageUnavailableException e) {
+                               throw new InvalidOperationException (e.Message, e);
+                       } catch (MonoMessagingException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
+                       }
                }
-               [MonoTODO]
+
                public Message ReceiveById (string id, MessageQueueTransactionType transactionType)
                {
-                       throw new NotImplementedException ();
+                       try {
+                               IMessage iMsg = delegateQueue.ReceiveById (id, (Mono.Messaging.MessageQueueTransactionType) transactionType);
+                               if (iMsg == null)
+                                       return null;
+
+                               return new Message (iMsg, null, Formatter);
+
+                       } catch (ConnectionException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
+                       } catch (MessageUnavailableException e) {
+                               throw new InvalidOperationException (e.Message, e);
+                       } catch (MonoMessagingException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
+                       }
                }
-               [MonoTODO]
+
                public Message ReceiveById (string id, TimeSpan timeout)
                {
-                       throw new NotImplementedException ();
+                       try {
+                               IMessage iMsg = delegateQueue.ReceiveById (id, timeout);
+                               if (iMsg == null)
+                                       return null;
+
+                               return new Message (iMsg, null, Formatter);
+
+                       } catch (ConnectionException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
+                       } catch (MessageUnavailableException e) {
+                               throw new InvalidOperationException (e.Message, e);
+                       } catch (MonoMessagingException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
+                       }
                }
-               [MonoTODO]
+
                public Message ReceiveById (string id, TimeSpan timeout, MessageQueueTransaction transaction)
                {
-                       throw new NotImplementedException ();
+                       try {
+                               IMessage iMsg = delegateQueue.ReceiveById (id, timeout, transaction.DelegateTx);
+                               if (iMsg == null)
+                                       return null;
+
+                               return new Message (iMsg, null, Formatter);
+
+                       } catch (ConnectionException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
+                       } catch (MessageUnavailableException e) {
+                               throw new InvalidOperationException (e.Message, e);
+                       } catch (MonoMessagingException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
+                       }
                }
-               [MonoTODO]
+
                public Message ReceiveById (string id, TimeSpan timeout, MessageQueueTransactionType transactionType)
                {
-                       throw new NotImplementedException ();
+                       try {
+                               IMessage iMsg = delegateQueue.ReceiveById (id, timeout, (Mono.Messaging.MessageQueueTransactionType) transactionType);
+                               if (iMsg == null)
+                                       return null;
+
+                               return new Message (iMsg, null, Formatter);
+
+                       } catch (ConnectionException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
+                       } catch (MessageUnavailableException e) {
+                               throw new InvalidOperationException (e.Message, e);
+                       } catch (MonoMessagingException e) {
+                               throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
+                       }
                }
                [MonoTODO]
                public void Refresh ()
@@ -689,7 +982,6 @@ namespace System.Messaging
                {
                        if (typeof (Message) == obj.GetType ()) {
                                Message m = (Message) obj;
-                               Console.WriteLine ("BodyStream {0}", m.BodyStream == null);
                                if (m.BodyStream == null) {
                                        IMessageFormatter f = (m.Formatter == null) ? Formatter : m.Formatter;
                                        f.Write (m, m.Body);
@@ -707,30 +999,98 @@ namespace System.Messaging
                                Send (m);
                        }
                }
-               [MonoTODO]
+
                public void Send (object obj, MessageQueueTransaction transaction)
                {
-                       throw new NotImplementedException ();
+                       if (typeof (Message) == obj.GetType ()) {
+                               Message m = (Message) obj;
+                               if (m.BodyStream == null) {
+                                       IMessageFormatter f = (m.Formatter == null) ? Formatter : m.Formatter;
+                                       f.Write (m, m.Body);
+                               }
+
+                               try {
+                                       delegateQueue.Send (m.DelegateMessage, transaction.DelegateTx);
+                               } catch (ConnectionException e) {
+                                       throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
+                               } catch (MonoMessagingException e) {
+                                       throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
+                               }
+                       } else {
+                               Message m = new Message (obj);
+                               Send (m, transaction);
+                       }
                }
-               [MonoTODO]
+
                public void Send (object obj, MessageQueueTransactionType transactionType)
                {
-                       throw new NotImplementedException ();
+                       if (typeof (Message) == obj.GetType ()) {
+                               Message m = (Message) obj;
+                               if (m.BodyStream == null) {
+                                       IMessageFormatter f = (m.Formatter == null) ? Formatter : m.Formatter;
+                                       f.Write (m, m.Body);
+                               }
+
+                               try {
+                                       delegateQueue.Send (m.DelegateMessage, (Mono.Messaging.MessageQueueTransactionType) transactionType);
+                               } catch (ConnectionException e) {
+                                       throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
+                               } catch (MonoMessagingException e) {
+                                       throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
+                               }
+                       } else {
+                               Message m = new Message (obj);
+                               Send (m, transactionType);
+                       }
                }
-               [MonoTODO]
+
                public void Send (object obj, string label)
                {
-                       throw new NotImplementedException ();
+                       if (typeof (Message) == obj.GetType ()) {
+                               Message m = (Message) obj;
+                               m.Label = label;
+                               
+                               Send (m);
+                       } else {
+                               Message m = new Message (obj);
+                               Send (m, label);
+                       }
                }
-               [MonoTODO]
+
                public void Send (object obj, string label, MessageQueueTransaction transaction)
                {
-                       throw new NotImplementedException ();
+                       if (typeof (Message) == obj.GetType ()) {
+                               Message m = (Message) obj;
+                               m.Label = label;
+                               
+                               if (m.BodyStream == null) {
+                                       IMessageFormatter f = (m.Formatter == null) ? Formatter : m.Formatter;
+                                       f.Write (m, m.Body);
+                               }
+
+                               try {
+                                       delegateQueue.Send (m.DelegateMessage, transaction.DelegateTx);
+                               } catch (ConnectionException e) {
+                                       throw new MessageQueueException (MessageQueueErrorCode.QueueNotAvailable, e.Message);
+                               } catch (MonoMessagingException e) {
+                                       throw new MessageQueueException (MessageQueueErrorCode.Generic, e.Message);
+                               }
+                       } else {
+                               Message m = new Message (obj);
+                               Send (m, label, transaction);
+                       }
                }
-               [MonoTODO]
+
                public void Send (object obj, string label, MessageQueueTransactionType transactionType)
                {
-                       throw new NotImplementedException ();
+                       if (typeof (Message) == obj.GetType ()) {
+                               Message m = (Message) obj;
+                               m.Label = label;
+                               Send (m, transactionType);
+                       } else {
+                               Message m = new Message (obj);
+                               Send (m, label, transactionType);
+                       }
                }
                [MonoTODO]
                public void SetPermissions (AccessControlList dacl)
@@ -770,29 +1130,29 @@ namespace System.Messaging
                
                private static IMessageQueue GetMessageQueue (string path)
                {
+                       QueueReference qRef = QueueReference.Parse (path);
                        IMessageQueue q = MessagingProviderLocator
                                .GetProvider ()
-                               .GetMessageQueue ();
-                       q.QRef = QueueReference.Parse (path);
+                               .GetMessageQueue (qRef);
                        return q;
                }
                
                private static IMessageQueue GetMessageQueue ()
                {
                        return MessagingProviderLocator.GetProvider ()
-                               .GetMessageQueue ();
+                               .GetMessageQueue (QueueReference.DEFAULT);
                }
                
-               private static IMessageQueue CreateMessageQueue (QueueReference qRef)
+               private static IMessageQueue CreateMessageQueue (QueueReference qRef,
+                                                                bool transactional)
                {
                        return MessagingProviderLocator.GetProvider ()
-                               .CreateMessageQueue (qRef);
+                               .CreateMessageQueue (qRef, transactional);
                }
                
                private static bool Exists (QueueReference qRef)
                {
                        return MessagingProviderLocator.GetProvider ().Exists (qRef);
                }
-               
        }
 }
index 80e05ac24c75085e2aaf6fe0d10593aa8a3a173e..122a26f39049787bc65ddf697be1513f1221ae74 100644 (file)
@@ -28,7 +28,9 @@
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-using System;\r
+using System;
+
+using Mono.Messaging;\r
 \r
 namespace System.Messaging \r
 {\r
@@ -36,76 +38,68 @@ namespace System.Messaging
        // TODO: have to comply with 'This type is safe for multithreaded operations'\r
        public class MessageQueueTransaction : IDisposable \r
        {\r
-        // To avoid multiple disposals\r
-        private bool disposed = false;\r
+               private readonly IMessageQueueTransaction delegateTx;
+               private readonly object syncObj = new object ();
+               private bool isDisposed = false;\r
 \r
-               public MessageQueueTransaction()\r
+               public MessageQueueTransaction () : this (GetMessageQueueTransaction ())\r
                {\r
-                       status = MessageQueueTransactionStatus.Initialized;\r
+               }
+               
+               internal MessageQueueTransaction (IMessageQueueTransaction delegateTx)
+               {
+                       this.delegateTx = delegateTx;
                }\r
                \r
-               MessageQueueTransactionStatus status;\r
-               \r
                public MessageQueueTransactionStatus Status \r
                {\r
-                       get { return status; }\r
+                       get { 
+                               return (MessageQueueTransactionStatus) delegateTx.Status;
+                       }\r
+               }
+               
+               internal IMessageQueueTransaction DelegateTx {
+                       get { return delegateTx; }
+               }
+               
+               private static IMessageQueueTransaction GetMessageQueueTransaction ()
+               {
+                       return MessagingProviderLocator.GetProvider ().CreateMessageQueueTransaction ();
                }\r
                        \r
-               [MonoTODO]\r
-               public void Abort()\r
-               {\r
-                       if (status != MessageQueueTransactionStatus.Pending)\r
-                               throw new InvalidOperationException();\r
-                       status = MessageQueueTransactionStatus.Aborted;\r
-                       throw new NotImplementedException();\r
+               public void Abort ()\r
+               {
+                       delegateTx.Abort ();\r
                }\r
                \r
-               [MonoTODO]\r
-               public void Begin()\r
-               {\r
-                       if (status != MessageQueueTransactionStatus.Initialized)\r
-                               throw new InvalidOperationException();\r
-                       status = MessageQueueTransactionStatus.Pending;\r
-                       throw new NotImplementedException();\r
+               public void Begin ()\r
+               {
+                       delegateTx.Begin ();\r
                }\r
                \r
-               [MonoTODO]\r
-               public void Commit()\r
-               {\r
-                       if (status != MessageQueueTransactionStatus.Pending)\r
-                               throw new InvalidOperationException();\r
-                       status = MessageQueueTransactionStatus.Committed;\r
-                       throw new NotImplementedException();\r
-               }\r
-\r
-               public virtual void Dispose()\r
-               {\r
-                       if (status == MessageQueueTransactionStatus.Pending)\r
-                               Abort();\r
-            // Do this only at the first time\r
-            if (!this.disposed)\r
-                               Dispose(true);\r
-            disposed = true;         \r
-            // Take this object off the finalization queue \r
-            GC.SuppressFinalize(this);\r
+               public void Commit ()\r
+               {
+                       delegateTx.Commit ();\r
                }\r
-               \r
-               [MonoTODO]\r
-               protected virtual void Dispose(bool disposing)\r
-               {\r
-                       //if (disposing)\r
-                       //  free managed resources, by calling dispose on them\r
 \r
-                       // free external resources\r
-                       throw new NotImplementedException();\r
-               }\r
+               public void Dispose ()
+               {
+                       Dispose (true);
+                       GC.SuppressFinalize (this);
+               }
+               
+               protected virtual void Dispose (bool disposing)
+               {
+                       lock (syncObj) {
+                               if (!isDisposed && disposing) {
+                                       delegateTx.Dispose ();
+                               }
+                       }
+               }
                \r
                ~MessageQueueTransaction()\r
-               {\r
-                       if (status == MessageQueueTransactionStatus.Pending)\r
-                               Abort();\r
-               if (!this.disposed)\r
-                               Dispose(false);\r
+               {
+                       Dispose ();\r
                }\r
        }\r
 }\r