DurableOperationAttribute.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 / NetFx35 / System.WorkflowServices / System / ServiceModel / Description / DurableOperationAttribute.cs / 1305376 / DurableOperationAttribute.cs

                            //------------------------------------------------------------ 
// 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)]
    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; 
        }
    }
}

// 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