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
- ComponentEditorForm.cs
- EnumBuilder.cs
- NotifyInputEventArgs.cs
- DataColumnPropertyDescriptor.cs
- PolicyChain.cs
- GZipDecoder.cs
- HandlerWithFactory.cs
- XmlSchemaSimpleTypeList.cs
- WebGetAttribute.cs
- AssemblyAttributes.cs
- ToolStripButton.cs
- CreateUserWizard.cs
- Transaction.cs
- StylusPoint.cs
- Utils.cs
- PersonalizationStateQuery.cs
- GifBitmapDecoder.cs
- IDispatchConstantAttribute.cs
- MaterializeFromAtom.cs
- FormViewInsertedEventArgs.cs
- BorderGapMaskConverter.cs
- FontDialog.cs
- TargetFrameworkAttribute.cs
- ToolStripPanelCell.cs
- RadioButtonList.cs
- FixedTextView.cs
- DataGridViewColumnCollection.cs
- DiscoveryDocumentSerializer.cs
- WebPartCatalogCloseVerb.cs
- HttpListenerContext.cs
- ContentType.cs
- CategoryNameCollection.cs
- BitmapEffectGeneralTransform.cs
- OleAutBinder.cs
- ItemsPresenter.cs
- PackagePartCollection.cs
- __ConsoleStream.cs
- SizeChangedEventArgs.cs
- _ConnectionGroup.cs
- NCryptNative.cs
- NativeMethods.cs
- InkPresenter.cs
- _LazyAsyncResult.cs
- CharAnimationBase.cs
- PageTheme.cs
- ToolBar.cs
- DockingAttribute.cs
- ArcSegment.cs
- PropertyGeneratedEventArgs.cs
- InstanceContext.cs
- CollectionBase.cs
- RequestCacheValidator.cs
- ToolStripDropDownClosedEventArgs.cs
- Validator.cs
- VisualStateChangedEventArgs.cs
- DataKey.cs
- ApplicationServicesHostFactory.cs
- WrappingXamlSchemaContext.cs
- EncryptedHeaderXml.cs
- DragCompletedEventArgs.cs
- DataGridViewCellFormattingEventArgs.cs
- FacetChecker.cs
- BamlResourceDeserializer.cs
- ConfigurationPropertyAttribute.cs
- ContentPlaceHolder.cs
- HtmlMeta.cs
- TrackingRecordPreFilter.cs
- AssociationSetEnd.cs
- XmlSchemaExporter.cs
- TemplatedEditableDesignerRegion.cs
- DirectoryInfo.cs
- MetadataCache.cs
- DocobjHost.cs
- GridViewCancelEditEventArgs.cs
- SimpleHandlerBuildProvider.cs
- MappedMetaModel.cs
- FacetValues.cs
- SqlFileStream.cs
- IgnorePropertiesAttribute.cs
- MemberListBinding.cs
- DeclarationUpdate.cs
- PrintDocument.cs
- ControlDesigner.cs
- PropertyGridCommands.cs
- CachedPathData.cs
- ObjectComplexPropertyMapping.cs
- SystemTcpConnection.cs
- DeflateStream.cs
- Compress.cs
- X509CertificateCollection.cs
- DeploymentSectionCache.cs
- _DisconnectOverlappedAsyncResult.cs
- AnimationLayer.cs
- LinkButton.cs
- SQLInt32.cs
- ContentAlignmentEditor.cs
- ValidationError.cs
- OutputScope.cs
- MetaTableHelper.cs
- XslVisitor.cs