Sequence.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.Activities / System / Activities / Statements / Sequence.cs / 1305376 / Sequence.cs

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

namespace System.Activities.Statements 
{
    using System.Activities; 
    using System.Activities.Validation; 
    using System.Collections.Generic;
    using System.Collections.ObjectModel; 
    using System.Runtime.Collections;
    using System.Windows.Markup;

    [ContentProperty("Activities")] 
    public sealed class Sequence : NativeActivity
    { 
        Collection activities; 
        Collection variables;
        Variable lastIndexHint; 
        CompletionCallback onChildComplete;

        public Sequence()
            : base() 
        {
            this.lastIndexHint = new Variable(); 
            this.onChildComplete = new CompletionCallback(InternalExecute); 
        }
 
        public Collection Variables
        {
            get
            { 
                if (this.variables == null)
                { 
                    this.variables = new ValidatingCollection 
                    {
                        // disallow null values 
                        OnAddValidationCallback = item =>
                        {
                            if (item == null)
                            { 
                                throw FxTrace.Exception.ArgumentNull("item");
                            } 
                        } 
                    };
                } 
                return this.variables;
            }
        }
 
        [DependsOn("Variables")]
        public Collection Activities 
        { 
            get
            { 
                if (this.activities == null)
                {
                    this.activities = new ValidatingCollection
                    { 
                        // disallow null values
                        OnAddValidationCallback = item => 
                        { 
                            if (item == null)
                            { 
                                throw FxTrace.Exception.ArgumentNull("item");
                            }
                        }
                    }; 
                }
                return this.activities; 
            } 
        }
 
        protected override void CacheMetadata(NativeActivityMetadata metadata)
        {
            metadata.SetChildrenCollection(this.Activities);
            metadata.SetVariablesCollection(this.Variables); 
            metadata.AddImplementationVariable(this.lastIndexHint);
        } 
 
        protected override void Execute(NativeActivityContext context)
        { 
            if (this.activities != null && this.Activities.Count > 0)
            {
                Activity nextChild = this.Activities[0];
 
                context.ScheduleActivity(nextChild, this.onChildComplete);
            } 
        } 

        void InternalExecute(NativeActivityContext context, ActivityInstance completedInstance) 
        {
            int completedInstanceIndex = this.lastIndexHint.Get(context);

            if (completedInstanceIndex >= this.Activities.Count || this.Activities[completedInstanceIndex] != completedInstance.Activity) 
            {
                completedInstanceIndex = this.Activities.IndexOf(completedInstance.Activity); 
            } 

            int nextChildIndex = completedInstanceIndex + 1; 

            if (nextChildIndex == this.Activities.Count)
            {
                return; 
            }
 
            Activity nextChild = this.Activities[nextChildIndex]; 

            context.ScheduleActivity(nextChild, this.onChildComplete); 

            this.lastIndexHint.Set(context, nextChildIndex);
        }
    } 
}

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