Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WF / RunTime / Hosting / DefaultWorkflowTransactionService.cs / 1305376 / DefaultWorkflowTransactionService.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- using System; using System.Transactions; using System.Collections.Specialized; using System.Diagnostics; using System.Configuration; namespace System.Workflow.Runtime.Hosting { ///A simple TransactionService that creates /// public class DefaultWorkflowCommitWorkBatchService : WorkflowCommitWorkBatchService { private bool _enableRetries = false; private bool _ignoreCommonEnableRetries = false; public DefaultWorkflowCommitWorkBatchService() { } public DefaultWorkflowCommitWorkBatchService(NameValueCollection parameters) { if (parameters == null) throw new ArgumentNullException("parameters", ExecutionStringManager.MissingParameters); if (parameters.Count > 0) { foreach (string key in parameters.Keys) { if (0 == string.Compare("EnableRetries", key, StringComparison.OrdinalIgnoreCase)) { _enableRetries = bool.Parse(parameters[key]); _ignoreCommonEnableRetries = true; } } } } public bool EnableRetries { get { return _enableRetries; } set { _enableRetries = value; _ignoreCommonEnableRetries = true; } } protected internal override void Start() { WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "DefaultWorkflowCommitWorkBatchService: Starting"); // // If we didn't find a local value for enable retries // check in the common section if ((!_ignoreCommonEnableRetries)&&(null != base.Runtime)) { NameValueConfigurationCollection commonConfigurationParameters = base.Runtime.CommonParameters; if (commonConfigurationParameters != null) { // Then scan for connection string in the common configuration parameters section foreach (string key in commonConfigurationParameters.AllKeys) { if (string.Compare("EnableRetries", key, StringComparison.OrdinalIgnoreCase) == 0) { _enableRetries = bool.Parse(commonConfigurationParameters[key].Value); break; } } } } base.Start(); } protected override void OnStopped() { WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "DefaultWorkflowCommitWorkBatchService: Stopping"); base.OnStopped(); } internal protected override void CommitWorkBatch(CommitWorkBatchCallback commitWorkBatchCallback) { DbRetry dbRetry = new DbRetry(_enableRetries); short retryCounter = 0; while (true) { if (null != Transaction.Current) { // // Can't retry as we don't own the tx // Set the counter to only allow one iteration retryCounter = dbRetry.MaxRetries; } try { base.CommitWorkBatch(commitWorkBatchCallback); break; } catch( Exception e ) { WorkflowTrace.Host.TraceEvent(TraceEventType.Error, 0, "DefaultWorkflowCommitWorkBatchService caught exception from commitWorkBatchCallback: " + e.ToString()); if (dbRetry.TryDoRetry(ref retryCounter)) { WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "DefaultWorkflowCommitWorkBatchService retrying commitWorkBatchCallback (retry attempt " + retryCounter.ToString(System.Globalization.CultureInfo.InvariantCulture) + ")"); continue; } else throw; } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //System.Transactions.CommittableTransaction .// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- using System; using System.Transactions; using System.Collections.Specialized; using System.Diagnostics; using System.Configuration; namespace System.Workflow.Runtime.Hosting { ///A simple TransactionService that creates /// public class DefaultWorkflowCommitWorkBatchService : WorkflowCommitWorkBatchService { private bool _enableRetries = false; private bool _ignoreCommonEnableRetries = false; public DefaultWorkflowCommitWorkBatchService() { } public DefaultWorkflowCommitWorkBatchService(NameValueCollection parameters) { if (parameters == null) throw new ArgumentNullException("parameters", ExecutionStringManager.MissingParameters); if (parameters.Count > 0) { foreach (string key in parameters.Keys) { if (0 == string.Compare("EnableRetries", key, StringComparison.OrdinalIgnoreCase)) { _enableRetries = bool.Parse(parameters[key]); _ignoreCommonEnableRetries = true; } } } } public bool EnableRetries { get { return _enableRetries; } set { _enableRetries = value; _ignoreCommonEnableRetries = true; } } protected internal override void Start() { WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "DefaultWorkflowCommitWorkBatchService: Starting"); // // If we didn't find a local value for enable retries // check in the common section if ((!_ignoreCommonEnableRetries)&&(null != base.Runtime)) { NameValueConfigurationCollection commonConfigurationParameters = base.Runtime.CommonParameters; if (commonConfigurationParameters != null) { // Then scan for connection string in the common configuration parameters section foreach (string key in commonConfigurationParameters.AllKeys) { if (string.Compare("EnableRetries", key, StringComparison.OrdinalIgnoreCase) == 0) { _enableRetries = bool.Parse(commonConfigurationParameters[key].Value); break; } } } } base.Start(); } protected override void OnStopped() { WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "DefaultWorkflowCommitWorkBatchService: Stopping"); base.OnStopped(); } internal protected override void CommitWorkBatch(CommitWorkBatchCallback commitWorkBatchCallback) { DbRetry dbRetry = new DbRetry(_enableRetries); short retryCounter = 0; while (true) { if (null != Transaction.Current) { // // Can't retry as we don't own the tx // Set the counter to only allow one iteration retryCounter = dbRetry.MaxRetries; } try { base.CommitWorkBatch(commitWorkBatchCallback); break; } catch( Exception e ) { WorkflowTrace.Host.TraceEvent(TraceEventType.Error, 0, "DefaultWorkflowCommitWorkBatchService caught exception from commitWorkBatchCallback: " + e.ToString()); if (dbRetry.TryDoRetry(ref retryCounter)) { WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "DefaultWorkflowCommitWorkBatchService retrying commitWorkBatchCallback (retry attempt " + retryCounter.ToString(System.Globalization.CultureInfo.InvariantCulture) + ")"); continue; } else throw; } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.System.Transactions.CommittableTransaction .
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DesignerForm.cs
- complextypematerializer.cs
- XpsFilter.cs
- SchemaTableOptionalColumn.cs
- CellRelation.cs
- KeyboardEventArgs.cs
- ClonableStack.cs
- ForEachAction.cs
- EmptyEnumerable.cs
- ConnectionStringSettingsCollection.cs
- WebConfigurationHostFileChange.cs
- MembershipPasswordException.cs
- GC.cs
- InheritanceRules.cs
- HostedHttpContext.cs
- Polygon.cs
- ConfigXmlReader.cs
- ErrorsHelper.cs
- DbParameterCollectionHelper.cs
- Util.cs
- AssemblyBuilder.cs
- IHttpResponseInternal.cs
- ViewDesigner.cs
- ComplexBindingPropertiesAttribute.cs
- MultiSelectRootGridEntry.cs
- FixedPosition.cs
- ConstructorArgumentAttribute.cs
- BitArray.cs
- LoadRetryConstantStrategy.cs
- UIElementParaClient.cs
- StackOverflowException.cs
- SourceElementsCollection.cs
- OdbcTransaction.cs
- RedirectionProxy.cs
- AddInControllerImpl.cs
- InputLanguage.cs
- ThemeDictionaryExtension.cs
- InvalidProgramException.cs
- CompilerResults.cs
- Metafile.cs
- ImageSourceConverter.cs
- FactoryMaker.cs
- DiagnosticTraceSource.cs
- mactripleDES.cs
- DataGridViewSelectedColumnCollection.cs
- EventLogPropertySelector.cs
- DeviceContext.cs
- XPathNodePointer.cs
- OLEDB_Enum.cs
- _OverlappedAsyncResult.cs
- versioninfo.cs
- HttpHandler.cs
- ExtentCqlBlock.cs
- HtmlButton.cs
- WebPartAuthorizationEventArgs.cs
- UserPersonalizationStateInfo.cs
- EdmComplexPropertyAttribute.cs
- MobileControlPersister.cs
- Int32RectValueSerializer.cs
- DbConnectionHelper.cs
- InfoCardClaim.cs
- CodeGroup.cs
- SmiEventStream.cs
- RegistrationServices.cs
- TypeGeneratedEventArgs.cs
- SqlDependency.cs
- DummyDataSource.cs
- BitmapDownload.cs
- VariableDesigner.xaml.cs
- FileDialogPermission.cs
- ObjectPersistData.cs
- ScriptingJsonSerializationSection.cs
- EdmComplexPropertyAttribute.cs
- WebPartEditorOkVerb.cs
- GeometryValueSerializer.cs
- DmlSqlGenerator.cs
- Point3D.cs
- ObjectDisposedException.cs
- Int16Animation.cs
- ParameterCollection.cs
- SystemInformation.cs
- BitSet.cs
- CodeTypeReferenceCollection.cs
- DataControlFieldHeaderCell.cs
- TypeElement.cs
- WindowsSlider.cs
- XPathDocumentBuilder.cs
- AttachedPropertyMethodSelector.cs
- ConsoleKeyInfo.cs
- CharacterBuffer.cs
- ConfigurationSchemaErrors.cs
- SemanticResolver.cs
- QuaternionAnimationUsingKeyFrames.cs
- _SecureChannel.cs
- FileIOPermission.cs
- CompositeFontParser.cs
- CodeValidator.cs
- VisualBrush.cs
- CounterSample.cs
- CompiledIdentityConstraint.cs