Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WF / RunTime / Hosting / SharedConnectionInfo.cs / 1305376 / SharedConnectionInfo.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- #region Using directives using System; using System.Diagnostics; using System.Transactions; using System.Data.Common; using System.Threading; #endregion namespace System.Workflow.Runtime.Hosting { ////// This class keeps the following associated with a Transaction /// - a connection that participates in the transaction. /// - an optional local transaction (DbTransaction) generated from the single-phase-committed Transaction. /// The connection and the local transaction are passed around to different host components to /// do transacted DB work using the shared connection. /// internal sealed class SharedConnectionInfo : IDisposable { readonly DbConnection connection; readonly DbTransaction localTransaction; private bool disposed; private ManualResetEvent handle; #region Constructor ////// Instantiate an opened connection enlisted to the Transaction /// if promotable is false, the Transaction wraps a local /// transaction inside and can never be promoted /// /// /// /// internal SharedConnectionInfo( DbResourceAllocator dbResourceAllocator, Transaction transaction, bool wantPromotable, ManualResetEvent handle) { Debug.Assert((transaction != null), "Null Transaction!"); if (null == handle) throw new ArgumentNullException("handle"); this.handle = handle; if (wantPromotable) { // Enlist a newly opened connection to this regular Transaction this.connection = dbResourceAllocator.OpenNewConnection(); this.connection.EnlistTransaction(transaction); } else { // Make this transaction no longer promotable by attaching our // IPromotableSinglePhaseNotification implementation (LocalTranscaction) // and track the DbConnection and DbTransaction associated with the LocalTranscaction LocalTransaction localTransaction = new LocalTransaction(dbResourceAllocator,handle); transaction.EnlistPromotableSinglePhase(localTransaction); this.connection = localTransaction.Connection; this.localTransaction = localTransaction.Transaction; } } #endregion Constructor #region Accessors internal DbConnection DBConnection { get { return this.connection; } } internal DbTransaction DBTransaction { get { return this.localTransaction; } } #endregion Accessors #region IDisposable Members public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } private void Dispose(bool disposing) { if (!this.disposed) { // // If we're using a LocalTransaction it will close the connection // in it's IPromotableSinglePhaseNotification methods if ((this.localTransaction == null)&&(null != connection)) this.connection.Dispose(); } this.disposed = true; } #endregion } } // 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.Common; using System.Threading; #endregion namespace System.Workflow.Runtime.Hosting { ////// This class keeps the following associated with a Transaction /// - a connection that participates in the transaction. /// - an optional local transaction (DbTransaction) generated from the single-phase-committed Transaction. /// The connection and the local transaction are passed around to different host components to /// do transacted DB work using the shared connection. /// internal sealed class SharedConnectionInfo : IDisposable { readonly DbConnection connection; readonly DbTransaction localTransaction; private bool disposed; private ManualResetEvent handle; #region Constructor ////// Instantiate an opened connection enlisted to the Transaction /// if promotable is false, the Transaction wraps a local /// transaction inside and can never be promoted /// /// /// /// internal SharedConnectionInfo( DbResourceAllocator dbResourceAllocator, Transaction transaction, bool wantPromotable, ManualResetEvent handle) { Debug.Assert((transaction != null), "Null Transaction!"); if (null == handle) throw new ArgumentNullException("handle"); this.handle = handle; if (wantPromotable) { // Enlist a newly opened connection to this regular Transaction this.connection = dbResourceAllocator.OpenNewConnection(); this.connection.EnlistTransaction(transaction); } else { // Make this transaction no longer promotable by attaching our // IPromotableSinglePhaseNotification implementation (LocalTranscaction) // and track the DbConnection and DbTransaction associated with the LocalTranscaction LocalTransaction localTransaction = new LocalTransaction(dbResourceAllocator,handle); transaction.EnlistPromotableSinglePhase(localTransaction); this.connection = localTransaction.Connection; this.localTransaction = localTransaction.Transaction; } } #endregion Constructor #region Accessors internal DbConnection DBConnection { get { return this.connection; } } internal DbTransaction DBTransaction { get { return this.localTransaction; } } #endregion Accessors #region IDisposable Members public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } private void Dispose(bool disposing) { if (!this.disposed) { // // If we're using a LocalTransaction it will close the connection // in it's IPromotableSinglePhaseNotification methods if ((this.localTransaction == null)&&(null != connection)) this.connection.Dispose(); } this.disposed = true; } #endregion } } // 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
- OracleMonthSpan.cs
- WindowAutomationPeer.cs
- SapiRecoInterop.cs
- MetadataPropertyvalue.cs
- FactoryGenerator.cs
- AssemblyFilter.cs
- ServiceObjectContainer.cs
- DbRetry.cs
- ModifiableIteratorCollection.cs
- PenThreadWorker.cs
- WorkflowDebuggerSteppingAttribute.cs
- SqlProcedureAttribute.cs
- ProvidersHelper.cs
- SR.Designer.cs
- TypedDataSetSchemaImporterExtensionFx35.cs
- UnsafeNativeMethods.cs
- WindowsGraphics2.cs
- QueryLifecycle.cs
- PreloadedPackages.cs
- FileChangeNotifier.cs
- DispatcherTimer.cs
- ValuePatternIdentifiers.cs
- TouchesCapturedWithinProperty.cs
- SystemException.cs
- DbTransaction.cs
- SynchronizationContext.cs
- TextParagraphCache.cs
- ServiceInfo.cs
- SpnEndpointIdentity.cs
- CroppedBitmap.cs
- UserNamePasswordValidator.cs
- ObjectManager.cs
- BamlLocalizableResource.cs
- TargetParameterCountException.cs
- SqlCommandBuilder.cs
- XmlText.cs
- MultiSelector.cs
- SqlUtils.cs
- WindowsGraphicsCacheManager.cs
- PreservationFileWriter.cs
- Style.cs
- WsiProfilesElementCollection.cs
- ObjectIDGenerator.cs
- DataBindingHandlerAttribute.cs
- ConfigXmlComment.cs
- PaperSource.cs
- securitycriticaldataformultiplegetandset.cs
- UnsafeNativeMethods.cs
- OptimisticConcurrencyException.cs
- TreeNodeMouseHoverEvent.cs
- TextContainerChangedEventArgs.cs
- OverrideMode.cs
- ListViewEditEventArgs.cs
- Oci.cs
- MenuStrip.cs
- WSSecurityJan2004.cs
- ProxyManager.cs
- TextParagraphView.cs
- FixedTextContainer.cs
- TextFormatterImp.cs
- DataGridColumnCollection.cs
- ListViewDataItem.cs
- ChannelTraceRecord.cs
- BindingValueChangedEventArgs.cs
- ManagementObjectCollection.cs
- SystemTcpStatistics.cs
- ProtocolElementCollection.cs
- XmlSequenceWriter.cs
- shaperfactoryquerycacheentry.cs
- DataServiceResponse.cs
- SerialReceived.cs
- basenumberconverter.cs
- AlphabeticalEnumConverter.cs
- MetadataFile.cs
- SemaphoreSecurity.cs
- DataTableCollection.cs
- FixedSOMLineCollection.cs
- PointAnimationClockResource.cs
- XmlDocument.cs
- HttpCachePolicyWrapper.cs
- UIElement.cs
- OleDbSchemaGuid.cs
- DescendantQuery.cs
- KeyBinding.cs
- HttpWebResponse.cs
- DbReferenceCollection.cs
- Helpers.cs
- AnnouncementEndpointElement.cs
- BindingContext.cs
- FrugalList.cs
- X500Name.cs
- CollectionViewProxy.cs
- LocalFileSettingsProvider.cs
- ConsoleCancelEventArgs.cs
- CallTemplateAction.cs
- ErrorStyle.cs
- MetadataCollection.cs
- ColorMap.cs
- UndirectedGraph.cs
- DocumentXmlWriter.cs