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

                            //---------------------------------------------------------------- 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//---------------------------------------------------------------

namespace System.ServiceModel.Activities 
{
    using System.Activities; 
    using System.Collections.Generic; 
    using System.Collections.ObjectModel;
    using System.ComponentModel; 
    using System.Runtime.Collections;

    // The correlation scope has to derive from NativeActivity
    // so that we can access execution properties from AEC. 
    //
    public class CorrelationScope : NativeActivity 
    { 
        Variable declaredHandle; //
 
        public CorrelationScope()
            : base()
        {
            this.declaredHandle = new Variable(); 
        }
 
        // Explicit correlation OM 
        public InArgument CorrelatesWith
        { 
            get;
            set;
        }
 
        public Activity Body
        { 
            get; 
            set;
        } 

        protected override void CacheMetadata(NativeActivityMetadata metadata)
        {
            metadata.AddChild(this.Body); 
            metadata.SetImplementationVariablesCollection(
                new Collection 
                { 
                    this.declaredHandle
                }); 

            RuntimeArgument correlatesWithArgument = new RuntimeArgument("CorrelatesWith", typeof(CorrelationHandle), ArgumentDirection.In);
            metadata.Bind(this.CorrelatesWith, correlatesWithArgument);
            metadata.SetArgumentsCollection(new Collection { correlatesWithArgument }); 
        }
 
        protected override void Execute(NativeActivityContext context) 
        {
            if (this.Body != null) 
            {
                CorrelationHandle ambientHandle = null;
                if (this.CorrelatesWith != null && this.CorrelatesWith.Expression != null)
                { 
                    ambientHandle = this.CorrelatesWith.Get(context);
                } 
 
                if (ambientHandle == null)
                { 
                    ambientHandle = this.declaredHandle.Get(context);
                }

                context.Properties.Add(CorrelationHandle.StaticExecutionPropertyName, ambientHandle); 

                context.ScheduleActivity(this.Body); 
            } 
        }
 
        [EditorBrowsable(EditorBrowsableState.Never)]
        public bool ShouldSerializeCorrelatesWith()
        {
            return this.CorrelatesWith != null && this.CorrelatesWith.Expression != null; 
        }
    } 
} 

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