/// <summary> /// Handles asynchounously the specified exception if possible. /// </summary> /// <param name="exceptionService">The exception service.</param> /// <param name="exception">The exception to handle.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <exception cref="ArgumentNullException">The <paramref name="exceptionService"/> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="exception"/> is <c>null</c>.</exception> /// <returns><c>true</c> if the exception is handled; otherwise <c>false</c>.</returns> public static async Task <bool> HandleExceptionAsync(this IExceptionService exceptionService, Exception exception, CancellationToken cancellationToken = default(CancellationToken)) { Argument.IsNotNull("exceptionService", exceptionService); #if NET40 || SL5 || PCL return(await Task.Factory.StartNew(() => exceptionService.HandleException(exception), cancellationToken).ConfigureAwait(false)); #else return(await Task.Run(() => exceptionService.HandleException(exception), cancellationToken).ConfigureAwait(false)); #endif }
protected void Execute <T>(T handlers, Action <T> action) where T : class { Task.Factory.StartNew(() => { if (handlers != null) { try { action(handlers); } catch (Exception ex) { _exceptionService.HandleException(ex); } } }); }
public IActionResult Post([FromBody] ExceptionViewModel model) { Guid id = Guid.Empty; if (!Guid.TryParse(HttpContext.GetRouteData().Values["id"].ToString(), out id)) { return(BadRequest("Token format is incorrect")); } try { _exceptionService.HandleException(id, Mapper.Map <IExceptionInfo>(model)); } catch (InvalidTokenException e) { return(NotFound(e.Message)); } catch { return(BadRequest()); } return(Ok()); }
/// <summary> /// The execute. /// </summary> private void Execute() { IsRunning = true; lock (_syncObj) { IsCommitting = false; } try { bool aborted = false; int progress = 0; int total = _tasks.Count; var processedTasks = new Stack <ITask>(); while (!aborted && _tasks.Count > 0) { ITask task = _tasks.Peek(); try { Log.Debug("Executing task '{0}'. ", task.Name); if (_progressNotifyableViewModel != null) { _progressNotifyableViewModel.UpdateStatus(progress++, total, task); } else { // TODO: Display smooth detailed progress using the PleasWaitService // ReSharper disable AccessToModifiedClosure _dispatcherService.BeginInvoke(() => _pleaseWaitService.UpdateStatus(progress++, total, task.Name)); // ReSharper restore AccessToModifiedClosure } if (task.AutomaticallyDispatch) { _dispatcherService.Invoke(task.Execute); } else { task.Execute(); } processedTasks.Push(_tasks.Dequeue()); } catch (Exception ex) { Log.Error(ex); if (!_exceptionService.HandleException(ex)) { processedTasks.Push(_tasks.Dequeue()); aborted = true; } else { processedTasks.Push(_tasks.Dequeue()); } } } if (aborted) { progress = processedTasks.Count; while (processedTasks.Count > 0) { ITask task = processedTasks.Pop(); Log.Debug("Rolling back task '{0}'. ", task.Name); try { task.Rollback(); } catch (Exception e) { Log.Warning("Rollback of task '{0}' failed", task.Name); Log.Error(e); } finally { if (_progressNotifyableViewModel != null) { _progressNotifyableViewModel.UpdateStatus(--progress, total, task); } else { _dispatcherService.BeginInvoke(() => _pleaseWaitService.UpdateStatus(--progress, total, string.Format("Rollback '{0}'", task.Name))); } } } } } finally { if (_pleaseWaitService != null) { _dispatcherService.Invoke(() => _pleaseWaitService.Hide()); } IsRunning = false; if (_progressNotifyableViewModel != null && CloseViewModelOnTerminated) { _dispatcherService.Invoke(() => _progressNotifyableViewModel.CloseViewModel(null)); } if (_completedCallback != null) { _dispatcherService.Invoke(() => _completedCallback.Invoke()); } } }
/// <summary> /// Handles asynchounously the specified exception if possible. /// </summary> /// <param name="exceptionService">The exception service.</param> /// <param name="exception">The exception to handle.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <exception cref="ArgumentNullException">The <paramref name="exceptionService"/> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="exception"/> is <c>null</c>.</exception> /// <returns><c>true</c> if the exception is handled; otherwise <c>false</c>.</returns> public static Task <bool> HandleExceptionAsync(this IExceptionService exceptionService, Exception exception, CancellationToken cancellationToken = default(CancellationToken)) { Argument.IsNotNull("exceptionService", exceptionService); return(TaskHelper.Run(() => exceptionService.HandleException(exception), cancellationToken)); }
public void Configure(ExceptionHandlerOptions exceptionHandlerOptions) => exceptionHandlerOptions.ExceptionHandler = httpContext => { _exceptionService.HandleException(httpContext.Features.Get <IExceptionHandlerPathFeature>().Error); return(Task.CompletedTask); };