Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx35 / System.WorkflowServices / System / ServiceModel / Description / WorkflowRuntimeBehavior.cs / 1305376 / WorkflowRuntimeBehavior.cs
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------
namespace System.ServiceModel.Description
{
using System.Globalization;
using System.ServiceModel.Administration;
using System.ServiceModel.Dispatcher;
using System.Workflow.Runtime;
using System.Workflow.Runtime.Configuration;
using System.Workflow.Runtime.Hosting;
public class WorkflowRuntimeBehavior : IServiceBehavior, IWmiInstanceProvider
{
internal static readonly TimeSpan DefaultCachedInstanceExpiration = TimeSpan.Parse(DefaultCachedInstanceExpirationString, CultureInfo.InvariantCulture);
//default of 10 minutes chosen to be in-parity with SM inactivity timeout for session.
internal const string DefaultCachedInstanceExpirationString = "00:10:00";
internal const string defaultName = "WorkflowRuntime";
internal const bool DefaultValidateOnCreate = true;
static WorkflowRuntimeSection defaultWorkflowRuntimeSection;
TimeSpan cachedInstanceExpiration;
bool validateOnCreate;
WorkflowRuntime workflowRuntime = null;
public WorkflowRuntimeBehavior() : this(null, DefaultCachedInstanceExpiration, DefaultValidateOnCreate)
{
// empty
}
internal WorkflowRuntimeBehavior(WorkflowRuntime workflowRuntime, TimeSpan cachedInstanceExpiration, bool validateOnCreate)
{
this.workflowRuntime = workflowRuntime;
this.cachedInstanceExpiration = cachedInstanceExpiration;
this.validateOnCreate = validateOnCreate;
}
public TimeSpan CachedInstanceExpiration
{
get
{
return this.cachedInstanceExpiration;
}
set
{
if (value < TimeSpan.Zero)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value"));
}
this.cachedInstanceExpiration = value;
}
}
public WorkflowRuntime WorkflowRuntime
{
get
{
if (this.workflowRuntime == null)
{
this.workflowRuntime = new WorkflowRuntime(WorkflowRuntimeBehavior.DefaultWorkflowRuntimeSection);
}
return this.workflowRuntime;
}
}
internal bool ValidateOnCreate
{
get { return this.validateOnCreate; }
}
static WorkflowRuntimeSection DefaultWorkflowRuntimeSection
{
get
{
if (defaultWorkflowRuntimeSection == null)
{
WorkflowRuntimeSection tempSection = new WorkflowRuntimeSection();
tempSection.ValidateOnCreate = false;
tempSection.EnablePerformanceCounters = true;
tempSection.Name = defaultName;
defaultWorkflowRuntimeSection = tempSection;
}
return defaultWorkflowRuntimeSection;
}
}
public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, System.Collections.ObjectModel.Collection endpoints, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
{
}
public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
if (serviceHostBase == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceHostBase");
}
if (serviceHostBase.Extensions == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceHostBase.Extensions");
}
WorkflowInstanceLifetimeManagerExtension cachedInstanceExpirationExtension = new WorkflowInstanceLifetimeManagerExtension(
this.WorkflowRuntime,
this.CachedInstanceExpiration,
this.WorkflowRuntime.GetService() != null);
serviceHostBase.Extensions.Add(cachedInstanceExpirationExtension);
}
void IWmiInstanceProvider.FillInstance(IWmiInstance wmiInstance)
{
wmiInstance.SetProperty("CachedInstanceExpiration", this.CachedInstanceExpiration.ToString());
}
string IWmiInstanceProvider.GetInstanceType()
{
return "WorkflowRuntimeBehavior";
}
public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
ValidateWorkflowRuntime(this.WorkflowRuntime);
}
void ValidateWorkflowRuntime(WorkflowRuntime workflowRuntime)
{
if (workflowRuntime.IsStarted)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.WorkflowRuntimeStartedBeforeHostOpen)));
}
WorkflowSchedulerService workflowSchedulerService = workflowRuntime.GetService();
if (!(workflowSchedulerService is SynchronizationContextWorkflowSchedulerService))
{
if (workflowSchedulerService != null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.WrongSchedulerServiceRegistered)));
}
workflowRuntime.AddService(new SynchronizationContextWorkflowSchedulerService());
}
}
}
}
// 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
- XmlDownloadManager.cs
- UrlMappingsModule.cs
- UITypeEditor.cs
- UnknownWrapper.cs
- FastEncoderWindow.cs
- MultilineStringConverter.cs
- RpcAsyncResult.cs
- UIPermission.cs
- VisualStyleInformation.cs
- ProfileEventArgs.cs
- PngBitmapEncoder.cs
- SynchronousReceiveElement.cs
- FormViewPageEventArgs.cs
- AmbientLight.cs
- DataKey.cs
- ConfigurationSchemaErrors.cs
- BitmapImage.cs
- StrokeNodeOperations2.cs
- WebPartExportVerb.cs
- XmlSiteMapProvider.cs
- XmlSchemaSimpleContentExtension.cs
- XmlIgnoreAttribute.cs
- ColumnReorderedEventArgs.cs
- CutCopyPasteHelper.cs
- UnknownMessageReceivedEventArgs.cs
- DBNull.cs
- DPTypeDescriptorContext.cs
- Or.cs
- WebConfigurationHost.cs
- METAHEADER.cs
- RawStylusActions.cs
- RowBinding.cs
- SqlNamer.cs
- SqlClientWrapperSmiStreamChars.cs
- TextTabProperties.cs
- JoinElimination.cs
- Underline.cs
- wpf-etw.cs
- LoginView.cs
- SplayTreeNode.cs
- MultiView.cs
- ActivityExecutionContextCollection.cs
- NotificationContext.cs
- hebrewshape.cs
- NameValueSectionHandler.cs
- ObjectDataSource.cs
- MimePart.cs
- AutomationPatternInfo.cs
- DbProviderServices.cs
- DataStreamFromComStream.cs
- StorageEntityTypeMapping.cs
- SystemThemeKey.cs
- InputScopeConverter.cs
- HttpListenerException.cs
- DataControlPagerLinkButton.cs
- PkcsUtils.cs
- WindowsListViewGroup.cs
- XmlSchemaProviderAttribute.cs
- HiddenFieldPageStatePersister.cs
- FixedSOMPage.cs
- StylusPointCollection.cs
- EnumValAlphaComparer.cs
- DataContractSerializerOperationGenerator.cs
- MenuItemCollection.cs
- ReadingWritingEntityEventArgs.cs
- DbProviderFactoriesConfigurationHandler.cs
- XmlText.cs
- WebPartMenu.cs
- HttpStreams.cs
- ToolStripComboBox.cs
- UdpConstants.cs
- XmlLoader.cs
- SqlConnectionPoolProviderInfo.cs
- SizeF.cs
- StreamGeometry.cs
- DataColumnCollection.cs
- DataRow.cs
- CustomError.cs
- BindStream.cs
- SingleObjectCollection.cs
- StreamingContext.cs
- MimeObjectFactory.cs
- TypeDescriptionProviderAttribute.cs
- XhtmlBasicFormAdapter.cs
- TextEmbeddedObject.cs
- WebControlAdapter.cs
- WsdlParser.cs
- ScrollProviderWrapper.cs
- RegexTree.cs
- AccessDataSourceDesigner.cs
- Splitter.cs
- SafeArrayTypeMismatchException.cs
- MethodBuilderInstantiation.cs
- RtfToXamlLexer.cs
- SharedUtils.cs
- TypedMessageConverter.cs
- MethodExecutor.cs
- Column.cs
- DynamicEntity.cs
- AffineTransform3D.cs