DurableOperationContext.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 / Dispatcher / DurableOperationContext.cs / 1305376 / DurableOperationContext.cs

                            //------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------
namespace System.ServiceModel.Dispatcher
{ 
    using System;
    using System.ServiceModel.Description; 
 
    public static class DurableOperationContext
    { 
        public static Guid InstanceId
        {
            get
            { 
                ServiceDurableInstance durableInstance = GetInstanceContextExtension();
 
                return durableInstance.InstanceId; 
            }
        } 

        public static void AbortInstance()
        {
            ServiceDurableInstance durableInstance = GetInstanceContextExtension(); 

            durableInstance.AbortInstance(); 
        } 

        public static void CompleteInstance() 
        {
            ServiceDurableInstance durableInstance = GetInstanceContextExtension();

            durableInstance.MarkForCompletion(); 
        }
 
        internal static void BeginOperation() 
        {
            OperationContext operationContext = OperationContext.Current; 

            if (operationContext != null)
            {
                operationContext.Extensions.Add(new DurableOperationContext.IsInOperation()); 
            }
        } 
 
        internal static void EndOperation()
        { 
            OperationContext operationContext = OperationContext.Current;

            if (operationContext != null)
            { 
                DurableOperationContext.IsInOperation isInOperation = operationContext.Extensions.Find();
 
                if (isInOperation != null) 
                {
                    operationContext.Extensions.Remove(isInOperation); 
                }
            }
        }
 
        static ServiceDurableInstance GetInstanceContextExtension()
        { 
            OperationContext operationContext = OperationContext.Current; 

            if (operationContext == null) 
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                    new InvalidOperationException(
                    SR2.GetString( 
                    SR2.OnlyCallableFromServiceOperation,
                    typeof(DurableOperationContext).Name))); 
            } 

            IsInOperation isInOperation = operationContext.Extensions.Find(); 

            if (isInOperation == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( 
                    new InvalidOperationException(
                    SR2.GetString( 
                    SR2.OnlyCallableWhileInOperation, 
                    typeof(DurableOperationContext).Name)));
            } 

            InstanceContext currentInstanceContext = operationContext.InstanceContext;

            if (currentInstanceContext == null) 
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( 
                    new InvalidOperationException( 
                    SR2.GetString(
                    SR2.OnlyCallableFromServiceOperation, 
                    typeof(DurableOperationContext).Name)));
            }

            ServiceDurableInstance durableInstance = 
                currentInstanceContext.Extensions.Find();
 
            if (durableInstance == null) 
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( 
                    new InvalidOperationException(
                    SR2.GetString(
                    SR2.OnlyCallableFromDurableService,
                    typeof(DurableOperationContext).Name, 
                    typeof(DurableServiceAttribute).Name)));
            } 
 
            return durableInstance;
        } 

        class IsInOperation : IExtension
        {
            public void Attach(OperationContext owner) 
            {
            } 
 
            public void Detach(OperationContext owner)
            { 
            }
        }
    }
} 

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