protected void DoExecute(ActionMessage actionMessage, IInteractionNode handlingNode, object[] parameters) { if (CurrentBackgroundActionInfo.BlockIfBusy && CurrentBackgroundTask.IsBusy) { return; } var context = new BackgroundActionContext(CurrentBackgroundActionInfo.BackgroundEndMode, () => _method.Invoke(handlingNode.MessageHandler.Unwrap(), parameters)); CurrentBackgroundTask.Enqueue(context); }
/// <summary> /// Executes the specified this action on the specified target. /// </summary> /// <param name="actionMessage">The action message.</param> /// <param name="handlingNode">The node.</param> /// <param name="context">The context.</param> public override void Execute(ActionMessage actionMessage, IInteractionNode handlingNode, object context) { try { TryUpdateTrigger(actionMessage, handlingNode, true); var parameters = _messageBinder.DetermineParameters( actionMessage, _requirements, handlingNode, context ); var beforeProcessors = _filters.PreProcessors.OfType <IBeforeProcessor>(); foreach (var filter in _filters.PreProcessors.Except(beforeProcessors.Cast <IPreProcessor>())) { if (!filter.Execute(actionMessage, handlingNode, parameters)) { return; } } //Before foreach (var before in beforeProcessors.OrderByDescending(p => p.Priority)) { if (!before.BeforeExecute(actionMessage, handlingNode, parameters)) { return; } } CurrentBackgroundActionInfo = _filters.PostProcessors.OfType <IBackgroundActionInfo>().Single(); var container = handlingNode.MessageHandler.Unwrap() as IExtendedPresenter; CurrentBackgroundTask = container.GetMetadata <IBackgroundThreadTask>(); if (CurrentBackgroundTask == null) { CurrentBackgroundTask = TaskImplFactory.CreateTask(CurrentBackgroundActionInfo.TaskMode); container.WasShutdown += (s, e) => CurrentBackgroundTask.Dispose(); container.AddMetadata(CurrentBackgroundTask); AttachTaskEvents(actionMessage, handlingNode, parameters); } //Exectue Before method if (CurrentBackgroundActionInfo.BeforeMethod != null) { var result = CurrentBackgroundActionInfo.BeforeMethod.Invoke(container, parameters); bool canProceed = true; if (CurrentBackgroundActionInfo.BeforeMethod.Info.ReturnType == typeof(bool)) { canProceed = result.As <bool>(); } if (!canProceed) { return; } } DoExecute(actionMessage, handlingNode, parameters); } catch (Exception ex) { TryUpdateTrigger(actionMessage, handlingNode, false); if (!TryApplyRescue(actionMessage, handlingNode, ex)) { throw; } OnCompleted(); } }