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

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

namespace System.Activities.Runtime 
{
    using System; 
    using System.Activities.Hosting; 
    using System.Runtime;
    using System.Runtime.Serialization; 

    [DataContract]
    class BookmarkWorkItem : ActivityExecutionWorkItem
    { 
        [DataMember]
        BookmarkCallbackWrapper callbackWrapper; 
        [DataMember] 
        Bookmark bookmark;
        [DataMember(EmitDefaultValue = false)] 
        object state;

        public BookmarkWorkItem(ActivityExecutor executor, bool isExternal, BookmarkCallbackWrapper callbackWrapper, Bookmark bookmark, object value)
            : this(callbackWrapper, bookmark, value) 
        {
            if (isExternal) 
            { 
                executor.EnterNoPersist();
                this.ExitNoPersistRequired = true; 
            }
        }

        // This ctor is only used by subclasses which make their own determination about no persist or not 
        protected BookmarkWorkItem(BookmarkCallbackWrapper callbackWrapper, Bookmark bookmark, object value)
            : base(callbackWrapper.ActivityInstance) 
        { 
            this.callbackWrapper = callbackWrapper;
            this.bookmark = bookmark; 
            this.state = value;
        }

        public override void TraceCompleted() 
        {
            if (TD.CompleteBookmarkWorkItemIsEnabled()) 
            { 
                TD.CompleteBookmarkWorkItem(this.ActivityInstance.Activity.GetType().ToString(), this.ActivityInstance.Activity.DisplayName, this.ActivityInstance.Id, ActivityUtilities.GetTraceString(this.bookmark), ActivityUtilities.GetTraceString(this.bookmark.Scope));
            } 
        }

        public override void TraceScheduled()
        { 
            if (TD.ScheduleBookmarkWorkItemIsEnabled())
            { 
                TD.ScheduleBookmarkWorkItem(this.ActivityInstance.Activity.GetType().ToString(), this.ActivityInstance.Activity.DisplayName, this.ActivityInstance.Id, ActivityUtilities.GetTraceString(this.bookmark), ActivityUtilities.GetTraceString(this.bookmark.Scope)); 
            }
        } 

        public override void TraceStarting()
        {
            if (TD.StartBookmarkWorkItemIsEnabled()) 
            {
                TD.StartBookmarkWorkItem(this.ActivityInstance.Activity.GetType().ToString(), this.ActivityInstance.Activity.DisplayName, this.ActivityInstance.Id, ActivityUtilities.GetTraceString(this.bookmark), ActivityUtilities.GetTraceString(this.bookmark.Scope)); 
            } 
        }
 
        public override bool Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
        {
            NativeActivityContext nativeContext = executor.NativeActivityContextPool.Acquire();
 
            try
            { 
                nativeContext.Initialize(this.ActivityInstance, executor, bookmarkManager); 
                this.callbackWrapper.Invoke(nativeContext, this.bookmark, this.state);
            } 
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                { 
                    throw;
                } 
 
                this.ExceptionToPropagate = e;
            } 
            finally
            {
                nativeContext.Dispose();
                executor.NativeActivityContextPool.Release(nativeContext); 
            }
 
            return true; 
        }
    } 
}

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