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

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

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

    [DataContract]
    class FaultCallbackWrapper : CallbackWrapper
    { 
        static Type faultCallbackType = typeof(FaultCallback);
        static Type[] faultCallbackParameters = new Type[] { typeof(NativeActivityFaultContext), typeof(Exception), typeof(ActivityInstance) }; 
 
        public FaultCallbackWrapper(FaultCallback callback, ActivityInstance owningInstance)
            : base(callback, owningInstance) 
        {
        }

        public void Invoke(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom) 
        {
            EnsureCallback(faultCallbackType, faultCallbackParameters); 
            FaultCallback faultCallback = (FaultCallback)this.Callback; 
            faultCallback(faultContext, propagatedException, propagatedFrom);
        } 

        public WorkItem CreateWorkItem(Exception propagatedException, ActivityInstance propagatedFrom, ActivityInstanceReference originalExceptionSource)
        {
            return new FaultWorkItem(this, propagatedException, propagatedFrom, originalExceptionSource); 
        }
 
        [DataContract] 
        class FaultWorkItem : ActivityExecutionWorkItem
        { 
            [DataMember]
            FaultCallbackWrapper callbackWrapper;
            [DataMember]
            Exception propagatedException; 
            [DataMember]
            ActivityInstance propagatedFrom; 
            [DataMember] 
            ActivityInstanceReference originalExceptionSource;
 
            public FaultWorkItem(FaultCallbackWrapper callbackWrapper, Exception propagatedException, ActivityInstance propagatedFrom, ActivityInstanceReference originalExceptionSource)
                : base(callbackWrapper.ActivityInstance)
            {
                this.callbackWrapper = callbackWrapper; 
                this.propagatedException = propagatedException;
                this.propagatedFrom = propagatedFrom; 
                this.originalExceptionSource = originalExceptionSource; 
            }
 
            public override ActivityInstance OriginalExceptionSource
            {
                get
                { 
                    return this.originalExceptionSource.ActivityInstance;
                } 
            } 

            public override void TraceCompleted() 
            {
                if (TD.CompleteFaultWorkItemIsEnabled())
                {
                    TD.CompleteFaultWorkItem(this.ActivityInstance.Activity.GetType().ToString(), this.ActivityInstance.Activity.DisplayName, this.ActivityInstance.Id, this.originalExceptionSource.ActivityInstance.Activity.GetType().ToString(), this.originalExceptionSource.ActivityInstance.Activity.DisplayName, this.originalExceptionSource.ActivityInstance.Id, this.propagatedException); 
                }
            } 
 
            public override void TraceScheduled()
            { 
                if (TD.ScheduleFaultWorkItemIsEnabled())
                {
                    TD.ScheduleFaultWorkItem(this.ActivityInstance.Activity.GetType().ToString(), this.ActivityInstance.Activity.DisplayName, this.ActivityInstance.Id, this.originalExceptionSource.ActivityInstance.Activity.GetType().ToString(), this.originalExceptionSource.ActivityInstance.Activity.DisplayName, this.originalExceptionSource.ActivityInstance.Id, this.propagatedException);
                } 
            }
 
            public override void TraceStarting() 
            {
                if (TD.StartFaultWorkItemIsEnabled()) 
                {
                    TD.StartFaultWorkItem(this.ActivityInstance.Activity.GetType().ToString(), this.ActivityInstance.Activity.DisplayName, this.ActivityInstance.Id, this.originalExceptionSource.ActivityInstance.Activity.GetType().ToString(), this.originalExceptionSource.ActivityInstance.Activity.DisplayName, this.originalExceptionSource.ActivityInstance.Id, this.propagatedException);
                }
            } 

            public override bool Execute(ActivityExecutor executor, BookmarkManager bookmarkManager) 
            { 
                NativeActivityFaultContext faultContext = null;
 
                try
                {
                    faultContext = new NativeActivityFaultContext(this.ActivityInstance, executor, bookmarkManager, this.propagatedException, this.originalExceptionSource);
                    this.callbackWrapper.Invoke(faultContext, this.propagatedException, this.propagatedFrom); 

                    if (!faultContext.IsFaultHandled) 
                    { 
                        SetExceptionToPropagateWithoutAbort(this.propagatedException);
                    } 
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e)) 
                    {
                        throw; 
                    } 

                    this.ExceptionToPropagate = e; 
                }
                finally
                {
                    if (faultContext != null) 
                    {
                        faultContext.Dispose(); 
                    } 
                }
 
                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