WorkflowControlEndpoint.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.ServiceModel.Activities / System / ServiceModel / Activities / WorkflowControlEndpoint.cs / 1305376 / WorkflowControlEndpoint.cs

                            //---------------------------------------------------------------- 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//---------------------------------------------------------------
namespace System.ServiceModel.Activities
{ 
    using System.Diagnostics;
    using System.Globalization; 
    using System.ServiceModel; 
    using System.ServiceModel.Activities.Description;
    using System.ServiceModel.Channels; 
    using System.ServiceModel.Description;
    using System.Runtime;

    [Fx.Tag.XamlVisible(false)] 
    public class WorkflowControlEndpoint : ServiceEndpoint
    { 
        static Uri defaultBaseUri; 
        static ContractDescription workflowControlServiceContract;
        static object workflowContractDescriptionLock = new object(); 

        public WorkflowControlEndpoint()
            : this(WorkflowControlEndpoint.GetDefaultBinding(),
            new EndpointAddress(new Uri(WorkflowControlEndpoint.DefaultBaseUri, new Uri(Guid.NewGuid().ToString(), UriKind.Relative)))) 
        {
        } 
 
        public WorkflowControlEndpoint(Binding binding, EndpointAddress address)
            : base(WorkflowControlEndpoint.WorkflowControlServiceContract, binding, address) 
        {
            this.IsSystemEndpoint = true;
        }
 
        internal static ContractDescription WorkflowControlServiceContract
        { 
            get 
            {
                if (workflowControlServiceContract == null) 
                {
                    lock (workflowContractDescriptionLock)
                    {
                        if (workflowControlServiceContract == null) 
                        {
                            ContractDescription tempControlServiceContract = ContractDescription.GetContract( 
                                typeof(IWorkflowInstanceManagement)); 
                            tempControlServiceContract.Behaviors.Add(new ServiceMetadataContractBehavior(true));
                            ApplyOperationBehaviors(tempControlServiceContract); 
                            workflowControlServiceContract = tempControlServiceContract;
                        }
                    }
                } 
                return workflowControlServiceContract;
            } 
        } 

        static Uri DefaultBaseUri 
        {
            get
            {
                if (defaultBaseUri == null) 
                {
                    defaultBaseUri = new Uri(string.Format(CultureInfo.InvariantCulture, "net.pipe://localhost/workflowControlServiceEndpoint/{0}/{1}", 
                        Process.GetCurrentProcess().Id, 
                        AppDomain.CurrentDomain.Id));
                } 
                return defaultBaseUri;
            }
        }
 
        static Binding GetDefaultBinding()
        { 
            return new NetNamedPipeBinding(NetNamedPipeSecurityMode.None) { TransactionFlow = true }; 
        }
 
        static void ApplyOperationBehaviors(ContractDescription contractDescription)
        {
            foreach (OperationDescription operationDescription in contractDescription.Operations)
            { 
                //Except "Abandon" all the operations in this contract are Async.
                //All Transacted* operation are Transacted & Async. 
                switch (operationDescription.Name) 
                {
                    case XD2.WorkflowInstanceManagementService.Abandon: 
                    case XD2.WorkflowInstanceManagementService.Cancel:
                    case XD2.WorkflowInstanceManagementService.Run:
                    case XD2.WorkflowInstanceManagementService.Suspend:
                    case XD2.WorkflowInstanceManagementService.Terminate: 
                    case XD2.WorkflowInstanceManagementService.Unsuspend:
                        EnsureDispatch(operationDescription); 
                        break; 
                    case XD2.WorkflowInstanceManagementService.TransactedCancel:
                    case XD2.WorkflowInstanceManagementService.TransactedRun: 
                    case XD2.WorkflowInstanceManagementService.TransactedSuspend:
                    case XD2.WorkflowInstanceManagementService.TransactedTerminate:
                    case XD2.WorkflowInstanceManagementService.TransactedUnsuspend:
                        EnsureDispatch(operationDescription); 
                        EnsureTransactedInvoke(operationDescription);
                        break; 
                } 
            }
        } 

        static void EnsureDispatch(OperationDescription operationDescription)
        {
            operationDescription.Behaviors.Add(new ControlOperationBehavior(false)); 
        }
 
        static void EnsureTransactedInvoke(OperationDescription operationDescription) 
        {
            OperationBehaviorAttribute operationAttribute = operationDescription.Behaviors.Find(); 
            operationAttribute.TransactionScopeRequired = true;
        }
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK