1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
//------------------------------------------------------------
// 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;
[Obsolete("The WF3 types are deprecated. Instead, please use the new WF4 types from System.Activities.*")]
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<ServiceEndpoint> 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<WorkflowPersistenceService>() != 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<WorkflowSchedulerService>();
if (!(workflowSchedulerService is SynchronizationContextWorkflowSchedulerService))
{
if (workflowSchedulerService != null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.WrongSchedulerServiceRegistered)));
}
workflowRuntime.AddService(new SynchronizationContextWorkflowSchedulerService());
}
}
}
}
|