diff options
author | Marek Safar <marek.safar@gmail.com> | 2016-05-29 09:22:45 +0300 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2016-05-29 09:22:45 +0300 |
commit | c6d3cc5fa7e759a8b36f1a4bd15a65312b7c7120 (patch) | |
tree | 09175a791c719bb1d4068876ac0ca92464a79352 /mcs/class/System.Transactions | |
parent | 6683c128e4510187b0a6b8a6585095dcd25984c2 (diff) | |
parent | 1516f24d06549c7ebd6eaea95a6c5415119e69e3 (diff) |
Merge pull request #3061 from Thorium/master
#23050 TransactionScopeAsyncFlowOption
Diffstat (limited to 'mcs/class/System.Transactions')
4 files changed, 79 insertions, 23 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 b7eec4745fd..0040fd6840b 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.dll.sources b/mcs/class/System.Transactions/System.Transactions.dll.sources index 36d981ebe95..4c5394f957b 100644 --- a/mcs/class/System.Transactions/System.Transactions.dll.sources +++ b/mcs/class/System.Transactions/System.Transactions.dll.sources @@ -31,6 +31,7 @@ System.Transactions/TransactionManagerCommunicationException.cs System.Transactions/TransactionOptions.cs System.Transactions/TransactionPromotionException.cs System.Transactions/TransactionScope.cs +System.Transactions/TransactionScopeAsyncFlowOption.cs System.Transactions/TransactionScopeOption.cs System.Transactions/TransactionStatus.cs System.Transactions/Configuration/DefaultSettingsSection.cs diff --git a/mcs/class/System.Transactions/System.Transactions/TransactionScope.cs b/mcs/class/System.Transactions/System.Transactions/TransactionScope.cs index 129967d9e27..8ec40403b06 100644 --- a/mcs/class/System.Transactions/System.Transactions/TransactionScope.cs +++ b/mcs/class/System.Transactions/System.Transactions/TransactionScope.cs @@ -31,12 +31,20 @@ namespace System.Transactions bool completed; bool isRoot; + bool asyncFlowEnabled; + public TransactionScope () : this (TransactionScopeOption.Required, TransactionManager.DefaultTimeout) { } + 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,16 +93,17 @@ 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) throw new ArgumentOutOfRangeException ("timeout"); @@ -165,36 +179,67 @@ 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; + } + + 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.CommitInternal (); + 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..5285fe5a0fd --- /dev/null +++ b/mcs/class/System.Transactions/System.Transactions/TransactionScopeAsyncFlowOption.cs @@ -0,0 +1,9 @@ + +namespace System.Transactions +{ + public enum TransactionScopeAsyncFlowOption + { + Suppress, + Enabled + } +} |