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

                            //------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------
namespace System.ServiceModel.Dispatcher
{ 
    using System.ServiceModel.Channels;
 
    class DurableMessageDispatchInspector : IDispatchMessageInspector 
    {
        public const string NewDurableInstanceIdPropertyName = "newDurableInstanceIdProperty"; 
        const string suppressContextOnReply = "suppressContextOnReply";
        SessionMode sessionMode;

        public DurableMessageDispatchInspector(SessionMode sessionMode) 
        {
            this.sessionMode = sessionMode; 
        } 

        public static void SuppressContextOnReply(OperationContext operationContext) 
        {
            if (operationContext == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("operationContext"); 
            }
            operationContext.OutgoingMessageProperties[suppressContextOnReply] = true; 
        } 

        public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext) 
        {
            if (instanceContext == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("instanceContext"); 
            }
 
            if (request == null) 
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("request"); 
            }

            if (sessionMode != SessionMode.NotAllowed)
            { 
                object result = null;
 
                if (request.Properties.TryGetValue(NewDurableInstanceIdPropertyName, out result)) 
                {
                    return result.ToString(); 
                }
            }
            return null;
        } 

        public void BeforeSendReply(ref Message reply, object correlationState) 
        { 
            try
            { 
                if (reply != null)
                {
                    ContextMessageProperty context = null;
 
                    if (sessionMode == SessionMode.NotAllowed || reply.Properties.ContainsKey(suppressContextOnReply))
                    { 
                        if (ContextMessageProperty.TryGet(reply, out context)) 
                        {
                            context.Context.Clear(); 
                        }
                    }
                    else
                    { 
                        string newInstanceId = correlationState as string;
 
                        if (newInstanceId != null) 
                        {
 
                            if (!ContextMessageProperty.TryGet(reply, out context))
                            {
                                context = new ContextMessageProperty();
                                context.Context[WellKnownContextProperties.InstanceId] = newInstanceId; 
                                context.AddOrReplaceInMessage(reply);
                            } 
                            else 
                            {
                                context.Context[WellKnownContextProperties.InstanceId] = newInstanceId; 
                            }
                        }
                    }
                } 
            }
            finally 
            { 
                DurableInstance durableInstance = OperationContext.Current.InstanceContext.Extensions.Find();
 
                if (durableInstance == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                        new InvalidOperationException( 
                        SR2.GetString(
                        SR2.RequiredInstanceContextExtensionNotFound, 
                        typeof(DurableInstance).Name))); 
                }
                //Decrement InstanceActivity Count 
                durableInstance.DecrementActivityCount();
            }
        }
    } 
}

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