X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.Messaging%2FSystem.Messaging%2FMessageQueueTransaction.cs;h=58df50edc214b58c7f656e5503ccb94b4b3bf462;hb=a73af072dc7341497943672c714304681295ff4b;hp=80e05ac24c75085e2aaf6fe0d10593aa8a3a173e;hpb=f99ce750ee781a2584e849a0264300fa4d99aaaa;p=mono.git diff --git a/mcs/class/System.Messaging/System.Messaging/MessageQueueTransaction.cs b/mcs/class/System.Messaging/System.Messaging/MessageQueueTransaction.cs index 80e05ac24c7..58df50edc21 100644 --- a/mcs/class/System.Messaging/System.Messaging/MessageQueueTransaction.cs +++ b/mcs/class/System.Messaging/System.Messaging/MessageQueueTransaction.cs @@ -1,12 +1,12 @@ -// -// System.Messaging -// -// Authors: -// Peter Van Isacker (sclytrack@planetinternet.be) -// Rafael Teixeira (rafaelteixeirabr@hotmail.com) -// -// (C) 2003 Peter Van Isacker -// +// +// 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 @@ -28,84 +28,78 @@ // 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; - -namespace System.Messaging -{ - - // TODO: have to comply with 'This type is safe for multithreaded operations' - public class MessageQueueTransaction : IDisposable - { - // To avoid multiple disposals - private bool disposed = false; - - public MessageQueueTransaction() - { - status = MessageQueueTransactionStatus.Initialized; - } - - MessageQueueTransactionStatus status; - - public MessageQueueTransactionStatus Status - { - get { return status; } - } - - [MonoTODO] - public void Abort() - { - if (status != MessageQueueTransactionStatus.Pending) - throw new InvalidOperationException(); - status = MessageQueueTransactionStatus.Aborted; - throw new NotImplementedException(); - } - - [MonoTODO] - public void Begin() - { - if (status != MessageQueueTransactionStatus.Initialized) - throw new InvalidOperationException(); - status = MessageQueueTransactionStatus.Pending; - throw new NotImplementedException(); - } - - [MonoTODO] - public void Commit() - { - if (status != MessageQueueTransactionStatus.Pending) - throw new InvalidOperationException(); - status = MessageQueueTransactionStatus.Committed; - throw new NotImplementedException(); - } - - public virtual void Dispose() - { - if (status == MessageQueueTransactionStatus.Pending) - Abort(); - // Do this only at the first time - if (!this.disposed) - Dispose(true); - disposed = true; - // Take this object off the finalization queue - GC.SuppressFinalize(this); - } - - [MonoTODO] - protected virtual void Dispose(bool disposing) - { - //if (disposing) - // free managed resources, by calling dispose on them - - // free external resources - throw new NotImplementedException(); - } - - ~MessageQueueTransaction() - { - if (status == MessageQueueTransactionStatus.Pending) - Abort(); - if (!this.disposed) - Dispose(false); - } - } -} +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 (); + } + } +}