merge -r 53370:58178
[mono.git] / mcs / class / System.Transactions / System.Transactions / CommittableTransaction.cs
1 //
2 // CommittableTransaction.cs
3 //
4 // Author:
5 //      Atsushi Enomoto  <atsushi@ximian.com>
6 //
7 // (C)2005 Novell Inc,
8 //
9
10 #if NET_2_0
11 using System.Runtime.Serialization;
12 using System.Threading;
13
14 namespace System.Transactions
15 {
16         [Serializable]
17         public sealed class CommittableTransaction : Transaction,
18                 ISerializable, IDisposable, IAsyncResult
19         {
20
21                 TransactionOptions options;
22                 AsyncCallback callback;
23                 object user_defined_state;
24                 bool committing;
25                 bool completed;
26
27                 public CommittableTransaction ()
28                         : this (new TransactionOptions ())
29                 {
30                 }
31
32                 public CommittableTransaction (TimeSpan timeout)
33                 {
34                         options = new TransactionOptions ();
35                         options.Timeout = timeout;
36                 }
37
38                 public CommittableTransaction (TransactionOptions options)
39                 {
40                         this.options = options;
41                 }
42
43                 [MonoTODO]
44                 public IAsyncResult BeginCommit (AsyncCallback callback,
45                         object user_defined_state)
46                 {
47                         if (committing)
48                                 throw new InvalidOperationException ();
49                         this.committing = true;
50                         this.callback = callback;
51                         this.user_defined_state = user_defined_state;
52                         // FIXME: invoke another thread and set WaitHandle.
53                         return this;
54                 }
55
56                 public void Commit ()
57                 {
58                         EndCommit (BeginCommit (null, null));
59                 }
60
61                 [MonoTODO]
62                 public void EndCommit (IAsyncResult asyncResult)
63                 {
64                         if (asyncResult != this)
65                                 throw new InvalidOperationException ();
66                         throw new NotImplementedException ();
67                 }
68
69                 [MonoTODO]
70                 void ISerializable.GetObjectData (SerializationInfo info,
71                         StreamingContext context)
72                 {
73                         throw new NotImplementedException ();
74                 }
75
76                 object IAsyncResult.AsyncState {
77                         get { return user_defined_state; }
78                 }
79
80                 [MonoTODO]
81                 WaitHandle IAsyncResult.AsyncWaitHandle {
82                         get { throw new NotImplementedException (); }
83                 }
84
85                 [MonoTODO]
86                 bool IAsyncResult.CompletedSynchronously {
87                         get { throw new NotImplementedException (); }
88                 }
89
90                 bool IAsyncResult.IsCompleted {
91                         get { return completed; }
92                 }
93         }
94 }
95
96 #endif