Merge pull request #4621 from alexanderkyte/strdup_env
[mono.git] / mcs / class / System.Transactions / System.Transactions / CommittableTransaction.cs
old mode 100755 (executable)
new mode 100644 (file)
index 3dc2c0b..f98f6fa
@@ -3,11 +3,12 @@
 //
 // Author:
 //     Atsushi Enomoto  <atsushi@ximian.com>
+//     Ankit Jain       <JAnkit@novell.com>
 //
 // (C)2005 Novell Inc,
+// (C)2006 Novell Inc,
 //
 
-#if NET_2_0
 using System.Runtime.Serialization;
 using System.Threading;
 
@@ -15,14 +16,14 @@ namespace System.Transactions
 {
        [Serializable]
        public sealed class CommittableTransaction : Transaction,
-               ISerializable, IDisposable, IAsyncResult
+               ISerializable, IDisposable, System.IAsyncResult
        {
-
                TransactionOptions options;
+
                AsyncCallback callback;
                object user_defined_state;
-               bool committing;
-               bool completed;
+
+               IAsyncResult asyncResult;
 
                public CommittableTransaction ()
                        : this (new TransactionOptions ())
@@ -40,33 +41,41 @@ namespace System.Transactions
                        this.options = options;
                }
 
-               [MonoTODO]
-               public IAsyncResult BeginCommit (AsyncCallback callback,
-                       object user_defined_state)
+               public IAsyncResult BeginCommit (AsyncCallback asyncCallback,
+                       object asyncState)
                {
-                       if (committing)
-                               throw new InvalidOperationException ();
-                       this.committing = true;
-                       this.callback = callback;
-                       this.user_defined_state = user_defined_state;
-                       // FIXME: invoke another thread and set WaitHandle.
+                       this.callback = asyncCallback;
+                       this.user_defined_state = asyncState;
+
+                       AsyncCallback cb = null;
+                       if (asyncCallback != null)
+                               cb = new AsyncCallback (CommitCallback);
+
+                       asyncResult = BeginCommitInternal (cb);
                        return this;
                }
-
-               public void Commit ()
+               
+               public void EndCommit (IAsyncResult asyncResult)
                {
-                       EndCommit (BeginCommit (null, null));
+                       if (asyncResult != this)
+                               throw new ArgumentException ("The IAsyncResult parameter must be the same parameter as returned by BeginCommit.", "asyncResult");
+
+                       EndCommitInternal (this.asyncResult);
                }
 
-               [MonoTODO]
-               public void EndCommit (IAsyncResult asyncResult)
+               private void CommitCallback (IAsyncResult ar)
                {
-                       if (asyncResult != this)
-                               throw new InvalidOperationException ();
-                       throw new NotImplementedException ();
+                       if (asyncResult == null && ar.CompletedSynchronously)
+                               asyncResult = ar;
+                       callback (this);
                }
 
-               [MonoTODO]
+               public void Commit ()
+               {
+                       CommitInternal ();
+               }
+               
+               [MonoTODO ("Not implemented")]
                void ISerializable.GetObjectData (SerializationInfo info,
                        StreamingContext context)
                {
@@ -77,20 +86,19 @@ namespace System.Transactions
                        get { return user_defined_state; }
                }
 
-               [MonoTODO]
                WaitHandle IAsyncResult.AsyncWaitHandle {
-                       get { throw new NotImplementedException (); }
+                       get { return asyncResult.AsyncWaitHandle; }
                }
 
-               [MonoTODO]
                bool IAsyncResult.CompletedSynchronously {
-                       get { throw new NotImplementedException (); }
+                       get { return asyncResult.CompletedSynchronously; }
                }
 
                bool IAsyncResult.IsCompleted {
-                       get { return completed; }
+                       get { return asyncResult.IsCompleted; }
                }
+
+
        }
 }
 
-#endif