/// <summary> /// Binds the return value to the UI. /// </summary> /// <param name="outcome">The outcome or processing the message.</param> public virtual IResult CreateResult(MessageProcessingOutcome outcome) { if (outcome.ResultType == typeof(void)) { return(new EmptyResult()); } var enumerable = outcome.Result as IEnumerable <IResult>; if (enumerable != null) { return(new SequentialResult(enumerable)); } return(outcome.Result as IResult ?? new DefaultResult(_routedMessageController, outcome)); }
private void HandleOutcome(IRoutedMessageWithOutcome message, IInteractionNode handlingNode, MessageProcessingOutcome outcome) { var result = _messageBinder.CreateResult(outcome); result.Completed += (r, ex) => { if (ex != null) { if (!TryApplyRescue(message, handlingNode, ex)) throw ex; } OnCompleted(); }; result.Execute(message, handlingNode); }
public override void Execute(ActionMessage actionMessage, IInteractionNode handlingNode, object context) { try { var parameters = _messageBinder.DetermineParameters(actionMessage,_requirements,handlingNode,context); // IBeforeProcessor 继承 IPreProcessor 相当于一样 var processors = _filters.PreProcessors.OfType<IBeforeProcessor>(); // caliburn preProcessor (before) (针对 IBeforeProcessor) foreach (var filter in _filters.PreProcessors.Except(processors.Cast<IPreProcessor>())) { if (!filter.Execute(actionMessage, handlingNode, parameters)) return; } // before custom aop hehavior (针对IPreProcessor) foreach (var before in processors.OrderByDescending(p => p.Priority)) { if (!before.BeforeExecute(actionMessage, handlingNode, parameters)) return; } object result = null; // the method will excute result = _method.Invoke(handlingNode.MessageHandler.Unwrap(), parameters); var outcome = new MessageProcessingOutcome(result ,_method.Info.ReturnType,false); // post foreach (var filter in _filters.PostProcessors) { filter.Execute(actionMessage, handlingNode, outcome); } HandleOutcome(actionMessage, handlingNode, outcome); } catch (Exception ex) { if (!TryApplyRescue(actionMessage, handlingNode, ex)) throw; OnCompleted(); } }
/// <summary> /// Executes the filter. /// </summary> /// <param name="message">The message.</param> /// <param name="handlingNode">The handling node.</param> /// <param name="outcome">The outcome of processing the message</param> public virtual void Execute(IRoutedMessage message, IInteractionNode handlingNode, MessageProcessingOutcome outcome) { if (_callback == null || outcome.WasCancelled) return; outcome.Result = _callback.Invoke(handlingNode.MessageHandler.Unwrap(), outcome.Result); outcome.ResultType = _callback.Info.ReturnType; }
/// <summary> /// Initializes a new instance of the <see cref="DefaultResult"/> class. /// </summary> /// <param name="routedMessageController">The routed message controller.</param> /// <param name="outcome">The outcome of processing the message.</param> public DefaultResult(IRoutedMessageController routedMessageController, MessageProcessingOutcome outcome) { _routedMessageController = routedMessageController; _outcome = outcome; }
/// <summary> /// Attaches the task complete. /// </summary> /// <param name="actionMessage">The action message.</param> /// <param name="handlingNode">The handling node.</param> /// <param name="parameters">The parameters.</param> protected void AttachTaskEvents(ActionMessage actionMessage, IInteractionNode handlingNode, object[] parameters) { if (CurrentBackgroundActionInfo.ShowBusyCursor) { CurrentBackgroundTask.Starting += (s, e) => Caliburn.Core.Invocation.Execute.OnUIThread( () => { FrameworkElement element = handlingNode.UIElement as FrameworkElement; element.Cursor = Cursors.Wait; }); CurrentBackgroundTask.Completed += (s, e) => Caliburn.Core.Invocation.Execute.OnUIThread( () => { FrameworkElement element = handlingNode.UIElement as FrameworkElement; element.Cursor = Cursors.Arrow; }); } CurrentBackgroundTask.Completed += (s, e) => Caliburn.Core.Invocation.Execute.OnUIThread( () => { Interlocked.Decrement(ref _runningCount); if (e.Error != null) { TryUpdateTrigger(actionMessage, handlingNode, false); if (!TryApplyRescue(actionMessage, handlingNode, e.Error)) throw e.Error; OnCompleted(); } else { try { var outcome = new MessageProcessingOutcome( e.Result, _method.Info.ReturnType, e.Cancelled ); foreach (var filter in _filters.PostProcessors) { filter.Execute(actionMessage, handlingNode, outcome); } var result = _messageBinder.CreateResult(outcome); result.Completed += (r, ex) => { TryUpdateTrigger(actionMessage, handlingNode, false); if (ex != null) { if (!TryApplyRescue(actionMessage, handlingNode, ex)) throw ex; } OnCompleted(); }; result.Execute(actionMessage, handlingNode); } catch (Exception ex) { TryUpdateTrigger(actionMessage, handlingNode, false); if (!TryApplyRescue(actionMessage, handlingNode, ex)) throw; OnCompleted(); } } }); Interlocked.Increment(ref _runningCount); }
/// <summary> /// Binds the return value to the UI. /// </summary> /// <param name="outcome">The outcome or processing the message.</param> public virtual IResult CreateResult(MessageProcessingOutcome outcome) { if (outcome.ResultType == typeof(void)) return new EmptyResult(); var enumerable = outcome.Result as IEnumerable<IResult>; if (enumerable != null) return new SequentialResult(enumerable); return outcome.Result as IResult ?? new DefaultResult(_routedMessageController, outcome); }
void IPostProcessor.Execute(IRoutedMessage message, IInteractionNode handlingNode, MessageProcessingOutcome outcome) { ServiceLocator.Current.GetInstance<IWindowManager>().ShowDialog(outcome.Result); }
public void Execute(IRoutedMessage message, IInteractionNode handlingNode, MessageProcessingOutcome outcome) { var content = LanguageKey.IsNullOrEmpty() ? Message : LanguageReader.GetValue(LanguageKey); ServiceLocator.Current.GetInstance<IAuditLogModel>().Write(new AuditLog { Action = content, CurrentUser = ApplicationCache.Get<string>(Global.LoggerId) }); }