protected async Task <object> ExecuteCommand(ActionInfo action, IDotvvmRequestContext context, IEnumerable <ICommandActionFilter> methodFilters) { // run OnCommandExecuting on action filters foreach (var filter in methodFilters) { await filter.OnCommandExecutingAsync(context, action); } object result = null; Task resultTask = null; try { result = action.Action(); resultTask = result as Task; if (resultTask != null) { await resultTask; } } catch (Exception ex) { if (ex is TargetInvocationException) { ex = ex.InnerException; } if (ex is DotvvmInterruptRequestExecutionException) { throw new DotvvmInterruptRequestExecutionException("The request execution was interrupted in the command!", ex); } context.CommandException = ex; } // run OnCommandExecuted on action filters foreach (var filter in methodFilters.Reverse()) { await filter.OnCommandExecutedAsync(context, action, context.CommandException); } if (context.CommandException != null && !context.IsCommandExceptionHandled) { throw new Exception("Unhandled exception occurred in the command!", context.CommandException); } if (resultTask != null) { return(TaskUtils.GetResult(resultTask)); } return(result); }
public virtual void Send(TMessage message, object context = null) { try { object cntxt = context; if (cntxt == null) { cntxt = _defaultMessenger; } IDictionary <WeakReference, ActionInfo> actions = FindActions(cntxt); if (actions != null) { foreach (var item in actions) { object recipient = item.Key.Target; if (recipient != null) // Otherwise the recipient has died and been garbage collected { ActionInfo actionInfo = item.Value; if (actionInfo.InvokeOnUiThread) { Device.BeginInvokeOnMainThread(() => { actionInfo.Action(message); }); } else { actionInfo.Action(message); } } } } } catch (Exception ex) { Logging.LogException(ex); throw; } }
private static void WaitCallBack(object obj) { ActionInfo actionInfo = obj as ActionInfo; try { if (actionInfo.Action != null) { actionInfo.Action(); } else { actionInfo.ObjectAction(actionInfo.State); } } catch (Exception ex) { } actionInfo.Status = ActionStatus.Stop; }
private void TryPublishEvents(EventStream eventStream, ActionInfo successActionInfo) { Func <EventStream, bool> tryPublishEventsAction = (stream) => { try { _eventPublisher.Publish(stream); return(true); } catch (Exception ex) { _logger.Error(string.Format("Exception raised when publishing events:{0}", stream.GetStreamInformation()), ex); return(false); } }; if (_retryService.TryAction("TryPublishEvents", () => tryPublishEventsAction(eventStream), 3)) { successActionInfo.Action(successActionInfo.Data); } else { _retryService.RetryInQueue(new ActionInfo("TryPublishEvents", (obj) => tryPublishEventsAction(obj as EventStream), eventStream, successActionInfo)); } }
protected Task ExecuteCommand(ActionInfo action, DotvvmRequestContext context, IEnumerable <ActionFilterAttribute> methodFilters) { // run OnCommandExecuting on action filters foreach (var filter in methodFilters) { filter.OnCommandExecuting(context, action); } object result = null; try { result = action.Action(); } catch (Exception ex) { if (ex is TargetInvocationException) { ex = ex.InnerException; } if (ex is DotvvmInterruptRequestExecutionException) { throw new DotvvmInterruptRequestExecutionException("The request execution was interrupted in the command!", ex); } context.CommandException = ex; } // run OnCommandExecuted on action filters foreach (var filter in methodFilters.Reverse()) { filter.OnCommandExecuted(context, action, context.CommandException); } if (context.CommandException != null && !context.IsCommandExceptionHandled) { throw new Exception("Unhandled exception occured in the command!", context.CommandException); } return(result as Task ?? (result == null ? TaskUtils.GetCompletedTask() : Task.FromResult(result))); }
private void TryPersistEvents(EventStreamContext eventStreamContext, ActionInfo successActionInfo) { Func <EventStreamContext, bool> tryPersistEventsAction = (context) => { try { _eventStore.Append(context.EventStream); return(true); } catch (Exception ex) { if (ex is ConcurrentException && IsEventStreamCommitted(context.EventStream)) { return(true); } var errorMessage = string.Format("{0} raised when persisting events:{1}", ex.GetType().Name, context.EventStream.GetStreamInformation()); _logger.Error(errorMessage, ex); if (ex is ConcurrentException) { context.SetConcurrentException(new ErrorInfo { ErrorMessage = errorMessage, Exception = ex }); return(true); } return(false); } }; if (_retryService.TryAction("TryPersistEvents", () => tryPersistEventsAction(eventStreamContext), 3)) { successActionInfo.Action(successActionInfo.Data); } else { _retryService.RetryInQueue(new ActionInfo("TryPersistEvents", (obj) => tryPersistEventsAction(obj as EventStreamContext), eventStreamContext, successActionInfo)); } }