-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 ();
+ }
+ }
+}