Exemplo n.º 1
0
        public static void CommitCache()
        {
            if (!_cachedHandledExceptions.Any())
            {
                throw new InvalidOperationException("No cached exceptions to commit");
            }

            using (var service = new HandledExceptionService())
            {
                service.AddRange(_cachedHandledExceptions);
            }
        }
Exemplo n.º 2
0
        private async static Task HandleExceptionAsync(Func <Task> action, List <Exception> exceptionsToCatch, bool addToDatabase,
                                                       Action handleMethodToRunSync, Func <Task> handleMethodToRunAsync, bool cache)
        {
            try
            {
                await action.Invoke();
            }
            catch (Exception ex)
            {
                if (exceptionsToCatch.Select(x => x.GetType()).Contains(ex.GetType()))
                {
                    if (handleMethodToRunSync != null)
                    {
                        handleMethodToRunSync.Invoke();
                    }

                    if (handleMethodToRunAsync != null)
                    {
                        await handleMethodToRunAsync();
                    }

                    if (addToDatabase)
                    {
                        if (cache)
                        {
                            _cachedHandledExceptions.Add(new HandledExceptionDTO()
                            {
                                ExceptionType = ex.GetType().ToString(), StackTrace = ex.InnerException.StackTrace
                            });
                        }
                        else
                        {
                            using (var service = new HandledExceptionService())
                            {
                                service.Add(new HandledExceptionDTO()
                                {
                                    ExceptionType = ex.GetType().ToString(), StackTrace = ex.InnerException.StackTrace
                                });
                            }
                        }
                    }
                }
                else
                {
                    throw ex;
                }
            }
        }
Exemplo n.º 3
0
        private static void HandleException(Action action, List <Exception> exceptionsToCatch, bool addToDatabase, Action handleMethodToRun, bool cache)
        {
            try
            {
                action.Invoke();
            }
            catch (Exception ex)
            {
                if (exceptionsToCatch.Select(x => x.GetType()).Contains(ex.GetType()))
                {
                    if (handleMethodToRun != null)
                    {
                        handleMethodToRun.Invoke();
                    }

                    if (addToDatabase)
                    {
                        if (cache)
                        {
                            _cachedHandledExceptions.Add(new HandledExceptionDTO()
                            {
                                ExceptionType = ex.GetType().ToString(), StackTrace = ex.InnerException != null ? ex.InnerException.StackTrace : null
                            });
                        }
                        else
                        {
                            using (var service = new HandledExceptionService())
                            {
                                service.Add(new HandledExceptionDTO()
                                {
                                    ExceptionType = ex.GetType().ToString(), StackTrace = ex.InnerException != null ? ex.InnerException.StackTrace : null
                                });
                            }
                        }
                    }
                }
                else
                {
                    throw ex;
                }
            }
        }