private void OnFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
        {
            PropertyDescriptor dropboxSessionProperty = faultContext.DataContext.GetProperties()[DropboxSessionPropertyName];
            IDropboxSession    dropboxSession         = dropboxSessionProperty?.GetValue(faultContext.DataContext) as IDropboxSession;

            dropboxSession?.Dispose();
        }
Exemplo n.º 2
0
        private void OnFaultedCallback(NativeActivityFaultContext faultContext, Exception exception, ActivityInstance source)
        {
            faultContext.CancelChildren();
            DatabaseConnection conn = DBConnection.Get(faultContext);

            if (conn != null)
            {
                try
                {
                    if (UseTransaction)
                    {
                        conn.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    conn.Dispose();
                }
            }

            HandleException(exception, ContinueOnError.Get(faultContext));
            faultContext.HandleFault();
        }
 private void onWorkItemFaulted(NativeActivityFaultContext faultcontext,
                                Exception propagatedexception, ActivityInstance propagatedfrom)
 {
     faultcontext.HandleFault();
     faultcontext.CancelChildren();
     _childFault.Set(faultcontext, propagatedexception);
 }
        public void Invoke(NativeActivityFaultContext faultContext, Exception propagatedException, System.Activities.ActivityInstance propagatedFrom)
        {
            base.EnsureCallback(faultCallbackType, faultCallbackParameters);
            FaultCallback callback = (FaultCallback)base.Callback;

            callback(faultContext, propagatedException, propagatedFrom);
        }
            public override bool Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
            {
                NativeActivityFaultContext faultContext = null;

                try
                {
                    faultContext = new NativeActivityFaultContext(base.ActivityInstance, executor, bookmarkManager, this.propagatedException, this.originalExceptionSource);
                    this.callbackWrapper.Invoke(faultContext, this.propagatedException, this.propagatedFrom);
                    if (!faultContext.IsFaultHandled)
                    {
                        base.SetExceptionToPropagateWithoutAbort(this.propagatedException);
                    }
                }
                catch (Exception exception)
                {
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }
                    base.ExceptionToPropagate = exception;
                }
                finally
                {
                    if (faultContext != null)
                    {
                        faultContext.Dispose();
                    }
                }
                return(true);
            }
Exemplo n.º 6
0
 protected void BodyFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
 {
     this.DisposeMonitor(faultContext);
     this.HandleException(propagatedException, this.ContinueOnError.Get(faultContext));
     faultContext.CancelChildren();
     faultContext.HandleFault();
 }
Exemplo n.º 7
0
        private void OnExceptionFromHandler(NativeActivityFaultContext context, Exception propagatedException, ActivityInstance propagatedFrom)
        {
            var compensationExtension = context.GetExtension <CompensationExtension>();

            Fx.Assert(compensationExtension != null, "CompensationExtension must be valid");

            var compensationToken = compensationExtension.Get(this.compensationId.Get(context));

            Fx.Assert(compensationToken != null, "CompensationTokenData must be valid");

            InvalidOperationException exception = null;

            switch (compensationToken.CompensationState)
            {
            case CompensationState.Confirming:
                exception = new InvalidOperationException(SR.ConfirmationHandlerFatalException(compensationToken.DisplayName), propagatedException);
                break;

            case CompensationState.Compensating:
                exception = new InvalidOperationException(SR.CompensationHandlerFatalException(compensationToken.DisplayName), propagatedException);
                break;

            case CompensationState.Canceling:
                exception = new InvalidOperationException(SR.CancellationHandlerFatalException(compensationToken.DisplayName), propagatedException);
                break;

            default:
                Fx.Assert(false, "CompensationState is in unexpected state!");
                break;
            }

            context.Abort(exception);
        }
        private void UnregisterReceiveNotification(ActivityContext context)
        {
            var      subscriptionHandle = this.SubscriptionHandle.Get(context);
            Bookmark bookmark           = this.receiveCompleteBookmark.Get(context);

            if (bookmark != null)
            {
                if (subscriptionHandle != null)
                {
                    context.GetExtension <Hosting.FolderWatcherExtension>()
                    .UnregisterReceiveNotification(bookmark, subscriptionHandle.Id);
                }
            }
            if (context is NativeActivityContext)
            {
                NativeActivityContext ctx = context as NativeActivityContext;
                if (bookmark != null)
                {
                    ctx.RemoveBookmark(bookmark);
                }
                this.noPersistHandle.Get(ctx).Exit(ctx);
            }
            else if (context is NativeActivityFaultContext)
            {
                NativeActivityFaultContext ctx = context as NativeActivityFaultContext;
                if (bookmark != null)
                {
                    ctx.RemoveBookmark(bookmark);
                }
                this.noPersistHandle.Get(ctx).Exit(ctx);
            }
        }
Exemplo n.º 9
0
        public void Invoke(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
        {
            EnsureCallback(faultCallbackType, faultCallbackParameters);
            FaultCallback faultCallback = (FaultCallback)this.Callback;

            faultCallback(faultContext, propagatedException, propagatedFrom);
        }
Exemplo n.º 10
0
 private void OnFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
 {
     if (sshClient.IsConnected)
     {
         sshClient.Disconnect();
     }
     sshClient.Dispose();
 }
Exemplo n.º 11
0
 private void OnFaulted(NativeActivityFaultContext context, Exception exception, ActivityInstance source)
 {
     if (rEngine != null)
     {
         this.RDispose();
     }
     context.CancelChildren();
 }
Exemplo n.º 12
0
 private void OnBodyFaulted(NativeActivityFaultContext faultcontext, Exception propagatedexception,
                            ActivityInstance propagatedfrom)
 {
     faultcontext.GetExtension <CriticalSectionQueueExtension>()
     .Exit(_resumeBookmark.Get(faultcontext), QueueName.Get(faultcontext));
     _bodyError.Set(faultcontext, propagatedexception);
     faultcontext.RemoveAllBookmarks();
 }
Exemplo n.º 13
0
        private void OnFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
        {
            PropertyDescriptor ftpSessionProperty = faultContext.DataContext.GetProperties()[WithFtpSession.FtpSessionPropertyName];
            IFtpSession        ftpSession         = ftpSessionProperty?.GetValue(faultContext.DataContext) as IFtpSession;

            ftpSession?.Close();
            ftpSession?.Dispose();
        }
Exemplo n.º 14
0
 private void OnExceptionFromCatchOrFinally(NativeActivityFaultContext context, Exception propagatedException, System.Activities.ActivityInstance propagatedFrom)
 {
     if (TD.TryCatchExceptionFromCatchOrFinallyIsEnabled())
     {
         TD.TryCatchExceptionFromCatchOrFinally(base.DisplayName);
     }
     this.state.Get(context).SuppressCancel = false;
 }
Exemplo n.º 15
0
        protected override void OnFaulted(NativeActivityFaultContext faultContext,
                                          Exception propagatedException, ActivityInstance propagatedFrom)
        {
            Console.WriteLine("OnFaulted: {0}", propagatedException.Message);

            faultContext.HandleFault();
            faultContext.CancelChild(propagatedFrom);
            Console.WriteLine("OnFaulted: Exception was handled");
        }
Exemplo n.º 16
0
        void OnFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
        {
            IDSFDataObject dataObject = faultContext.GetExtension <IDSFDataObject>();

            if (dataObject != null && dataObject.IsDebugMode())
            {
                DispatchDebugState(faultContext, StateType.After);
            }
            OnExecutedCompleted(faultContext, true, false);
        }
Exemplo n.º 17
0
        void OnFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
        {
            IDSFDataObject dataObject = faultContext.GetExtension <IDSFDataObject>();

            dataObject.Environment.AddError(propagatedException.Message);
            if (dataObject.IsDebugMode())
            {
                DispatchDebugState(dataObject, StateType.After, 0);
            }
            OnExecutedCompleted(faultContext, true, false);
        }
Exemplo n.º 18
0
        void OnExceptionFromCatchOrFinally(NativeActivityFaultContext context, Exception propagatedException, ActivityInstance propagatedFrom)
        {
            if (TD.TryCatchExceptionFromCatchOrFinallyIsEnabled())
            {
                TD.TryCatchExceptionFromCatchOrFinally(this.DisplayName);
            }

            // We allow cancel through if there is an exception from the catch or finally
            TryCatchState state = this.state.Get(context);

            state.SuppressCancel = false;
        }
Exemplo n.º 19
0
        /// <summary>
        /// Invoked when a <see cref="RetryCatch"/> faultssss.
        /// </summary>
        /// <param name="faultContext"></param>
        /// <param name="propagatedException"></param>
        /// <param name="propagatedFrom"></param>
        void OnCatchFault(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
        {
            var state = this.state.Get(faultContext);

            // append new exception to exception list
            if (propagatedException != null)
            {
                state.Attempts.Add(propagatedException);
            }

            // do not handle, allow to fail
            BeforeExit(faultContext);
        }
Exemplo n.º 20
0
        private void OnTryFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
        {
            // TODO: delete
            // Write event into the log
            // This is necessary here because the trace log won't be available later

            /*var record = new CustomTrackingRecord("OnTryFaulted", System.Diagnostics.TraceLevel.Error)
             * {
             *  Data =
             *  {
             *      { "Exception", propagatedException },
             *      { "JobGuid", JobGuid.Get(faultContext) },
             *      { "UserGuid", UserGuid.Get(faultContext) },
             *  }
             * };
             * faultContext.Track(record);
             */

            // Handle exception
            int r = retries.Get(faultContext);

            retries.Set(faultContext, ++r);

            faultContext.CancelChild(propagatedFrom);
            faultContext.HandleFault();


            // Run the finally block before doing anything else
            if (Finally != null)
            {
                faultContext.ScheduleActivity(this.Finally, OnFinallyComplete, OnFinallyFaulted);
            }
            else
            {
                OnFinallyComplete(faultContext, null);
            }

            // If retry is possible,
            if (r < MaxRetries.Get(faultContext))
            {
                // absorb error
                faultContext.HandleFault();

                faultContext.ScheduleActivity(this.Try, OnTryComplete, OnTryFaulted);
            }
            else
            {
                // fault
                throw propagatedException;
            }
        }
Exemplo n.º 21
0
 // TODO: we propagate an unhandled exception during an operation back to the task, should we handle it differently?
 private void BodyFaultCallback(NativeActivityFaultContext context, Exception propagatedException, ActivityInstance propagatedFrom)
 {
     if (!context.GetReceiveRequestSendResponseScopeExecutionProperty().TrySetTaskCompletionSourceException(propagatedException))
     {
         // this will add a WorkflowInstanceAbortedRecord with the reason
         context.Abort(propagatedException);
     }
     else
     {
         // this won't add any WorkflowInstanceAbortedRecord at all
         context.Abort();
     }
     context.HandleFault();
 }
Exemplo n.º 22
0
        /// <summary>
        /// Invoked when an error occurs in the body.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="propagatedException"></param>
        /// <param name="propagatedFrom"></param>
        void OnBodyFaulted(NativeActivityFaultContext context, Exception propagatedException, ActivityInstance propagatedFrom)
        {
            var state = this.state.Get(context);

            // discover if exception is handled, if so cancel children and record
            var c = FindCatch(propagatedException);

            if (c != null)
            {
                context.CancelChild(propagatedFrom);
                state.CaughtException = propagatedException;
                context.HandleFault();
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// Respond to the fault callback, used for all scheduled activities.
        /// </summary>
        /// <param name="context">The activity context.</param>
        /// <param name="exception">An exception which was thrown by the activity.</param>
        /// <param name="instance">The current instance of the activity.</param>
        private void OnOperationFault(NativeActivityFaultContext context, Exception exception, ActivityInstance instance)
        {
            // Mark the fault handled, or else this activity will throw and will not contine after this method returns.
            context.HandleFault();

            // TODO: Make this logging dependent on the operation configuration
            LogBuildError(context, string.Format("AzureAsyncOperation Fault {0} during execution of {1}\r\n{2}", exception.GetType().Name, instance.Activity.GetType().Name, exception.Message));
            LogBuildMessage(context, exception.StackTrace, BuildMessageImportance.High);

            // Cancel the running activity
            context.CancelChild(instance);

            // Notify that an exception has been caught
            // The CompletionCallback will be called because we handled the exception.
            // This makes a better design choice to do any scheduling or further logic there.
            this.AzureActivityExceptionCaught.Set(context, true);
        }
Exemplo n.º 24
0
        private void BodyFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
        {
            if (ContinueOnError.Get(faultContext))
            {
                // Cancel all remaining actions for the current event.
                faultContext.CancelChildren();

                // ... but continue monitoring and triggering new events.
                faultContext.HandleFault();

                Trace.TraceError(propagatedException.ToString());
            }
            else
            {
                CleanUp(faultContext);
                throw propagatedException;
            }
        }
Exemplo n.º 25
0
        private void ActionFailed(NativeActivityFaultContext faultContext, Exception propagatedexception, ActivityInstance propagatedfrom)
        {
            Int32 currentAttemptCount = _attemptCount.Get(faultContext);
            Int32 maxAttempts         = MaxAttempts.Get(faultContext);

            Type[] exceptionType = ExceptionType.Get(faultContext);

            //Increment and track the count
            currentAttemptCount++;
            _attemptCount.Set(faultContext, currentAttemptCount);

            if (currentAttemptCount >= maxAttempts)
            {
                // There are no further attempts to make
                return;
            }

            if (ShouldRetryAction(exceptionType, propagatedexception) == false)
            {
                _log.Error("Will only retry exception of type '" + exceptionType.ToCSV() + "'. Unhandled type of '" + propagatedexception.GetType().FullName + "' was found.", propagatedexception);
                return;
            }

            faultContext.CancelChild(propagatedfrom);
            faultContext.HandleFault();

            TimeSpan retryInterval = _delayOverrideForUnitTests == null?RetryInterval.Get(faultContext) : _delayOverrideForUnitTests.Value;

            _log.Debug("Retrying in " + retryInterval.TotalSeconds + " seconds due to " + propagatedexception.GetType().FullName + ". " + currentAttemptCount + " of " + maxAttempts);

            if (retryInterval == TimeSpan.Zero)
            {
                ExecuteAttempt(faultContext);
            }
            else
            {
                // We are going to wait before trying again
                _delayDuration.Set(faultContext, retryInterval);
                faultContext.ScheduleActivity(
                    _internalDelay,
                    DelayCompleted);
            }
        }
Exemplo n.º 26
0
        void OnExceptionFromTry(NativeActivityFaultContext context, Exception propagatedException, ActivityInstance propagatedFrom)
        {
            if (propagatedFrom.IsCancellationRequested)
            {
                if (TD.TryCatchExceptionDuringCancelationIsEnabled())
                {
                    TD.TryCatchExceptionDuringCancelation(this.DisplayName);
                }

                // The Try activity threw an exception during Cancel; abort the workflow
                context.Abort(propagatedException);
                context.HandleFault();
            }
            else
            {
                Catch catchHandler = FindCatch(propagatedException);
                if (catchHandler != null)
                {
                    if (TD.TryCatchExceptionFromTryIsEnabled())
                    {
                        TD.TryCatchExceptionFromTry(this.DisplayName, propagatedException.GetType().ToString());
                    }

                    context.CancelChild(propagatedFrom);
                    TryCatchState state = this.state.Get(context);

                    // If we are not supposed to persist exceptions, enter our noPersistScope
                    ExceptionPersistenceExtension extension = context.GetExtension <ExceptionPersistenceExtension>();
                    if ((extension != null) && !extension.PersistExceptions)
                    {
                        NoPersistProperty noPersistProperty = (NoPersistProperty)context.Properties.FindAtCurrentScope(NoPersistProperty.Name);
                        if (noPersistProperty != null)
                        {
                            // The property will be exited when the activity completes or aborts.
                            noPersistProperty.Enter();
                        }
                    }

                    state.CaughtException = context.CreateFaultContext();
                    context.HandleFault();
                }
            }
        }
        private void OnExceptionFromHandler(NativeActivityFaultContext context, Exception propagatedException, System.Activities.ActivityInstance propagatedFrom)
        {
            CompensationTokenData     data   = context.GetExtension <CompensationExtension>().Get(this.compensationId.Get(context));
            InvalidOperationException reason = null;

            switch (data.CompensationState)
            {
            case CompensationState.Confirming:
                reason = new InvalidOperationException(System.Activities.SR.ConfirmationHandlerFatalException(data.DisplayName), propagatedException);
                break;

            case CompensationState.Compensating:
                reason = new InvalidOperationException(System.Activities.SR.CompensationHandlerFatalException(data.DisplayName), propagatedException);
                break;

            case CompensationState.Canceling:
                reason = new InvalidOperationException(System.Activities.SR.CancellationHandlerFatalException(data.DisplayName), propagatedException);
                break;
            }
            context.Abort(reason);
        }
Exemplo n.º 28
0
 private void OnExceptionFromTry(NativeActivityFaultContext context, Exception propagatedException, System.Activities.ActivityInstance propagatedFrom)
 {
     if (propagatedFrom.IsCancellationRequested)
     {
         if (TD.TryCatchExceptionDuringCancelationIsEnabled())
         {
             TD.TryCatchExceptionDuringCancelation(base.DisplayName);
         }
         context.Abort(propagatedException);
         context.HandleFault();
     }
     else if (this.FindCatch(propagatedException) != null)
     {
         if (TD.TryCatchExceptionFromTryIsEnabled())
         {
             TD.TryCatchExceptionFromTry(base.DisplayName, propagatedException.GetType().ToString());
         }
         context.CancelChild(propagatedFrom);
         this.state.Get(context).CaughtException = context.CreateFaultContext();
         context.HandleFault();
     }
 }
Exemplo n.º 29
0
        private void ActionFailed(NativeActivityFaultContext faultcontext, Exception propagatedexception, ActivityInstance propagatedfrom)
        {
            Int32 currentAttemptCount = _attemptCount.Get(faultcontext);

            currentAttemptCount++;

            _attemptCount.Set(faultcontext, currentAttemptCount);

            Int32 maxAttempts = MaxAttempts.Get(faultcontext);

            if (currentAttemptCount >= maxAttempts)
            {
                // There are no further attempts to make
                return;
            }

            if (ShouldRetryAction(ExceptionType, propagatedexception) == false)
            {
                return;
            }

            faultcontext.CancelChild(propagatedfrom);
            faultcontext.HandleFault();

            TimeSpan retryInterval = RetryInterval.Get(faultcontext);

            if (retryInterval == TimeSpan.Zero)
            {
                ExecuteAttempt(faultcontext);
            }
            else
            {
                // We are going to wait before trying again
                _delayDuration.Set(faultcontext, retryInterval);

                faultcontext.ScheduleActivity(_internalDelay, DelayCompleted);
            }
        }
Exemplo n.º 30
0
            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();
                    }

                    // Tell the executor to decrement its no persist count persistence of exceptions is disabled.
                    executor.ExitNoPersistForExceptionPropagation();
                }

                return(true);
            }
 public void Invoke(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
 {
     EnsureCallback(faultCallbackType, faultCallbackParameters);
     FaultCallback faultCallback = (FaultCallback)this.Callback;
     faultCallback(faultContext, propagatedException, propagatedFrom);
 }
        void OnExceptionFromHandler(NativeActivityFaultContext context, Exception propagatedException, ActivityInstance propagatedFrom)
        {
            CompensationExtension compensationExtension = context.GetExtension<CompensationExtension>();
            Fx.Assert(compensationExtension != null, "CompensationExtension must be valid");

            CompensationTokenData compensationToken = compensationExtension.Get(this.compensationId.Get(context));
            Fx.Assert(compensationToken != null, "CompensationTokenData must be valid");

            InvalidOperationException exception = null;

            switch (compensationToken.CompensationState)
            {
                case CompensationState.Confirming:
                    exception = new InvalidOperationException(SR.ConfirmationHandlerFatalException(compensationToken.DisplayName), propagatedException);
                    break;
                case CompensationState.Compensating:
                    exception = new InvalidOperationException(SR.CompensationHandlerFatalException(compensationToken.DisplayName), propagatedException);
                    break;
                case CompensationState.Canceling:
                    exception = new InvalidOperationException(SR.CancellationHandlerFatalException(compensationToken.DisplayName), propagatedException);
                    break;
                default:
                    Fx.Assert(false, "CompensationState is in unexpected state!");
                    break;
            }

            context.Abort(exception);
        }
            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();
                    }

                    // Tell the executor to decrement its no persist count persistence of exceptions is disabled.
                    executor.ExitNoPersistForExceptionPropagation();
                }

                return true;
            }