diff options
author | Tuomas Hietanen <tuomas.hietanen@iki.fi> | 2016-05-26 17:04:25 +0300 |
---|---|---|
committer | Tuomas Hietanen <tuomas.hietanen@iki.fi> | 2016-05-26 17:05:29 +0300 |
commit | c9c563fa5b09ca31e538ac02313189aa54e25038 (patch) | |
tree | 5df84e4379c16a77483e9c668d31b97da97c8a42 /mcs/class/System.Transactions | |
parent | 478db45ebddf19a2d13100a1024d40f57eeb7385 (diff) |
#23050 First attempt to create TransactionScopeAsyncFlowOption on Mono.
This is a feature that is missing. However I don't have Mono,
so has to be compiled and tested.
Diffstat (limited to 'mcs/class/System.Transactions')
3 files changed, 83 insertions, 28 deletions
diff --git a/mcs/class/System.Transactions/System.Transactions-net_4_x.csproj b/mcs/class/System.Transactions/System.Transactions-net_4_x.csproj index 9b0b192e2d6..6f42248c8e3 100644 --- a/mcs/class/System.Transactions/System.Transactions-net_4_x.csproj +++ b/mcs/class/System.Transactions/System.Transactions-net_4_x.csproj @@ -84,6 +84,7 @@ <Compile Include="System.Transactions\TransactionOptions.cs" />
<Compile Include="System.Transactions\TransactionPromotionException.cs" />
<Compile Include="System.Transactions\TransactionScope.cs" />
+ <Compile Include="System.Transactions\TransactionScopeAsyncFlowOption.cs" />
<Compile Include="System.Transactions\TransactionScopeOption.cs" />
<Compile Include="System.Transactions\TransactionStatus.cs" />
</ItemGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
diff --git a/mcs/class/System.Transactions/System.Transactions/TransactionScope.cs b/mcs/class/System.Transactions/System.Transactions/TransactionScope.cs index 129967d9e27..9c0c353ba24 100644 --- a/mcs/class/System.Transactions/System.Transactions/TransactionScope.cs +++ b/mcs/class/System.Transactions/System.Transactions/TransactionScope.cs @@ -31,13 +31,21 @@ namespace System.Transactions bool completed; bool isRoot; - public TransactionScope () + bool asyncFlowEnabled; + + public TransactionScope () : this (TransactionScopeOption.Required, TransactionManager.DefaultTimeout) { } - public TransactionScope (Transaction transaction) + public TransactionScope(TransactionScopeAsyncFlowOption asyncFlow) + : this(TransactionScopeOption.Required, + TransactionManager.DefaultTimeout, asyncFlow) + { + } + + public TransactionScope (Transaction transaction) : this (transaction, TransactionManager.DefaultTimeout) { } @@ -53,7 +61,7 @@ namespace System.Transactions TimeSpan timeout, DTCOption opt) { Initialize (TransactionScopeOption.Required, - transaction, defaultOptions, opt, timeout); + transaction, defaultOptions, opt, timeout, TransactionScopeAsyncFlowOption.Suppress); } public TransactionScope (TransactionScopeOption option) @@ -61,11 +69,16 @@ namespace System.Transactions { } - public TransactionScope (TransactionScopeOption option, - TimeSpan timeout) + public TransactionScope(TransactionScopeOption option, TransactionScopeAsyncFlowOption asyncFlow) + : this(option, TransactionManager.DefaultTimeout, asyncFlow) + { + } + + public TransactionScope (TransactionScopeOption option, + TimeSpan timeout, TransactionScopeAsyncFlowOption asyncFlow) { Initialize (option, null, defaultOptions, - DTCOption.None, timeout); + DTCOption.None, timeout, asyncFlow); } public TransactionScope (TransactionScopeOption scopeOption, @@ -80,18 +93,19 @@ namespace System.Transactions DTCOption opt) { Initialize (scopeOption, null, options, opt, - TransactionManager.DefaultTimeout); + TransactionManager.DefaultTimeout, TransactionScopeAsyncFlowOption.Suppress); } void Initialize (TransactionScopeOption scopeOption, Transaction tx, TransactionOptions options, - DTCOption interop, TimeSpan timeout) + DTCOption interop, TimeSpan timeout, TransactionScopeAsyncFlowOption asyncFlow) { completed = false; isRoot = false; nested = 0; + asyncFlowEnabled = asyncFlow == TransactionScopeAsyncFlowOption.Enabled; - if (timeout < TimeSpan.Zero) + if (timeout < TimeSpan.Zero) throw new ArgumentOutOfRangeException ("timeout"); this.timeout = timeout; @@ -165,39 +179,70 @@ namespace System.Transactions throw new InvalidOperationException ("TransactionScope nested incorrectly"); } - if (Transaction.CurrentInternal != transaction) { + if (Transaction.CurrentInternal != transaction && !asyncFlowEnabled) { if (transaction != null) transaction.Rollback (); if (Transaction.CurrentInternal != null) Transaction.CurrentInternal.Rollback (); throw new InvalidOperationException ("Transaction.Current has changed inside of the TransactionScope"); - } + } - if (Transaction.CurrentInternal == oldTransaction && oldTransaction != null) - oldTransaction.Scope = parentScope; + if (asyncFlowEnabled) { + if (oldTransaction != null) + oldTransaction.Scope = parentScope; - Transaction.CurrentInternal = oldTransaction; + var variedTransaction = Transaction.CurrentInternal; - if (transaction == null) - /* scope was not in a transaction, (Suppress) */ - return; + if (transaction == null && variedTransaction == null) + /* scope was not in a transaction, (Suppress) */ + return; - transaction.Scope = null; + variedTransaction.Scope = parentScope; + Transaction.CurrentInternal = oldTransaction; - if (!IsComplete) { - transaction.Rollback (); - return; - } + transaction.Scope = null; - if (!isRoot) - /* Non-root scope has completed+ended */ - return; + if (!IsComplete) { + transaction.Rollback (); + variedTransaction.Rollback(); + return; + } - transaction.CommitInternal (); - } + if (!isRoot) + /* Non-root scope has completed+ended */ + return; + + variedTransaction.CommitInternal(); + transaction.CommitInternal(); + } else { + if (Transaction.CurrentInternal == oldTransaction && oldTransaction != null) + oldTransaction.Scope = parentScope; + + Transaction.CurrentInternal = oldTransaction; + + if (transaction == null) + /* scope was not in a transaction, (Suppress) */ + return; + + transaction.Scope = null; + + if (!IsComplete) + { + transaction.Rollback(); + return; + } + + if (!isRoot) + /* Non-root scope has completed+ended */ + return; + + transaction.CommitInternal(); + + } + } - } + } } diff --git a/mcs/class/System.Transactions/System.Transactions/TransactionScopeAsyncFlowOption.cs b/mcs/class/System.Transactions/System.Transactions/TransactionScopeAsyncFlowOption.cs new file mode 100644 index 00000000000..f1c941979a3 --- /dev/null +++ b/mcs/class/System.Transactions/System.Transactions/TransactionScopeAsyncFlowOption.cs @@ -0,0 +1,9 @@ + +namespace System.Transactions +{ + public enum TransactionScopeAsyncFlowOption + { + Suppress, + Enabled + } +} |