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

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

namespace System.Activities 
{
    using System.Activities.Runtime; 
    using System.Activities.Validation; 
    using System.Collections.Generic;
    using System.Runtime; 
    using System.Runtime.Serialization;

    public abstract class CodeActivity : Activity
    { 
        protected CodeActivity()
        { 
        } 

        [IgnoreDataMember] 
        [Fx.Tag.KnownXamlExternal]
        protected sealed override Func Implementation
        {
            get 
            {
                return null; 
            } 
            set
            { 
                if (value != null)
                {
                    throw FxTrace.Exception.AsError(new NotSupportedException());
                } 
            }
        } 
 
        protected abstract void Execute(CodeActivityContext context);
 
        sealed internal override void InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
        {
            CodeActivityContext context = executor.CodeActivityContextPool.Acquire();
            try 
            {
                context.Initialize(instance, executor); 
                Execute(context); 
            }
            finally 
            {
                context.Dispose();
                executor.CodeActivityContextPool.Release(context);
            } 
        }
 
        sealed internal override void InternalCancel(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) 
        {
            Fx.Assert("Cancel should never be called on CodeActivity since it's synchronous"); 
        }

        sealed internal override void InternalAbort(ActivityInstance instance, ActivityExecutor executor, Exception terminationReason)
        { 
            // no-op, this is only called if an exception is thrown out of execute
        } 
 
        sealed internal override void OnInternalCacheMetadata(bool createEmptyBindings)
        { 
            CodeActivityMetadata metadata = new CodeActivityMetadata(this, this.GetParentEnvironment(), createEmptyBindings);
            CacheMetadata(metadata);
            metadata.Dispose();
        } 

        protected sealed override void CacheMetadata(ActivityMetadata metadata) 
        { 
            throw FxTrace.Exception.AsError(new InvalidOperationException(SR.WrongCacheMetadataForCodeActivity));
        } 

        protected virtual void CacheMetadata(CodeActivityMetadata metadata)
        {
            // We bypass the metadata call to avoid the null checks 
            SetArgumentsCollection(ReflectedInformation.GetArguments(this), metadata.CreateEmptyBindings);
        } 
    } 

    public abstract class CodeActivity : Activity 
    {
        protected CodeActivity()
        {
        } 

        [IgnoreDataMember] 
        [Fx.Tag.KnownXamlExternal] 
        protected sealed override Func Implementation
        { 
            get
            {
                return null;
            } 
            set
            { 
                if (value != null) 
                {
                    throw FxTrace.Exception.AsError(new NotSupportedException()); 
                }
            }
        }
 
        protected abstract TResult Execute(CodeActivityContext context);
 
        sealed internal override void InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) 
        {
            CodeActivityContext context = executor.CodeActivityContextPool.Acquire(); 
            try
            {
                context.Initialize(instance, executor);
                TResult executeResult = Execute(context); 
                this.Result.Set(context, executeResult);
            } 
            finally 
            {
                context.Dispose(); 
                executor.CodeActivityContextPool.Release(context);
            }
        }
 
        sealed internal override void InternalCancel(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
        { 
            Fx.Assert("Cancel should never be called on CodeActivity since it's synchronous"); 
        }
 
        sealed internal override void InternalAbort(ActivityInstance instance, ActivityExecutor executor, Exception terminationReason)
        {
            // no-op, this is only called if an exception is thrown out of execute
        } 

        sealed internal override void OnInternalCacheMetadataExceptResult(bool createEmptyBindings) 
        { 
            CodeActivityMetadata metadata = new CodeActivityMetadata(this, this.GetParentEnvironment(), createEmptyBindings);
            CacheMetadata(metadata); 
            metadata.Dispose();
        }

        protected sealed override void CacheMetadata(ActivityMetadata metadata) 
        {
            throw FxTrace.Exception.AsError(new InvalidOperationException(SR.WrongCacheMetadataForCodeActivity)); 
        } 

        protected virtual void CacheMetadata(CodeActivityMetadata metadata) 
        {
            // We bypass the metadata call to avoid the null checks
            SetArgumentsCollection(ReflectedInformation.GetArguments(this), metadata.CreateEmptyBindings);
        } 
    }
} 

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