Merge pull request #901 from Blewzman/FixAggregateExceptionGetBaseException
[mono.git] / mcs / class / System.Transactions / System.Transactions / PreparingEnlistment.cs
old mode 100755 (executable)
new mode 100644 (file)
index 32e4f0c..eaaa277
@@ -3,36 +3,57 @@
 //
 // 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.Threading;
+
 namespace System.Transactions
 {
        public class PreparingEnlistment : Enlistment
        {
-               internal PreparingEnlistment ()
+               bool prepared = false;
+               Transaction tx;
+               IEnlistmentNotification enlisted;
+               WaitHandle waitHandle;
+               Exception ex;
+
+               internal PreparingEnlistment (Transaction tx, IEnlistmentNotification enlisted)
                {
+                       this.tx = tx;
+                       this.enlisted = enlisted;
+                       waitHandle = new ManualResetEvent (false);
                }
 
-               [MonoTODO]
                public void ForceRollback ()
                {
-                       throw new NotImplementedException ();
+                       ForceRollback (null);
+               }
+
+               internal override void InternalOnDone ()
+               {
+                       this.Prepared();                        
                }
 
                [MonoTODO]
                public void ForceRollback (Exception ex)
                {
-                       throw new NotImplementedException ();
+                       tx.Rollback (ex, enlisted);
+                       /* See test RMFail2 */
+                       ((ManualResetEvent) waitHandle).Set ();
                }
 
                [MonoTODO]
                public void Prepared ()
                {
-                       throw new NotImplementedException ();
+                       prepared = true;
+                       /* See test RMFail2 */
+                       ((ManualResetEvent) waitHandle).Set ();
                }
 
                [MonoTODO]
@@ -40,6 +61,27 @@ namespace System.Transactions
                {
                        throw new NotImplementedException ();
                }
+
+               internal bool IsPrepared {
+                       get { return prepared; }
+               }
+
+               internal WaitHandle WaitHandle {
+                       get { return waitHandle; }
+               }
+
+               internal IEnlistmentNotification EnlistmentNotification
+               {
+                       get { return enlisted; }
+               }
+
+               // Uncatched exceptions thrown during prepare will
+               // be saved here so they can be retrieved by TM.
+               internal Exception Exception
+               {
+                       get { return ex; }
+                       set { ex = value; }
+               }
        }
 }