Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WF / RunTime / Hosting / LocalTransaction.cs / 1305376 / LocalTransaction.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- #region Using directives using System; using System.Diagnostics; using System.Transactions; using System.Data; using System.Data.Common; using System.Threading; #endregion namespace System.Workflow.Runtime.Hosting { ////// This class wraps a local transaction (DbTransaction) by implementing IPromotableSinglePhaseNotification: /// It instantiate a DbTransaction and never allows promotion to a DTC transaction. /// internal sealed class LocalTransaction : IPromotableSinglePhaseNotification { readonly DbTransaction transaction; System.Data.Common.DbConnection connection; ManualResetEvent handle; object syncRoot = new Object(); #region Constructor ////// Wraps a local transaction inside /// /// internal LocalTransaction(DbResourceAllocator dbHelper, ManualResetEvent handle) { if (null == handle) throw new ArgumentNullException("handle"); // Open a connection that specifically does not auto-enlist ("Enlist=false" in connection string) // to prevent auto-promotion of the transaction this.connection = dbHelper.OpenNewConnectionNoEnlist(); this.transaction = this.connection.BeginTransaction(); this.handle = handle; } #endregion Constructor #region Accessors public System.Data.Common.DbConnection Connection { get { return this.connection; } } public DbTransaction Transaction { get { return this.transaction; } } #endregion Accessors #region IPromotableSinglePhaseNotification Members public void Initialize() { } public void SinglePhaseCommit(SinglePhaseEnlistment en) { if (en == null) throw new ArgumentNullException("en"); // // Wait until IPendingWork members have completed (WinOE bugs 17580 and 13395) try { handle.WaitOne(); } catch (ObjectDisposedException) { // If an ObjectDisposedException is thrown because // the WaitHandle has already closed, nothing to worry // about. Move on. } lock (syncRoot) { try { this.transaction.Commit(); en.Committed(); } catch (Exception e) { en.Aborted(e); } finally { if ((null != connection) && (ConnectionState.Closed != connection.State)) { connection.Close(); connection = null; } } } } public void Rollback(SinglePhaseEnlistment en) { if (en == null) throw new ArgumentNullException("en"); // // Wait until IPendingWork members have completed (WinOE bugs 17580 and 13395) try { handle.WaitOne(); } catch (ObjectDisposedException) { // If an ObjectDisposedException is thrown because // the WaitHandle has already closed, nothing to worry // about. Move on. } // DbTransaction.Dispose will call Rollback if the DbTransaction is not Zombied. // Not safe to call DbTransaction.Rollback here as the the underlining // DbTransaction may have already been Rolled back lock (syncRoot) { if (null != transaction) transaction.Dispose(); if ((null != connection) && (ConnectionState.Closed != connection.State)) { connection.Close(); connection = null; } en.Aborted(); } } public byte[] Promote() { throw new TransactionPromotionException( ExecutionStringManager.PromotionNotSupported); } #endregion IPromotableSinglePhaseNotification Members } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- #region Using directives using System; using System.Diagnostics; using System.Transactions; using System.Data; using System.Data.Common; using System.Threading; #endregion namespace System.Workflow.Runtime.Hosting { ////// This class wraps a local transaction (DbTransaction) by implementing IPromotableSinglePhaseNotification: /// It instantiate a DbTransaction and never allows promotion to a DTC transaction. /// internal sealed class LocalTransaction : IPromotableSinglePhaseNotification { readonly DbTransaction transaction; System.Data.Common.DbConnection connection; ManualResetEvent handle; object syncRoot = new Object(); #region Constructor ////// Wraps a local transaction inside /// /// internal LocalTransaction(DbResourceAllocator dbHelper, ManualResetEvent handle) { if (null == handle) throw new ArgumentNullException("handle"); // Open a connection that specifically does not auto-enlist ("Enlist=false" in connection string) // to prevent auto-promotion of the transaction this.connection = dbHelper.OpenNewConnectionNoEnlist(); this.transaction = this.connection.BeginTransaction(); this.handle = handle; } #endregion Constructor #region Accessors public System.Data.Common.DbConnection Connection { get { return this.connection; } } public DbTransaction Transaction { get { return this.transaction; } } #endregion Accessors #region IPromotableSinglePhaseNotification Members public void Initialize() { } public void SinglePhaseCommit(SinglePhaseEnlistment en) { if (en == null) throw new ArgumentNullException("en"); // // Wait until IPendingWork members have completed (WinOE bugs 17580 and 13395) try { handle.WaitOne(); } catch (ObjectDisposedException) { // If an ObjectDisposedException is thrown because // the WaitHandle has already closed, nothing to worry // about. Move on. } lock (syncRoot) { try { this.transaction.Commit(); en.Committed(); } catch (Exception e) { en.Aborted(e); } finally { if ((null != connection) && (ConnectionState.Closed != connection.State)) { connection.Close(); connection = null; } } } } public void Rollback(SinglePhaseEnlistment en) { if (en == null) throw new ArgumentNullException("en"); // // Wait until IPendingWork members have completed (WinOE bugs 17580 and 13395) try { handle.WaitOne(); } catch (ObjectDisposedException) { // If an ObjectDisposedException is thrown because // the WaitHandle has already closed, nothing to worry // about. Move on. } // DbTransaction.Dispose will call Rollback if the DbTransaction is not Zombied. // Not safe to call DbTransaction.Rollback here as the the underlining // DbTransaction may have already been Rolled back lock (syncRoot) { if (null != transaction) transaction.Dispose(); if ((null != connection) && (ConnectionState.Closed != connection.State)) { connection.Close(); connection = null; } en.Aborted(); } } public byte[] Promote() { throw new TransactionPromotionException( ExecutionStringManager.PromotionNotSupported); } #endregion IPromotableSinglePhaseNotification Members } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ApplicationBuildProvider.cs
- StrictModeSecurityHeaderElementInferenceEngine.cs
- EmbeddedObject.cs
- Rotation3DAnimation.cs
- CSharpCodeProvider.cs
- RightsManagementLicense.cs
- DataGridViewCellStyleConverter.cs
- RenderData.cs
- WindowsEditBox.cs
- DocumentReferenceCollection.cs
- LineServicesRun.cs
- WebPartCancelEventArgs.cs
- ToolStripScrollButton.cs
- GraphicsContext.cs
- BindingSourceDesigner.cs
- AccessDataSourceWizardForm.cs
- ToolStripRenderer.cs
- Error.cs
- PointConverter.cs
- ActivationService.cs
- SplitterCancelEvent.cs
- ThemeDictionaryExtension.cs
- FontFaceLayoutInfo.cs
- ValueTable.cs
- TagPrefixCollection.cs
- Page.cs
- ProfileServiceManager.cs
- PageParser.cs
- XmlSchemaObjectCollection.cs
- Array.cs
- XamlToRtfParser.cs
- Calendar.cs
- AdjustableArrowCap.cs
- TreeNodeStyle.cs
- DataRelationCollection.cs
- ClientCultureInfo.cs
- Math.cs
- ApplicationInterop.cs
- FormsAuthenticationTicket.cs
- WebServiceHandler.cs
- NativeCompoundFileAPIs.cs
- MailDefinition.cs
- Win32MouseDevice.cs
- ListViewGroupConverter.cs
- DiagnosticEventProvider.cs
- ExtenderControl.cs
- CheckBoxFlatAdapter.cs
- DataRelationPropertyDescriptor.cs
- PeerNameRegistration.cs
- XmlDataCollection.cs
- WebControlAdapter.cs
- ReadWriteSpinLock.cs
- TreeViewItemAutomationPeer.cs
- MobileControl.cs
- BinaryWriter.cs
- ShellProvider.cs
- XmlTextReaderImpl.cs
- ClientScriptManager.cs
- _SSPISessionCache.cs
- OdbcDataAdapter.cs
- TemplateAction.cs
- basevalidator.cs
- BidOverLoads.cs
- DbDataReader.cs
- MouseCaptureWithinProperty.cs
- DataBoundLiteralControl.cs
- Solver.cs
- SafeEventLogWriteHandle.cs
- Vector3D.cs
- InputReportEventArgs.cs
- QuaternionRotation3D.cs
- DetailsViewActionList.cs
- XPathDocumentNavigator.cs
- CodeStatementCollection.cs
- NominalTypeEliminator.cs
- XmlSchemaSimpleContentRestriction.cs
- SQLConvert.cs
- EditingMode.cs
- SiteMapNodeCollection.cs
- PenThread.cs
- ZipIOExtraFieldZip64Element.cs
- __Error.cs
- CatalogPartChrome.cs
- OutOfProcStateClientManager.cs
- RawStylusInputCustomDataList.cs
- AccessText.cs
- ExtentJoinTreeNode.cs
- SqlUdtInfo.cs
- WebControlsSection.cs
- SchemaHelper.cs
- MethodRental.cs
- WebMethodAttribute.cs
- versioninfo.cs
- RoutedEventHandlerInfo.cs
- CacheAxisQuery.cs
- EncryptedPackageFilter.cs
- AdPostCacheSubstitution.cs
- __ComObject.cs
- TextEffectResolver.cs
- FusionWrap.cs