CRLF->LF conversion
[mono.git] / mcs / class / System.Messaging / System.Messaging / MessageQueueTransaction.cs
index 80e05ac24c75085e2aaf6fe0d10593aa8a3a173e..58df50edc214b58c7f656e5503ccb94b4b3bf462 100644 (file)
@@ -1,12 +1,12 @@
-//\r
-// System.Messaging\r
-//\r
-// Authors:\r
-//      Peter Van Isacker (sclytrack@planetinternet.be)\r
-//      Rafael Teixeira   (rafaelteixeirabr@hotmail.com)\r
-//\r
-// (C) 2003 Peter Van Isacker\r
-//\r
+//
+// System.Messaging
+//
+// Authors:
+//      Peter Van Isacker (sclytrack@planetinternet.be)
+//      Rafael Teixeira   (rafaelteixeirabr@hotmail.com)
+//
+// (C) 2003 Peter Van Isacker
+//
 
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // 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
-\r
-namespace System.Messaging \r
-{\r
-\r
-       // 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
-\r
-               public MessageQueueTransaction()\r
-               {\r
-                       status = MessageQueueTransactionStatus.Initialized;\r
-               }\r
-               \r
-               MessageQueueTransactionStatus status;\r
-               \r
-               public MessageQueueTransactionStatus Status \r
-               {\r
-                       get { return status; }\r
-               }\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
-               }\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
-               }\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
-               }\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
-               \r
-               ~MessageQueueTransaction()\r
-               {\r
-                       if (status == MessageQueueTransactionStatus.Pending)\r
-                               Abort();\r
-               if (!this.disposed)\r
-                               Dispose(false);\r
-               }\r
-       }\r
-}\r
+using System;
+
+using Mono.Messaging;
+
+namespace System.Messaging 
+{
+
+       // TODO: have to comply with 'This type is safe for multithreaded operations'
+       public class MessageQueueTransaction : IDisposable 
+       {
+               private readonly IMessageQueueTransaction delegateTx;
+               private readonly object syncObj = new object ();
+               private bool isDisposed = false;
+
+               public MessageQueueTransaction () : this (GetMessageQueueTransaction ())
+               {
+               }
+               
+               internal MessageQueueTransaction (IMessageQueueTransaction delegateTx)
+               {
+                       this.delegateTx = delegateTx;
+               }
+               
+               public MessageQueueTransactionStatus Status 
+               {
+                       get { 
+                               return (MessageQueueTransactionStatus) delegateTx.Status;
+                       }
+               }
+               
+               internal IMessageQueueTransaction DelegateTx {
+                       get { return delegateTx; }
+               }
+               
+               private static IMessageQueueTransaction GetMessageQueueTransaction ()
+               {
+                       return MessagingProviderLocator.GetProvider ().CreateMessageQueueTransaction ();
+               }
+                       
+               public void Abort ()
+               {
+                       delegateTx.Abort ();
+               }
+               
+               public void Begin ()
+               {
+                       delegateTx.Begin ();
+               }
+               
+               public void Commit ()
+               {
+                       delegateTx.Commit ();
+               }
+
+               public void Dispose ()
+               {
+                       Dispose (true);
+                       GC.SuppressFinalize (this);
+               }
+               
+               protected virtual void Dispose (bool disposing)
+               {
+                       lock (syncObj) {
+                               if (!isDisposed && disposing) {
+                                       delegateTx.Dispose ();
+                               }
+                       }
+               }
+               
+               ~MessageQueueTransaction()
+               {
+                       Dispose ();
+               }
+       }
+}