You've already forked linux-packaging-mono
Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
parent
a569aebcfd
commit
e79aa3c0ed
@@ -0,0 +1,75 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
namespace System.ServiceModel.Description
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Workflow.ComponentModel;
|
||||
using System.Workflow.Runtime;
|
||||
|
||||
class DescriptionCreator
|
||||
{
|
||||
WorkflowDefinitionContext workflowDefinitionContext;
|
||||
|
||||
public DescriptionCreator(WorkflowDefinitionContext workflowDefinitionContext)
|
||||
{
|
||||
if (workflowDefinitionContext == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("workflowDefinitionContext");
|
||||
}
|
||||
this.workflowDefinitionContext = workflowDefinitionContext;
|
||||
}
|
||||
|
||||
public ServiceDescription BuildServiceDescription(out IDictionary<string, ContractDescription> implementedContracts, out IList<Type> reflectedContracts)
|
||||
{
|
||||
ServiceDescriptionContext context = new ServiceDescriptionContext();
|
||||
|
||||
ServiceDescription description = new ServiceDescription();
|
||||
ApplyBehaviors(description);
|
||||
|
||||
context.ServiceDescription = description;
|
||||
|
||||
Walker walker = new Walker(true);
|
||||
walker.FoundActivity += delegate(Walker w, WalkerEventArgs args)
|
||||
{
|
||||
IServiceDescriptionBuilder activity = args.CurrentActivity as IServiceDescriptionBuilder;
|
||||
if (activity == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
activity.BuildServiceDescription(context);
|
||||
};
|
||||
|
||||
walker.Walk(this.workflowDefinitionContext.GetWorkflowDefinition());
|
||||
|
||||
if (context.Contracts == null || context.Contracts.Count == 0)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.NoContract)));
|
||||
}
|
||||
|
||||
implementedContracts = context.Contracts;
|
||||
reflectedContracts = context.ReflectedContracts;
|
||||
return description;
|
||||
}
|
||||
|
||||
void ApplyBehaviors(ServiceDescription serviceDescription)
|
||||
{
|
||||
WorkflowServiceBehavior wsb = new WorkflowServiceBehavior(workflowDefinitionContext);
|
||||
serviceDescription.Behaviors.Add(wsb);
|
||||
|
||||
if (wsb.Name != null)
|
||||
{
|
||||
serviceDescription.Name = wsb.Name;
|
||||
}
|
||||
if (wsb.Namespace != null)
|
||||
{
|
||||
serviceDescription.Namespace = wsb.Namespace;
|
||||
}
|
||||
if (wsb.ConfigurationName != null)
|
||||
{
|
||||
serviceDescription.ConfigurationName = wsb.ConfigurationName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
namespace System.ServiceModel.Description
|
||||
{
|
||||
using System;
|
||||
using System.ServiceModel.Dispatcher;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.ServiceModel.Administration;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
[Obsolete("The WF3 types are deprecated. Instead, please use the new WF4 types from System.Activities.*")]
|
||||
public sealed class DurableOperationAttribute : Attribute, IOperationBehavior, IWmiInstanceProvider
|
||||
{
|
||||
static DurableOperationAttribute defaultInstance = new DurableOperationAttribute();
|
||||
bool canCreateInstance;
|
||||
bool canCreateInstanceSetExplicitly;
|
||||
bool completesInstance;
|
||||
|
||||
public DurableOperationAttribute()
|
||||
{
|
||||
this.completesInstance = false;
|
||||
}
|
||||
|
||||
public bool CanCreateInstance
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.canCreateInstance;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.canCreateInstance = value;
|
||||
this.canCreateInstanceSetExplicitly = true;
|
||||
}
|
||||
}
|
||||
|
||||
public bool CompletesInstance
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.completesInstance;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.completesInstance = value;
|
||||
}
|
||||
}
|
||||
|
||||
internal static DurableOperationAttribute DefaultInstance
|
||||
{
|
||||
get
|
||||
{
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddBindingParameters(
|
||||
OperationDescription operationDescription,
|
||||
BindingParameterCollection bindingParameters)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
public void ApplyDispatchBehavior(
|
||||
OperationDescription operationDescription,
|
||||
DispatchOperation dispatchOperation)
|
||||
{
|
||||
if (dispatchOperation == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("dispatchOperation");
|
||||
}
|
||||
|
||||
if (dispatchOperation.Invoker == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
|
||||
new InvalidOperationException(
|
||||
SR2.GetString(
|
||||
SR2.ExistingIOperationInvokerRequired,
|
||||
typeof(DurableOperationAttribute).Name)));
|
||||
}
|
||||
|
||||
if (operationDescription == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("operationDescription");
|
||||
}
|
||||
|
||||
if (operationDescription.DeclaringContract == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(
|
||||
"operationDescription",
|
||||
SR2.GetString(SR2.OperationDescriptionNeedsDeclaringContract));
|
||||
}
|
||||
|
||||
bool canCreate = CanCreateInstanceForOperation(dispatchOperation.IsOneWay);
|
||||
|
||||
dispatchOperation.Invoker =
|
||||
new ServiceOperationInvoker(
|
||||
dispatchOperation.Invoker,
|
||||
this.CompletesInstance,
|
||||
canCreate,
|
||||
operationDescription.DeclaringContract.SessionMode != SessionMode.NotAllowed);
|
||||
}
|
||||
|
||||
void IWmiInstanceProvider.FillInstance(IWmiInstance wmiInstance)
|
||||
{
|
||||
wmiInstance.SetProperty("CanCreateInstance", this.CanCreateInstance);
|
||||
wmiInstance.SetProperty("CompletesInstance", this.CompletesInstance);
|
||||
}
|
||||
|
||||
string IWmiInstanceProvider.GetInstanceType()
|
||||
{
|
||||
return "DurableOperationAttribute";
|
||||
}
|
||||
|
||||
public void Validate(OperationDescription operationDescription)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
internal bool CanCreateInstanceForOperation(bool isOneWay)
|
||||
{
|
||||
bool canCreate = false;
|
||||
|
||||
if (this.canCreateInstanceSetExplicitly)
|
||||
{
|
||||
canCreate = this.canCreateInstance;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isOneWay)
|
||||
{
|
||||
canCreate = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
canCreate = true;
|
||||
}
|
||||
}
|
||||
|
||||
return canCreate;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,352 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
namespace System.ServiceModel.Description
|
||||
{
|
||||
using System;
|
||||
using System.Runtime;
|
||||
using System.ServiceModel.Administration;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.ServiceModel.Dispatcher;
|
||||
using System.ServiceModel.Persistence;
|
||||
using System.Xml;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
[Obsolete("The WF3 types are deprecated. Instead, please use the new WF4 types from System.Activities.*")]
|
||||
public sealed class DurableServiceAttribute : Attribute, IServiceBehavior, IContextSessionProvider, IWmiInstanceProvider
|
||||
{
|
||||
static DurableOperationAttribute defaultDurableOperationBehavior = new DurableOperationAttribute();
|
||||
bool saveStateInOperationTransaction;
|
||||
UnknownExceptionAction unknownExceptionAction;
|
||||
|
||||
public DurableServiceAttribute()
|
||||
{
|
||||
this.unknownExceptionAction = UnknownExceptionAction.TerminateInstance;
|
||||
}
|
||||
|
||||
public bool SaveStateInOperationTransaction
|
||||
{
|
||||
get { return this.saveStateInOperationTransaction; }
|
||||
set { this.saveStateInOperationTransaction = value; }
|
||||
}
|
||||
|
||||
public UnknownExceptionAction UnknownExceptionAction
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.unknownExceptionAction;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!UnknownExceptionActionHelper.IsDefined(value))
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value"));
|
||||
}
|
||||
|
||||
this.unknownExceptionAction = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, System.Collections.ObjectModel.Collection<ServiceEndpoint> endpoints, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
|
||||
{
|
||||
if (serviceDescription == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceDescription");
|
||||
}
|
||||
|
||||
if (serviceHostBase == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceHostBase");
|
||||
}
|
||||
|
||||
if (serviceDescription.Endpoints == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("serviceDescription", SR2.GetString(SR2.NoEndpoints));
|
||||
}
|
||||
|
||||
PersistenceProviderBehavior providerBehavior = null;
|
||||
|
||||
if (serviceDescription.Behaviors != null)
|
||||
{
|
||||
providerBehavior = serviceDescription.Behaviors.Find<PersistenceProviderBehavior>();
|
||||
}
|
||||
|
||||
if (providerBehavior == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
|
||||
new InvalidOperationException(
|
||||
SR2.GetString(
|
||||
SR2.NonNullPersistenceProviderRequired,
|
||||
typeof(PersistenceProvider).Name,
|
||||
typeof(DurableServiceAttribute).Name)));
|
||||
}
|
||||
|
||||
if (providerBehavior.PersistenceProviderFactory == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
|
||||
new InvalidOperationException(
|
||||
SR2.GetString(
|
||||
SR2.NonNullPersistenceProviderRequired,
|
||||
typeof(PersistenceProvider).Name,
|
||||
typeof(DurableServiceAttribute).Name)));
|
||||
}
|
||||
|
||||
providerBehavior.PersistenceProviderFactory.Open();
|
||||
serviceHostBase.Closed += new EventHandler(
|
||||
delegate(object sender, EventArgs args)
|
||||
{
|
||||
Fx.Assert(sender is ServiceHostBase, "The sender should be serviceHostBase.");
|
||||
// We have no way of knowing whether the service host closed or aborted
|
||||
// so we err on the side of abort for right now.
|
||||
providerBehavior.PersistenceProviderFactory.Abort();
|
||||
}
|
||||
);
|
||||
|
||||
DurableInstanceContextProvider instanceContextProvider = new ServiceDurableInstanceContextProvider(
|
||||
serviceHostBase,
|
||||
false,
|
||||
serviceDescription.ServiceType,
|
||||
providerBehavior.PersistenceProviderFactory,
|
||||
this.saveStateInOperationTransaction,
|
||||
this.unknownExceptionAction,
|
||||
new DurableRuntimeValidator(this.saveStateInOperationTransaction, this.unknownExceptionAction),
|
||||
providerBehavior.PersistenceOperationTimeout);
|
||||
|
||||
DurableInstanceContextProvider singleCallInstanceContextProvider = null;
|
||||
|
||||
IInstanceProvider instanceProvider = new DurableInstanceProvider(instanceContextProvider);
|
||||
|
||||
bool includeExceptionDetails = false;
|
||||
|
||||
if (serviceDescription.Behaviors != null)
|
||||
{
|
||||
ServiceBehaviorAttribute serviceBehavior = serviceDescription.Behaviors.Find<ServiceBehaviorAttribute>();
|
||||
|
||||
if (serviceBehavior != null)
|
||||
{
|
||||
includeExceptionDetails |= serviceBehavior.IncludeExceptionDetailInFaults;
|
||||
}
|
||||
|
||||
ServiceDebugBehavior serviceDebugBehavior = serviceDescription.Behaviors.Find<ServiceDebugBehavior>();
|
||||
|
||||
if (serviceDebugBehavior != null)
|
||||
{
|
||||
includeExceptionDetails |= serviceDebugBehavior.IncludeExceptionDetailInFaults;
|
||||
}
|
||||
}
|
||||
|
||||
IErrorHandler errorHandler = new ServiceErrorHandler(includeExceptionDetails);
|
||||
|
||||
foreach (ChannelDispatcherBase channelDispatcherBase in serviceHostBase.ChannelDispatchers)
|
||||
{
|
||||
ChannelDispatcher channelDispatcher = channelDispatcherBase as ChannelDispatcher;
|
||||
|
||||
if (channelDispatcher != null && channelDispatcher.HasApplicationEndpoints())
|
||||
{
|
||||
if (this.unknownExceptionAction == UnknownExceptionAction.AbortInstance)
|
||||
{
|
||||
channelDispatcher.ErrorHandlers.Add(errorHandler);
|
||||
}
|
||||
|
||||
foreach (EndpointDispatcher endpointDispatcher in channelDispatcher.Endpoints)
|
||||
{
|
||||
if (endpointDispatcher.IsSystemEndpoint)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ServiceEndpoint serviceEndPoint = serviceDescription.Endpoints.Find(new XmlQualifiedName(endpointDispatcher.ContractName, endpointDispatcher.ContractNamespace));
|
||||
|
||||
if (serviceEndPoint != null)
|
||||
{
|
||||
if (serviceEndPoint.Contract.SessionMode != SessionMode.NotAllowed)
|
||||
{
|
||||
endpointDispatcher.DispatchRuntime.InstanceContextProvider = instanceContextProvider;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (singleCallInstanceContextProvider == null)
|
||||
{
|
||||
singleCallInstanceContextProvider = new ServiceDurableInstanceContextProvider(
|
||||
serviceHostBase,
|
||||
true,
|
||||
serviceDescription.ServiceType,
|
||||
providerBehavior.PersistenceProviderFactory,
|
||||
this.saveStateInOperationTransaction,
|
||||
this.unknownExceptionAction,
|
||||
new DurableRuntimeValidator(this.saveStateInOperationTransaction, this.unknownExceptionAction),
|
||||
providerBehavior.PersistenceOperationTimeout);
|
||||
}
|
||||
endpointDispatcher.DispatchRuntime.InstanceContextProvider = singleCallInstanceContextProvider;
|
||||
}
|
||||
endpointDispatcher.DispatchRuntime.MessageInspectors.Add(new DurableMessageDispatchInspector(serviceEndPoint.Contract.SessionMode));
|
||||
endpointDispatcher.DispatchRuntime.InstanceProvider = instanceProvider;
|
||||
WorkflowServiceBehavior.SetContractFilterToIncludeAllOperations(endpointDispatcher, serviceEndPoint.Contract);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (ServiceEndpoint endpoint in serviceDescription.Endpoints)
|
||||
{
|
||||
if (!endpoint.InternalIsSystemEndpoint(serviceDescription))
|
||||
{
|
||||
foreach (OperationDescription opDescription in endpoint.Contract.Operations)
|
||||
{
|
||||
if (!opDescription.Behaviors.Contains(typeof(DurableOperationAttribute)))
|
||||
{
|
||||
opDescription.Behaviors.Add(DurableOperationAttribute.DefaultInstance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IWmiInstanceProvider.FillInstance(IWmiInstance wmiInstance)
|
||||
{
|
||||
wmiInstance.SetProperty("SaveStateInOperationTransaction", this.saveStateInOperationTransaction);
|
||||
}
|
||||
|
||||
string IWmiInstanceProvider.GetInstanceType()
|
||||
{
|
||||
return "DurableServiceAttribute";
|
||||
}
|
||||
|
||||
public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
|
||||
{
|
||||
if (serviceDescription == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceDescription");
|
||||
}
|
||||
|
||||
ContextBindingElement.ValidateContextBindingElementOnAllEndpointsWithSessionfulContract(serviceDescription, this);
|
||||
|
||||
if (serviceDescription.Behaviors != null)
|
||||
{
|
||||
ServiceBehaviorAttribute serviceBehavior = serviceDescription.Behaviors.Find<ServiceBehaviorAttribute>();
|
||||
|
||||
if (serviceBehavior != null)
|
||||
{
|
||||
if (serviceBehavior.InstanceContextMode != InstanceContextMode.PerSession)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
|
||||
new InvalidOperationException(
|
||||
SR2.GetString(SR2.InstanceContextModeMustBePerSession, serviceBehavior.InstanceContextMode)));
|
||||
}
|
||||
|
||||
if (serviceBehavior.ConcurrencyMode == ConcurrencyMode.Multiple)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
|
||||
new InvalidOperationException(
|
||||
SR2.GetString(SR2.ConcurrencyMultipleNotSupported)));
|
||||
}
|
||||
|
||||
if (serviceBehavior.ConcurrencyMode == ConcurrencyMode.Reentrant
|
||||
&& this.UnknownExceptionAction == UnknownExceptionAction.AbortInstance)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
|
||||
new InvalidOperationException(
|
||||
SR2.GetString(SR2.ConcurrencyReentrantAndAbortNotSupported)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool foundSessionfulContract = false;
|
||||
|
||||
foreach (ServiceEndpoint serviceEndpoint in serviceDescription.Endpoints)
|
||||
{
|
||||
if (serviceEndpoint != null && !serviceEndpoint.InternalIsSystemEndpoint(serviceDescription))
|
||||
{
|
||||
if (serviceEndpoint.Contract.SessionMode != SessionMode.NotAllowed)
|
||||
{
|
||||
foundSessionfulContract = true;
|
||||
}
|
||||
|
||||
foreach (OperationDescription operation in serviceEndpoint.Contract.Operations)
|
||||
{
|
||||
DurableOperationAttribute durableBehavior =
|
||||
operation.Behaviors.Find<DurableOperationAttribute>();
|
||||
|
||||
if (durableBehavior == null)
|
||||
{
|
||||
durableBehavior = defaultDurableOperationBehavior;
|
||||
}
|
||||
|
||||
if (serviceEndpoint.Contract.SessionMode == SessionMode.NotAllowed)
|
||||
{
|
||||
if (!durableBehavior.CanCreateInstanceForOperation(operation.IsOneWay))
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
|
||||
new InvalidOperationException(
|
||||
SR2.GetString(
|
||||
SR2.CanCreateInstanceMustBeTrue,
|
||||
serviceEndpoint.Contract.Name,
|
||||
operation.Name)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (operation.IsOneWay &&
|
||||
durableBehavior.CanCreateInstanceForOperation(operation.IsOneWay))
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
|
||||
new InvalidOperationException(
|
||||
SR2.GetString(
|
||||
SR2.CanCreateInstanceMustBeTwoWay,
|
||||
serviceEndpoint.Contract.Name,
|
||||
serviceEndpoint.Contract.SessionMode,
|
||||
operation.Name)));
|
||||
}
|
||||
}
|
||||
|
||||
if (this.saveStateInOperationTransaction)
|
||||
{
|
||||
bool hasTransaction = false;
|
||||
|
||||
OperationBehaviorAttribute operationBehavior = operation.Behaviors.Find<OperationBehaviorAttribute>();
|
||||
|
||||
if (operationBehavior != null)
|
||||
{
|
||||
if (operationBehavior.TransactionScopeRequired)
|
||||
{
|
||||
hasTransaction = true;
|
||||
}
|
||||
}
|
||||
|
||||
TransactionFlowAttribute transactionBehavior = operation.Behaviors.Find<TransactionFlowAttribute>();
|
||||
|
||||
if (transactionBehavior != null)
|
||||
{
|
||||
if (transactionBehavior.Transactions == TransactionFlowOption.Mandatory)
|
||||
{
|
||||
hasTransaction = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasTransaction)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
|
||||
new InvalidOperationException(
|
||||
SR2.GetString(
|
||||
SR2.SaveStateInTransactionValidationFailed,
|
||||
operation.Name,
|
||||
serviceEndpoint.ListenUri)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundSessionfulContract)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
|
||||
new InvalidOperationException(
|
||||
SR2.GetString(SR2.SessionfulContractNotFound)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Description
|
||||
{
|
||||
using System;
|
||||
|
||||
interface IServiceDescriptionBuilder
|
||||
{
|
||||
void BuildServiceDescription(ServiceDescriptionContext context);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
namespace System.ServiceModel.Description
|
||||
{
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.ServiceModel.Administration;
|
||||
using System.ServiceModel.Persistence;
|
||||
|
||||
[Obsolete("The WF3 types are deprecated. Instead, please use the new WF4 types from System.Activities.*")]
|
||||
public class PersistenceProviderBehavior : IServiceBehavior, IWmiInstanceProvider
|
||||
{
|
||||
internal static readonly TimeSpan DefaultPersistenceOperationTimeout = TimeSpan.Parse(DefaultPersistenceOperationTimeoutString, CultureInfo.InvariantCulture);
|
||||
// 30 seconds was chosen because it is the default timeout for SqlCommand
|
||||
// (seemed like a reasonable reference point)
|
||||
internal const string DefaultPersistenceOperationTimeoutString = "00:00:30";
|
||||
TimeSpan persistenceOperationTimeout;
|
||||
|
||||
PersistenceProviderFactory persistenceProviderFactory;
|
||||
|
||||
public PersistenceProviderBehavior(PersistenceProviderFactory providerFactory)
|
||||
: this(providerFactory, DefaultPersistenceOperationTimeout)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
public PersistenceProviderBehavior(PersistenceProviderFactory providerFactory, TimeSpan persistenceOperationTimeout)
|
||||
{
|
||||
this.PersistenceProviderFactory = providerFactory;
|
||||
this.PersistenceOperationTimeout = persistenceOperationTimeout;
|
||||
}
|
||||
|
||||
public TimeSpan PersistenceOperationTimeout
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.persistenceOperationTimeout;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value < TimeSpan.Zero)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
|
||||
new ArgumentOutOfRangeException(SR2.GetString(SR2.PersistenceOperationTimeoutOutOfRange)));
|
||||
}
|
||||
this.persistenceOperationTimeout = value;
|
||||
}
|
||||
}
|
||||
|
||||
public PersistenceProviderFactory PersistenceProviderFactory
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.persistenceProviderFactory;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
|
||||
}
|
||||
this.persistenceProviderFactory = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public virtual void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, System.Collections.ObjectModel.Collection<ServiceEndpoint> endpoints, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
public virtual void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
void IWmiInstanceProvider.FillInstance(IWmiInstance wmiInstance)
|
||||
{
|
||||
wmiInstance.SetProperty("PersistenceOperationTimeout", this.PersistenceOperationTimeout.ToString());
|
||||
wmiInstance.SetProperty("PersistenceProviderFactoryType", this.PersistenceProviderFactory.GetType().FullName);
|
||||
}
|
||||
|
||||
string IWmiInstanceProvider.GetInstanceType()
|
||||
{
|
||||
return "PersistenceProviderBehavior";
|
||||
}
|
||||
|
||||
public virtual void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Description
|
||||
{
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ServiceModel;
|
||||
|
||||
class ServiceDescriptionContext
|
||||
{
|
||||
Dictionary<string, ContractDescription> contracts;
|
||||
IList<Type> reflectedContracts;
|
||||
ServiceDescription serviceDescription;
|
||||
Dictionary<KeyValuePair<Type, string>, WorkflowOperationBehavior> workflowOperationBehaviors;
|
||||
|
||||
internal ServiceDescriptionContext()
|
||||
{
|
||||
this.contracts = new Dictionary<string, ContractDescription>();
|
||||
this.reflectedContracts = new List<Type>();
|
||||
this.workflowOperationBehaviors = new Dictionary<KeyValuePair<Type, string>, WorkflowOperationBehavior>();
|
||||
}
|
||||
|
||||
public IDictionary<string, ContractDescription> Contracts
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.contracts;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<Type> ReflectedContracts
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.reflectedContracts;
|
||||
}
|
||||
}
|
||||
|
||||
public ServiceDescription ServiceDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.serviceDescription;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.serviceDescription = value;
|
||||
}
|
||||
}
|
||||
|
||||
internal IDictionary<KeyValuePair<Type, string>, WorkflowOperationBehavior> WorkflowOperationBehaviors
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.workflowOperationBehaviors;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
namespace System.ServiceModel.Description
|
||||
{
|
||||
using System;
|
||||
|
||||
[Obsolete("The WF3 types are deprecated. Instead, please use the new WF4 types from System.Activities.*")]
|
||||
public enum UnknownExceptionAction
|
||||
{
|
||||
TerminateInstance = 0,
|
||||
AbortInstance
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
namespace System.ServiceModel.Description
|
||||
{
|
||||
using System;
|
||||
|
||||
static class UnknownExceptionActionHelper
|
||||
{
|
||||
public static bool IsDefined(UnknownExceptionAction action)
|
||||
{
|
||||
return action == UnknownExceptionAction.AbortInstance ||
|
||||
action == UnknownExceptionAction.TerminateInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
namespace System.ServiceModel.Description
|
||||
{
|
||||
using System.ServiceModel.Dispatcher;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.ServiceModel.Administration;
|
||||
|
||||
class WorkflowOperationBehavior : IOperationBehavior, IWmiInstanceProvider
|
||||
{
|
||||
bool canCreateInstance = true;
|
||||
ServiceAuthorizationManager serviceAuthorizationManager;
|
||||
|
||||
public bool CanCreateInstance
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.canCreateInstance;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.canCreateInstance = value;
|
||||
}
|
||||
}
|
||||
|
||||
public ServiceAuthorizationManager ServiceAuthorizationManager
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.serviceAuthorizationManager;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.serviceAuthorizationManager = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddBindingParameters(OperationDescription description, BindingParameterCollection parameters)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void ApplyClientBehavior(OperationDescription description, ClientOperation proxy)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void ApplyDispatchBehavior(OperationDescription description, DispatchOperation dispatch)
|
||||
{
|
||||
if (description == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("description");
|
||||
}
|
||||
if (dispatch == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("dispatch");
|
||||
}
|
||||
if (dispatch.Parent == null
|
||||
|| dispatch.Parent.ChannelDispatcher == null
|
||||
|| dispatch.Parent.ChannelDispatcher.Host == null
|
||||
|| dispatch.Parent.ChannelDispatcher.Host.Description == null
|
||||
|| dispatch.Parent.ChannelDispatcher.Host.Description.Behaviors == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.DispatchOperationInInvalidState)));
|
||||
}
|
||||
|
||||
WorkflowRuntimeBehavior workflowRuntimeBehavior = dispatch.Parent.ChannelDispatcher.Host.Description.Behaviors.Find<WorkflowRuntimeBehavior>();
|
||||
|
||||
if (workflowRuntimeBehavior == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.NoWorkflowRuntimeBehavior)));
|
||||
}
|
||||
|
||||
dispatch.Invoker = new WorkflowOperationInvoker(description, this, workflowRuntimeBehavior.WorkflowRuntime, dispatch.Parent);
|
||||
}
|
||||
|
||||
void IWmiInstanceProvider.FillInstance(IWmiInstance wmiInstance)
|
||||
{
|
||||
wmiInstance.SetProperty("CanCreateInstance", this.CanCreateInstance);
|
||||
}
|
||||
|
||||
string IWmiInstanceProvider.GetInstanceType()
|
||||
{
|
||||
return "WorkflowOperationBehavior";
|
||||
}
|
||||
|
||||
public void Validate(OperationDescription description)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,471 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
namespace System.ServiceModel.Description
|
||||
{
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Runtime;
|
||||
using System.ServiceModel.Administration;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.ServiceModel.Dispatcher;
|
||||
using System.Workflow.ComponentModel;
|
||||
using System.Workflow.Runtime;
|
||||
using System.Workflow.Runtime.Hosting;
|
||||
using System.Xml;
|
||||
|
||||
class WorkflowServiceBehavior : IServiceBehavior, IContextSessionProvider, IWmiInstanceProvider
|
||||
{
|
||||
static readonly object[] emptyObjectArray = new object[] { };
|
||||
AddressFilterMode addressFilterMode;
|
||||
string configurationName;
|
||||
bool ignoreExtensionDataObject;
|
||||
bool includeExceptionDetailInFaults;
|
||||
int maxItemsInObjectGraph = -1;
|
||||
string name;
|
||||
string nameSpace;
|
||||
bool useSynchronizationContext;
|
||||
bool validateMustUnderstand;
|
||||
WorkflowDefinitionContext workflowDefinitionContext;
|
||||
string workflowDefinitionPath;
|
||||
string workflowRulesPath;
|
||||
|
||||
public WorkflowServiceBehavior(Type workflowType) :
|
||||
this(new CompiledWorkflowDefinitionContext(workflowType))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public WorkflowServiceBehavior(string workflowDefinitionPath)
|
||||
:
|
||||
this(workflowDefinitionPath, null)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public WorkflowServiceBehavior(string workflowDefinitionPath, string ruleDefinitionPath)
|
||||
:
|
||||
this(new StreamedWorkflowDefinitionContext(workflowDefinitionPath, ruleDefinitionPath, null))
|
||||
{
|
||||
this.workflowDefinitionPath = workflowDefinitionPath;
|
||||
this.workflowRulesPath = ruleDefinitionPath;
|
||||
}
|
||||
|
||||
public WorkflowServiceBehavior(Stream workflowDefinitionStream)
|
||||
: this(new StreamedWorkflowDefinitionContext(workflowDefinitionStream, null, null))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public WorkflowServiceBehavior(Stream workflowDefinitionStream, Stream ruleDefinitionStream)
|
||||
: this(new StreamedWorkflowDefinitionContext(workflowDefinitionStream, ruleDefinitionStream, null))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal WorkflowServiceBehavior(WorkflowDefinitionContext workflowDefinitionContext)
|
||||
{
|
||||
if (workflowDefinitionContext == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("workflowDefinitionContext");
|
||||
}
|
||||
|
||||
this.workflowDefinitionContext = workflowDefinitionContext;
|
||||
this.name = this.workflowDefinitionContext.WorkflowName;
|
||||
this.configurationName = this.workflowDefinitionContext.ConfigurationName;
|
||||
}
|
||||
|
||||
public AddressFilterMode AddressFilterMode
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.addressFilterMode;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!AddressFilterModeHelper.IsDefined(value))
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value"));
|
||||
}
|
||||
this.addressFilterMode = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string ConfigurationName
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.configurationName;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
|
||||
}
|
||||
this.configurationName = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IgnoreExtensionDataObject
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.ignoreExtensionDataObject;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.ignoreExtensionDataObject = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IncludeExceptionDetailInFaults
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.includeExceptionDetailInFaults;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.includeExceptionDetailInFaults = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int MaxItemsInObjectGraph
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.maxItemsInObjectGraph;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.maxItemsInObjectGraph = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
|
||||
}
|
||||
this.name = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string Namespace
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.nameSpace;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
|
||||
}
|
||||
this.nameSpace = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool UseSynchronizationContext
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.useSynchronizationContext;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.useSynchronizationContext = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ValidateMustUnderstand
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.validateMustUnderstand;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.validateMustUnderstand = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void AddBindingParameters(ServiceDescription description, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection parameters)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void ApplyDispatchBehavior(ServiceDescription description, ServiceHostBase serviceHostBase)
|
||||
{
|
||||
if (description == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("description");
|
||||
}
|
||||
|
||||
if (serviceHostBase == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceHostBase");
|
||||
}
|
||||
if (description.Behaviors == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("description", SR2.GetString(SR2.NoBehaviors));
|
||||
}
|
||||
if (description.Endpoints == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("description", SR2.GetString(SR2.NoEndpoints));
|
||||
}
|
||||
|
||||
bool syncContextRegistered = false;
|
||||
WorkflowRuntimeBehavior workflowRuntimeBehavior = description.Behaviors.Find<WorkflowRuntimeBehavior>();
|
||||
|
||||
if (workflowRuntimeBehavior == null)
|
||||
{
|
||||
workflowRuntimeBehavior = new WorkflowRuntimeBehavior();
|
||||
description.Behaviors.Add(workflowRuntimeBehavior);
|
||||
}
|
||||
|
||||
WorkflowPersistenceService persistenceService = workflowRuntimeBehavior.WorkflowRuntime.GetService<WorkflowPersistenceService>();
|
||||
if (persistenceService != null)
|
||||
{
|
||||
bool wasRuntimeStarted = workflowRuntimeBehavior.WorkflowRuntime.IsStarted;
|
||||
if (wasRuntimeStarted)
|
||||
{
|
||||
workflowRuntimeBehavior.WorkflowRuntime.StopRuntime();
|
||||
}
|
||||
workflowRuntimeBehavior.WorkflowRuntime.RemoveService(persistenceService);
|
||||
workflowRuntimeBehavior.WorkflowRuntime.AddService(new SkipUnloadOnFirstIdleWorkflowPersistenceService(persistenceService));
|
||||
if (wasRuntimeStarted)
|
||||
{
|
||||
workflowRuntimeBehavior.WorkflowRuntime.StartRuntime();
|
||||
}
|
||||
}
|
||||
|
||||
this.workflowDefinitionContext.Register(workflowRuntimeBehavior.WorkflowRuntime, workflowRuntimeBehavior.ValidateOnCreate);
|
||||
|
||||
WorkflowInstanceContextProvider instanceContextProvider = new WorkflowInstanceContextProvider(
|
||||
serviceHostBase,
|
||||
false,
|
||||
this.workflowDefinitionContext
|
||||
);
|
||||
|
||||
WorkflowInstanceContextProvider singleCallInstanceContextProvider = null;
|
||||
|
||||
IInstanceProvider instanceProvider = new WorkflowInstanceProvider(instanceContextProvider);
|
||||
ServiceDebugBehavior serviceDebugBehavior = description.Behaviors.Find<ServiceDebugBehavior>();
|
||||
|
||||
bool includeExceptionDetailsInFaults = this.IncludeExceptionDetailInFaults;
|
||||
if (serviceDebugBehavior != null)
|
||||
{
|
||||
includeExceptionDetailsInFaults |= serviceDebugBehavior.IncludeExceptionDetailInFaults;
|
||||
}
|
||||
|
||||
IErrorHandler workflowOperationErrorHandler = new WorkflowOperationErrorHandler(includeExceptionDetailsInFaults);
|
||||
|
||||
foreach (ChannelDispatcherBase channelDispatcherBase in serviceHostBase.ChannelDispatchers)
|
||||
{
|
||||
ChannelDispatcher channelDispatcher = channelDispatcherBase as ChannelDispatcher;
|
||||
|
||||
if (channelDispatcher != null && channelDispatcher.HasApplicationEndpoints())
|
||||
{
|
||||
channelDispatcher.IncludeExceptionDetailInFaults = includeExceptionDetailsInFaults;
|
||||
channelDispatcher.ErrorHandlers.Add(workflowOperationErrorHandler);
|
||||
foreach (EndpointDispatcher endPointDispatcher in channelDispatcher.Endpoints)
|
||||
{
|
||||
if (endPointDispatcher.IsSystemEndpoint)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ServiceEndpoint serviceEndPoint = description.Endpoints.Find(new XmlQualifiedName(endPointDispatcher.ContractName, endPointDispatcher.ContractNamespace));
|
||||
|
||||
if (serviceEndPoint != null)
|
||||
{
|
||||
|
||||
DispatchRuntime dispatchRuntime = endPointDispatcher.DispatchRuntime;
|
||||
|
||||
dispatchRuntime.AutomaticInputSessionShutdown = true;
|
||||
dispatchRuntime.ConcurrencyMode = ConcurrencyMode.Single;
|
||||
dispatchRuntime.ValidateMustUnderstand = this.ValidateMustUnderstand;
|
||||
|
||||
if (!this.UseSynchronizationContext)
|
||||
{
|
||||
dispatchRuntime.SynchronizationContext = null;
|
||||
}
|
||||
else if (!syncContextRegistered)
|
||||
{
|
||||
SynchronizationContextWorkflowSchedulerService syncSchedulerService = workflowRuntimeBehavior.WorkflowRuntime.GetService<SynchronizationContextWorkflowSchedulerService>();
|
||||
Fx.Assert(syncSchedulerService != null, "Wrong Synchronization Context Set");
|
||||
syncSchedulerService.SetSynchronizationContext(dispatchRuntime.SynchronizationContext);
|
||||
syncContextRegistered = true;
|
||||
}
|
||||
|
||||
if (!endPointDispatcher.AddressFilterSetExplicit)
|
||||
{
|
||||
EndpointAddress endPointAddress = endPointDispatcher.OriginalAddress;
|
||||
if ((endPointAddress == null) || (this.AddressFilterMode == AddressFilterMode.Any))
|
||||
{
|
||||
endPointDispatcher.AddressFilter = new MatchAllMessageFilter();
|
||||
}
|
||||
else if (this.AddressFilterMode == AddressFilterMode.Prefix)
|
||||
{
|
||||
endPointDispatcher.AddressFilter = new PrefixEndpointAddressMessageFilter(endPointAddress);
|
||||
}
|
||||
else if (this.AddressFilterMode == AddressFilterMode.Exact)
|
||||
{
|
||||
endPointDispatcher.AddressFilter = new EndpointAddressMessageFilter(endPointAddress);
|
||||
}
|
||||
}
|
||||
|
||||
if (serviceEndPoint.Contract.SessionMode != SessionMode.NotAllowed)
|
||||
{
|
||||
endPointDispatcher.DispatchRuntime.InstanceContextProvider = instanceContextProvider;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (singleCallInstanceContextProvider == null)
|
||||
{
|
||||
singleCallInstanceContextProvider = new WorkflowInstanceContextProvider(
|
||||
serviceHostBase,
|
||||
true,
|
||||
this.workflowDefinitionContext);
|
||||
}
|
||||
endPointDispatcher.DispatchRuntime.InstanceContextProvider = singleCallInstanceContextProvider;
|
||||
}
|
||||
endPointDispatcher.DispatchRuntime.MessageInspectors.Add(new DurableMessageDispatchInspector(serviceEndPoint.Contract.SessionMode));
|
||||
endPointDispatcher.DispatchRuntime.InstanceProvider = instanceProvider;
|
||||
SetContractFilterToIncludeAllOperations(endPointDispatcher, serviceEndPoint.Contract);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DataContractSerializerServiceBehavior.ApplySerializationSettings(description, this.ignoreExtensionDataObject, this.maxItemsInObjectGraph);
|
||||
}
|
||||
|
||||
void IWmiInstanceProvider.FillInstance(IWmiInstance wmiInstance)
|
||||
{
|
||||
wmiInstance.SetProperty("AddressFilterMode", this.AddressFilterMode.ToString());
|
||||
wmiInstance.SetProperty("ConfigurationName", this.ConfigurationName);
|
||||
wmiInstance.SetProperty("IgnoreExtensionDataObject", this.IgnoreExtensionDataObject);
|
||||
wmiInstance.SetProperty("IncludeExceptionDetailInFaults", this.IncludeExceptionDetailInFaults);
|
||||
wmiInstance.SetProperty("MaxItemsInObjectGraph", this.MaxItemsInObjectGraph);
|
||||
wmiInstance.SetProperty("Name", this.Name);
|
||||
wmiInstance.SetProperty("Namespace", this.Namespace);
|
||||
wmiInstance.SetProperty("UseSynchronizationContext", this.UseSynchronizationContext);
|
||||
wmiInstance.SetProperty("ValidateMustUnderstand", this.ValidateMustUnderstand);
|
||||
wmiInstance.SetProperty("WorkflowType", this.workflowDefinitionContext.WorkflowName);
|
||||
wmiInstance.SetProperty("WorkflowDefinitionPath", this.workflowDefinitionPath);
|
||||
wmiInstance.SetProperty("WorkflowRulesPath", this.workflowRulesPath);
|
||||
}
|
||||
|
||||
string IWmiInstanceProvider.GetInstanceType()
|
||||
{
|
||||
return "WorkflowServiceBehavior";
|
||||
}
|
||||
|
||||
public void Validate(ServiceDescription description, ServiceHostBase serviceHostBase)
|
||||
{
|
||||
ContextBindingElement.ValidateContextBindingElementOnAllEndpointsWithSessionfulContract(description, this);
|
||||
}
|
||||
|
||||
internal static void SetContractFilterToIncludeAllOperations(EndpointDispatcher dispatcher, ContractDescription contract)
|
||||
{
|
||||
if (dispatcher == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("dispatcher");
|
||||
}
|
||||
if (contract == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contract");
|
||||
}
|
||||
|
||||
if (contract.SessionMode == SessionMode.Required)
|
||||
{
|
||||
EndpointFilterProvider provider = new EndpointFilterProvider();
|
||||
foreach (OperationDescription operation in contract.Operations)
|
||||
{
|
||||
if (!operation.IsServerInitiated())
|
||||
{
|
||||
provider.InitiatingActions.Add(operation.Messages[0].Action);
|
||||
}
|
||||
}
|
||||
int priority;
|
||||
dispatcher.ContractFilter = provider.CreateFilter(out priority);
|
||||
dispatcher.FilterPriority = priority;
|
||||
}
|
||||
}
|
||||
|
||||
class SkipUnloadOnFirstIdleWorkflowPersistenceService : WorkflowPersistenceService
|
||||
{
|
||||
WorkflowPersistenceService inner;
|
||||
|
||||
public SkipUnloadOnFirstIdleWorkflowPersistenceService(WorkflowPersistenceService inner)
|
||||
{
|
||||
if (inner == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("inner");
|
||||
}
|
||||
|
||||
this.inner = inner;
|
||||
}
|
||||
|
||||
protected internal override Activity LoadCompletedContextActivity(Guid scopeId, Activity outerActivity)
|
||||
{
|
||||
return this.inner.LoadCompletedContextActivity(scopeId, outerActivity);
|
||||
}
|
||||
|
||||
protected internal override Activity LoadWorkflowInstanceState(Guid instanceId)
|
||||
{
|
||||
return this.inner.LoadWorkflowInstanceState(instanceId);
|
||||
}
|
||||
|
||||
protected internal override void SaveCompletedContextActivity(Activity activity)
|
||||
{
|
||||
this.inner.SaveCompletedContextActivity(activity);
|
||||
}
|
||||
|
||||
protected internal override void SaveWorkflowInstanceState(Activity rootActivity, bool unlock)
|
||||
{
|
||||
this.inner.SaveWorkflowInstanceState(rootActivity, unlock);
|
||||
}
|
||||
|
||||
protected internal override void Start()
|
||||
{
|
||||
this.inner.SetRuntime(this.Runtime);
|
||||
this.inner.Start();
|
||||
}
|
||||
|
||||
protected internal override void Stop()
|
||||
{
|
||||
this.inner.Stop();
|
||||
this.inner.SetRuntime(null);
|
||||
}
|
||||
|
||||
protected internal override bool UnloadOnIdle(Activity activity)
|
||||
{
|
||||
if (WorkflowDispatchContext.Current != null && WorkflowDispatchContext.Current.IsWorkflowStarting)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.inner.UnloadOnIdle(activity);
|
||||
}
|
||||
}
|
||||
|
||||
protected internal override void UnlockWorkflowInstanceState(Activity rootActivity)
|
||||
{
|
||||
this.inner.UnlockWorkflowInstanceState(rootActivity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user