* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Transactions / System.Transactions / CommittableTransaction.cs
1 //
2 // CommittableTransaction.cs
3 //
4 // Author:
5 //      Atsushi Enomoto  <atsushi@ximian.com>
6 //      Ankit Jain       <JAnkit@novell.com>
7 //
8 // (C)2005 Novell Inc,
9 // (C)2006 Novell Inc,
10 //
11
12 #if NET_2_0
13 using System.Runtime.Serialization;
14 using System.Threading;
15
16 namespace System.Transactions
17 {
18         [Serializable]
19         public sealed class CommittableTransaction : Transaction,
20                 ISerializable, IDisposable, System.IAsyncResult
21         {
22                 TransactionOptions options;
23
24                 AsyncCallback callback;
25                 object user_defined_state;
26
27                 IAsyncResult asyncResult;
28
29                 public CommittableTransaction ()
30                         : this (new TransactionOptions ())
31                 {
32                 }
33
34                 public CommittableTransaction (TimeSpan timeout)
35                 {
36                         options = new TransactionOptions ();
37                         options.Timeout = timeout;
38                 }
39
40                 public CommittableTransaction (TransactionOptions options)
41                 {
42                         this.options = options;
43                 }
44
45                 public IAsyncResult BeginCommit (AsyncCallback callback,
46                         object user_defined_state)
47                 {
48                         this.callback = callback;
49                         this.user_defined_state = user_defined_state;
50
51                         AsyncCallback cb = null;
52                         if (callback != null)
53                                 cb = new AsyncCallback (CommitCallback);
54
55                         asyncResult = BeginCommitInternal (cb);
56                         return this;
57                 }
58                 
59                 public void EndCommit (IAsyncResult ar)
60                 {
61                         if (ar != this)
62                                 throw new ArgumentException ("The IAsyncResult parameter must be the same parameter as returned by BeginCommit.", "asyncResult");
63
64                         EndCommitInternal (asyncResult);
65                 }
66
67                 private void CommitCallback (IAsyncResult ar)
68                 {
69                         callback (this);
70                 }
71
72                 public void Commit ()
73                 {
74                         CommitInternal ();
75                 }
76                 
77                 [MonoTODO]
78                 void ISerializable.GetObjectData (SerializationInfo info,
79                         StreamingContext context)
80                 {
81                         throw new NotImplementedException ();
82                 }
83
84                 object IAsyncResult.AsyncState {
85                         get { return user_defined_state; }
86                 }
87
88                 WaitHandle IAsyncResult.AsyncWaitHandle {
89                         get { return asyncResult.AsyncWaitHandle; }
90                 }
91
92                 bool IAsyncResult.CompletedSynchronously {
93                         get { return asyncResult.CompletedSynchronously; }
94                 }
95
96                 bool IAsyncResult.IsCompleted {
97                         get { return asyncResult.IsCompleted; }
98                 }
99
100
101         }
102 }
103
104 #endif