Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / WorkflowPersistenceContext.cs / 1305376 / WorkflowPersistenceContext.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities
{
using System.Collections.Generic;
using System.Transactions;
using System.Runtime;
class WorkflowPersistenceContext
{
CommittableTransaction contextOwnedTransaction;
Transaction clonedTransaction;
public WorkflowPersistenceContext(bool transactionRequired, TimeSpan transactionTimeout)
: this(transactionRequired, CloneAmbientTransaction(), transactionTimeout)
{
}
public WorkflowPersistenceContext(bool transactionRequired, Transaction transactionToUse, TimeSpan transactionTimeout)
{
if (transactionToUse != null)
{
this.clonedTransaction = transactionToUse;
}
else if (transactionRequired)
{
this.contextOwnedTransaction = new CommittableTransaction(transactionTimeout);
// Clone it so that we don't pass a CommittableTransaction to the participants
this.clonedTransaction = this.contextOwnedTransaction.Clone();
}
}
public Transaction PublicTransaction
{
get
{
return this.clonedTransaction;
}
}
public void Abort()
{
if (this.contextOwnedTransaction != null)
{
try
{
this.contextOwnedTransaction.Rollback();
}
catch (Exception e)
{
if (Fx.IsFatal(e))
{
throw;
}
// ---- these exceptions as we are already on the error path
}
}
}
public void Complete()
{
if (this.contextOwnedTransaction != null)
{
this.contextOwnedTransaction.Commit();
}
}
// Returns true if end needs to be called
// Note: this is side effecting even if it returns false
public bool TryBeginComplete(AsyncCallback callback, object state, out IAsyncResult result)
{
// In the interest of allocating less objects we don't implement
// the full async pattern here. Instead, we've flattened it to
// do the [....] part and then optionally delegate down to the inner
// BeginCommit.
if (this.contextOwnedTransaction != null)
{
result = this.contextOwnedTransaction.BeginCommit(callback, state);
return true;
}
else
{
result = null;
return false;
}
}
public void EndComplete(IAsyncResult result)
{
Fx.Assert(this.contextOwnedTransaction != null, "We must have a contextOwnedTransaction if we are calling End");
this.contextOwnedTransaction.EndCommit(result);
}
// We might as well clone the ambient transaction so that PersistenceParticipants
// can't cast to a CommittableTransaction.
static Transaction CloneAmbientTransaction()
{
Transaction ambientTransaction = Transaction.Current;
return ambientTransaction == null ? null : ambientTransaction.Clone();
}
}
}
// 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
- PageAction.cs
- ProfileSettings.cs
- CompareValidator.cs
- SafeUserTokenHandle.cs
- SelectionItemPattern.cs
- WebPartExportVerb.cs
- DetailsViewInsertedEventArgs.cs
- AsymmetricSignatureFormatter.cs
- RowParagraph.cs
- SessionParameter.cs
- SerializerDescriptor.cs
- XmlSortKey.cs
- RenderData.cs
- OrthographicCamera.cs
- ResourceContainer.cs
- BigInt.cs
- DrawingAttributes.cs
- UInt32Converter.cs
- Image.cs
- PathFigureCollectionConverter.cs
- ToolTipAutomationPeer.cs
- SystemDiagnosticsSection.cs
- UriTemplateClientFormatter.cs
- DictionarySectionHandler.cs
- Type.cs
- APCustomTypeDescriptor.cs
- HttpValueCollection.cs
- SortedDictionary.cs
- FixedSOMImage.cs
- IdentityReference.cs
- XmlCollation.cs
- _ProxyRegBlob.cs
- SqlUdtInfo.cs
- DataRecordInternal.cs
- KeyToListMap.cs
- AsyncPostBackErrorEventArgs.cs
- ConstructorNeedsTagAttribute.cs
- EndpointNameMessageFilter.cs
- SqlUtils.cs
- MarkupExtensionParser.cs
- StringAnimationUsingKeyFrames.cs
- XmlNamespaceMappingCollection.cs
- CssTextWriter.cs
- IntegerFacetDescriptionElement.cs
- HttpListener.cs
- AjaxFrameworkAssemblyAttribute.cs
- EventlogProvider.cs
- JsonSerializer.cs
- BamlTreeMap.cs
- _TLSstream.cs
- CodeIterationStatement.cs
- ClientConfigPaths.cs
- ConfigurationException.cs
- Stacktrace.cs
- UrlAuthFailureHandler.cs
- XmlSortKey.cs
- DesignTimeSiteMapProvider.cs
- RIPEMD160.cs
- Brushes.cs
- XmlFormatExtensionPointAttribute.cs
- XmlNode.cs
- MsdtcClusterUtils.cs
- HexParser.cs
- ProjectionPath.cs
- MatrixKeyFrameCollection.cs
- ADRole.cs
- OdbcParameter.cs
- EdmFunction.cs
- CodeIndexerExpression.cs
- DesignOnlyAttribute.cs
- ProtectedConfiguration.cs
- XmlSchemaIdentityConstraint.cs
- WinFormsUtils.cs
- AttachedAnnotationChangedEventArgs.cs
- EntityConnection.cs
- TimeSpanStorage.cs
- NativeMethods.cs
- SelectionPattern.cs
- SourceInterpreter.cs
- RangeContentEnumerator.cs
- PeekCompletedEventArgs.cs
- FontWeightConverter.cs
- FormViewPagerRow.cs
- SimpleType.cs
- DropDownList.cs
- PropertyStore.cs
- ProjectionCamera.cs
- CryptographicAttribute.cs
- VirtualPathUtility.cs
- OuterGlowBitmapEffect.cs
- ToolStripItemCollection.cs
- BufferBuilder.cs
- _CookieModule.cs
- Int32CAMarshaler.cs
- ShimAsPublicXamlType.cs
- XPathNodeIterator.cs
- SqlRowUpdatingEvent.cs
- ServicePointManager.cs
- KeysConverter.cs
- WpfPayload.cs