Пример #1
0
        private void HandleOutcome(ActionMessage message, IInteractionNode handlingNode, MessageProcessingOutcome outcome)
        {
            var result = MessageBinder.CreateResult(outcome);

            result.Completed += (s, e) => {
                TryUpdateTrigger(message, handlingNode, false);

                if (e.Error != null)
                {
                    if (!TryApplyRescue(message, handlingNode, e.Error))
                    {
                        Log.Error(e.Error);
                        throw e.Error;
                    }
                }

                OnCompleted();
            };

            result.Execute(new ResultExecutionContext(serviceLocator, message, handlingNode));
        }
Пример #2
0
        /// <summary>
        /// Executes the core logic, specific to the action type.
        /// </summary>
        /// <param name="actionMessage">The action message.</param>
        /// <param name="handlingNode">The node.</param>
        /// <param name="parameters">The parameters.</param>
        protected void DoExecute(ActionMessage actionMessage, IInteractionNode handlingNode, object[] parameters)
        {
            CurrentTask.Completed +=
                (s, e) => Invocation.Execute.OnUIThread(
                    () => {
                Interlocked.Decrement(ref runningCount);
                if (e.Error != null)
                {
                    TryUpdateTrigger(actionMessage, handlingNode, false);
                    if (!TryApplyRescue(actionMessage, handlingNode, e.Error))
                    {
                        Log.Error(e.Error);
                        throw e.Error;
                    }
                    OnCompleted();
                }
                else
                {
                    try
                    {
                        var outcome = new MessageProcessingOutcome(
                            e.Cancelled ? null : e.Result,
                            UnderlyingMethod.Info.ReturnType,
                            e.Cancelled
                            );

                        foreach (var filter in UnderlyingFilters.PostProcessors)
                        {
                            filter.Execute(actionMessage, handlingNode, outcome);
                        }

                        var result = MessageBinder.CreateResult(outcome);

                        result.Completed += (r, arg) => {
                            TryUpdateTrigger(actionMessage, handlingNode, false);

                            if (arg.Error != null)
                            {
                                if (!TryApplyRescue(actionMessage, handlingNode, arg.Error))
                                {
                                    Log.Error(arg.Error);
                                    throw arg.Error;
                                }
                            }

                            OnCompleted();
                        };

                        result.Execute(new ResultExecutionContext(serviceLocator, actionMessage, handlingNode));
                    }
                    catch (Exception ex)
                    {
                        TryUpdateTrigger(actionMessage, handlingNode, false);
                        if (!TryApplyRescue(actionMessage, handlingNode, ex))
                        {
                            Log.Error(ex);
                            throw;
                        }
                        OnCompleted();
                    }
                }
            });

            Interlocked.Increment(ref runningCount);
            CurrentTask.Start(this);
            CurrentTask = null;
        }