NativeActivity.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 / NativeActivity.cs / 1305376 / NativeActivity.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 NativeActivity : Activity
    { 
        protected NativeActivity()
            : base() 
        { 
        }
 
        [IgnoreDataMember]
        [Fx.Tag.KnownXamlExternal]
        protected sealed override Func Implementation
        { 
            get
            { 
                return null; 
            }
            set 
            {
                if (value != null)
                {
                    throw FxTrace.Exception.AsError(new NotSupportedException()); 
                }
            } 
        } 

        protected virtual bool CanInduceIdle 
        {
            get
            {
                return false; 
            }
        } 
 
        internal override bool InternalCanInduceIdle
        { 
            get
            {
                return this.CanInduceIdle;
            } 
        }
 
        protected abstract void Execute(NativeActivityContext context); 

        protected virtual void Abort(NativeActivityAbortContext context) 
        {
        }

        protected virtual void Cancel(NativeActivityContext context) 
        {
            if (!context.IsCancellationRequested) 
            { 
                throw FxTrace.Exception.AsError(new InvalidOperationException(SR.DefaultCancelationRequiresCancelHasBeenRequested));
            } 
            context.Cancel();
        }

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

        protected sealed override void CacheMetadata(ActivityMetadata metadata)
        {
            throw FxTrace.Exception.AsError(new InvalidOperationException(SR.WrongCacheMetadataForNativeActivity)); 
        }
 
        protected virtual void CacheMetadata(NativeActivityMetadata metadata) 
        {
            ReflectedInformation information = new ReflectedInformation(this); 

            // We bypass the metadata structure to avoid the checks for null entries
            SetArgumentsCollection(information.GetArguments(), metadata.CreateEmptyBindings);
            SetChildrenCollection(information.GetChildren()); 
            SetDelegatesCollection(information.GetDelegates());
            SetVariablesCollection(information.GetVariables()); 
        } 

        internal override void InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) 
        {
            NativeActivityContext context = executor.NativeActivityContextPool.Acquire();
            try
            { 
                context.Initialize(instance, executor, bookmarkManager);
                Execute(context); 
            } 
            finally
            { 
                context.Dispose();
                executor.NativeActivityContextPool.Release(context);
            }
        } 

        internal override void InternalAbort(ActivityInstance instance, ActivityExecutor executor, Exception terminationReason) 
        { 
            NativeActivityAbortContext context = new NativeActivityAbortContext(instance, executor, terminationReason);
            try 
            {
                Abort(context);
            }
            finally 
            {
                context.Dispose(); 
            } 
        }
 
        internal override void InternalCancel(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
        {
            NativeActivityContext context = executor.NativeActivityContextPool.Acquire();
            try 
            {
                context.Initialize(instance, executor, bookmarkManager); 
                Cancel(context); 
            }
            finally 
            {
                context.Dispose();
                executor.NativeActivityContextPool.Release(context);
            } 
        }
    } 
 
    public abstract class NativeActivity : Activity
    { 

        protected NativeActivity()
            : base()
        { 
        }
 
        [IgnoreDataMember] 
        [Fx.Tag.KnownXamlExternal]
        protected sealed override Func Implementation 
        {
            get
            {
                return null; 
            }
            set 
            { 
                if (value != null)
                { 
                    throw FxTrace.Exception.AsError(new NotSupportedException());
                }
            }
        } 

        protected virtual bool CanInduceIdle 
        { 
            get
            { 
                return false;
            }
        }
 
        internal override bool InternalCanInduceIdle
        { 
            get 
            {
                return this.CanInduceIdle; 
            }
        }

        protected abstract void Execute(NativeActivityContext context); 

        protected virtual void Abort(NativeActivityAbortContext context) 
        { 
        }
 
        protected virtual void Cancel(NativeActivityContext context)
        {
            if (!context.IsCancellationRequested)
            { 
                throw FxTrace.Exception.AsError(new InvalidOperationException(SR.DefaultCancelationRequiresCancelHasBeenRequested));
            } 
            context.Cancel(); 
        }
 
        sealed internal override void OnInternalCacheMetadataExceptResult(bool createEmptyBindings)
        {
            NativeActivityMetadata metadata = new NativeActivityMetadata(this, GetParentEnvironment(), createEmptyBindings);
            CacheMetadata(metadata); 
            metadata.Dispose();
        } 
 
        protected sealed override void CacheMetadata(ActivityMetadata metadata)
        { 
            throw FxTrace.Exception.AsError(new InvalidOperationException(SR.WrongCacheMetadataForNativeActivity));
        }

        protected virtual void CacheMetadata(NativeActivityMetadata metadata) 
        {
            ReflectedInformation information = new ReflectedInformation(this); 
 
            // We bypass the metadata structure to avoid the checks for null entries
            SetArgumentsCollection(information.GetArguments(), metadata.CreateEmptyBindings); 
            SetChildrenCollection(information.GetChildren());
            SetDelegatesCollection(information.GetDelegates());
            SetVariablesCollection(information.GetVariables());
        } 

        internal override void InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) 
        { 
            NativeActivityContext context = executor.NativeActivityContextPool.Acquire();
            try 
            {
                context.Initialize(instance, executor, bookmarkManager);
                Execute(context);
            } 
            finally
            { 
                context.Dispose(); 
                executor.NativeActivityContextPool.Release(context);
            } 
        }

        internal override void InternalAbort(ActivityInstance instance, ActivityExecutor executor, Exception terminationReason)
        { 
            NativeActivityAbortContext context = new NativeActivityAbortContext(instance, executor, terminationReason);
            try 
            { 
                Abort(context);
            } 
            finally
            {
                context.Dispose();
            } 
        }
 
        internal override void InternalCancel(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) 
        {
            NativeActivityContext context = executor.NativeActivityContextPool.Acquire(); 
            try
            {
                context.Initialize(instance, executor, bookmarkManager);
                Cancel(context); 
            }
            finally 
            { 
                context.Dispose();
                executor.NativeActivityContextPool.Release(context); 
            }
        }
    }
} 

 

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