Ejemplo n.º 1
0
        private static ExceptionMessageModel GetExceptionMessageModel(IException myException)
        {
            IMessageCreator messageCreator = null;

            switch (myException)
            {
            case IValidationException:
                messageCreator = new ValidationMessageCreator();
                break;

            case IBusinessException:
                messageCreator = new BusinessMessageCreator();
                break;

            case IAuthenticationException:
                messageCreator = new AuthenticationMessageCreator();
                break;

            case IDataException:
                messageCreator = new DataMessageCreator();
                break;

            default:
                break;
            }
            return(messageCreator.GetExceptionMessageModel(myException));
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public override void VisitException(IException exception)
        {
            if (exception.Name == null)
            {
                // An exception has been declared with no name. For example `exception {}`.
                this.AddError(
                    CompilerMessageId.ExceptionMustHaveAName,
                    exception.Node.EXCEPTION().Symbol);
            }
            else if (exception.Parent.IsMemberNameAlreadyDeclared(exception))
            {
                // Another type has already been declared with the same name.
                // For example:
                // ```
                // struct Request {}
                // exception Request {}
                // ```
                this.AddError(
                    CompilerMessageId.NameAlreadyDeclared,
                    exception.Node.name,
                    exception.Name);
            }

            base.VisitException(exception);
        }
Ejemplo n.º 3
0
        public static void Handle(IException e)
        {
            ExceptionFactory factory    = ExceptionFactories.GetExceptionFactory(e);
            PublisherList    publishers = factory.CreatePublishers();
            IAction          action     = factory.CreateAction();

            action.Run(e, publishers);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes new instance of <see cref="ExceptionContract"/> from exception.
        /// </summary>
        /// <param name="exception">Exception contract.</param>
        /// <param name="correlationId">Correlation identifier.</param>
        public ExceptionContract(IException exception, string correlationId)
        {
            this.ErrorCode = exception.ErrorCode;
            this.Extension = exception.Extension;
            this.Message   = exception.Message;

            this.CorrelationId = correlationId;
        }
Ejemplo n.º 5
0
 public Dictionary <string, string> TryConvert(IException exp)
 {
     if (exp is T)
     {
         return(converter.Convert((T)exp));
     }
     return(null);
 }
 public DatabaseException(DbConfig.DbType type, int code)
 {
     switch (type)
     {
     case DbConfig.DbType.MYSQL:
         instance = MySqlException.GetInstance(code);
         break;
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Expose a method to comunicate interface with error process
 /// </summary>
 /// <param name="prmInterfaceException"></param>
 public static void LoadInterface(IException prmInterfaceException)
 {
     // Check if parameter is valid
     if (prmInterfaceException == null)
     {
         throw new Exception("Fatal Error : the Exception interface has become empty.");
     }
     // Load parameter in static value
     Interface = prmInterfaceException;
 }
Ejemplo n.º 8
0
 private void CheckForException(IException result)
 {
     if (result != null)
     {
         if (!string.IsNullOrEmpty(result.Message))
         {
             throw new GrabzItException(result.Message, result.Code);
         }
     }
 }
Ejemplo n.º 9
0
        public async Task <IException> GetInnerException(ISettings settings, long id)
        {
            IException    exception = null;
            ExceptionData data      = await _dataFactory.GetInnerException(_settingsFactory.CreateData(settings), id);

            if (data != null)
            {
                exception = new Exception(data, _dataSaver, this);
            }
            return(exception);
        }
Ejemplo n.º 10
0
        private async Task <LogModels.Exception> Map(IException innerException, CoreSettings settings, IMapper mapper)
        {
            LogModels.Exception exception       = mapper.Map <LogModels.Exception>(innerException);
            IException          innerException2 = await innerException.GetInnerException(settings);

            if (innerException2 != null)
            {
                exception.InnerException = await Map(innerException2, settings, mapper);
            }
            return(exception);
        }
Ejemplo n.º 11
0
        public async Task <IException> Get(ISettings settings, long id)
        {
            IException    result = null;
            ExceptionData data   = await _dataFactory.Get(_settingsFactory.CreateData(settings), id);

            if (data != null)
            {
                result = new Exception(data, _dataSaver, this);
            }
            return(result);
        }
Ejemplo n.º 12
0
 public void Run(IException e, PublisherList publishers)
 {
     foreach (IPublisher p in publishers)
     {
         try
         {
             p.Publish(e);
         }
         catch
         {
         }
     }
 }
Ejemplo n.º 13
0
        public virtual IActionResult Post([FromBody] T entity)
        {
            IException exception = _service.Add(entity);

            if (exception.IsValid)
            {
                return(Json(entity));
            }
            else
            {
                return(new BadRequestObjectResult(exception.GetException()));
            }
        }
Ejemplo n.º 14
0
        public virtual IActionResult Delete(long id)
        {
            IException exception = _service.Delete(id);

            if (exception.IsValid)
            {
                return(new OkObjectResult("Deleted"));
            }

            else
            {
                return(new JsonResult(exception.GetException()));
            }
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> Get([FromRoute] Guid?domainId, [FromRoute] long?id)
        {
            IActionResult result = null;

            try
            {
                if (result == null && !id.HasValue)
                {
                    result = BadRequest("Missing exception id parameter value");
                }
                if (result == null && (!domainId.HasValue || domainId.Value.Equals(Guid.Empty)))
                {
                    result = BadRequest("Missing domain id prameter value");
                }
                if (result == null)
                {
                    using ILifetimeScope scope = _container.BeginLifetimeScope();
                    SettingsFactory   settingsFactory  = scope.Resolve <SettingsFactory>();
                    CoreSettings      settings         = settingsFactory.CreateCore(_settings.Value);
                    IExceptionFactory exceptionFactory = scope.Resolve <IExceptionFactory>();
                    IException        exception        = await exceptionFactory.Get(settings, id.Value);

                    if (exception != null && !exception.DomainId.Equals(domainId.Value))
                    {
                        exception = null;
                    }
                    if (result == null && !(await VerifyDomainAccount(domainId.Value, settingsFactory, _settings.Value, scope.Resolve <IDomainService>())))
                    {
                        result = StatusCode(StatusCodes.Status401Unauthorized);
                    }
                    if (result == null && exception == null)
                    {
                        result = NotFound();
                    }
                    if (result == null && exception != null)
                    {
                        IMapper mapper = MapperConfigurationFactory.CreateMapper();
                        result = Ok(
                            await Map(exception, settings, mapper)
                            );
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                result = StatusCode(StatusCodes.Status500InternalServerError);
            }
            return(result);
        }
Ejemplo n.º 16
0
        private static void UnhandleException(Exception e)
        {
            // 记录日志
            IException innerException = e as IException;
            ILog       adviceLogger   = LogManager.GetLogger(AppDomain.CurrentDomain.Id.ToString());

            try
            {
                if (innerException != null)
                {
                    if (innerException is Core.SysRegist.SysRegistException)
                    {
                        ForeStar.SysReg.SysRegistForm from = new SysReg.SysRegistForm();
                        DialogResult dr = from.ShowDialog();
                        if (dr == DialogResult.OK)
                        {
                            Application.Restart();
                        }
                        else
                        {
                            Application.Exit();
                        }
                    }
                    else
                    {
                        if (!innerException.IsLog)
                        {
                            adviceLogger.Error(e.Message, e);
                            innerException.IsLog = true;
                        }

                        if (!innerException.IsShow)
                        {
                            innerException.IsShow = true;
                        }
                    }
                }
                else
                {
                    adviceLogger.Error(e.Message, e);
                }
                //XtraMessageBox.Show(String.Format("原因:{0};\n堆栈信息:{1}", e.Message, e.StackTrace));
            }
            catch (Exception ex)
            {
                adviceLogger.Error(ex.Message, ex);
                //XtraMessageBox.Show(String.Format("原因:{0};\n堆栈信息:{1}", e.Message, e.StackTrace));
            }
        }
Ejemplo n.º 17
0
 public BooksBusinessLogic
 (
     IRepository <Book> repositoryBook,
     IRepository <Author> repositoryAuthor,
     IMapper mapper,
     IException <Book> exceptionBook,
     IException <Author> exceptionAuthor
 )
 {
     _repositoryBook   = repositoryBook;
     _repositoryAuthor = repositoryAuthor;
     _mapper           = mapper;
     _exceptionBook    = exceptionBook;
     _exceptionAuthor  = exceptionAuthor;
 }
Ejemplo n.º 18
0
 public IException Create(Guid domainId, DateTime?createTimestamp, IException parentException)
 {
     if (!createTimestamp.HasValue)
     {
         createTimestamp = DateTime.UtcNow;
     }
     createTimestamp = createTimestamp.Value.ToUniversalTime();
     return(new Exception(
                new ExceptionData()
     {
         DomainId = domainId, CreateTimestamp = createTimestamp.Value
     },
                _dataSaver,
                this
                ));
 }
        internal static ExceptionFactory GetExceptionFactory(IException e)
        {
            if (e is CoreLevelException)
            {
                return(new CoreLevelFactory());
            }
            else if (e is UserLevelException)
            {
                return(new UserLevelFactory());
            }
            else if (e is CriticalLevelException)
            {
                return(new CriticalLevelFactory());
            }

            throw new NotSupportedException();
        }
Ejemplo n.º 20
0
        /// <summary>
        /// 根据mode创建不同的异常处理模式
        /// </summary>
        /// <param name="mode"></param>
        /// <returns></returns>
        public static IException Create(logEncapsulation.ExceptionMode mode)
        {
            IException exception = null;

            try
            {
                switch (mode)
                {
                case ExceptionMode.Default:
                    exception = new logEncapsulation.ExceptionDefault();
                    break;
                }
            }
            catch (Exception ex)
            {
                throw new System.Exception("Create Exception Error:" + ex.Message);
            }
            return(exception);
        }
Ejemplo n.º 21
0
        private IException Map(
            LogModels.Exception exception,
            Guid domainId,
            DateTime?timestamp,
            IExceptionFactory exceptionFactory,
            IMapper mapper,
            List <IException> allExceptions,
            IException parentException = null)
        {
            IException innerException = exceptionFactory.Create(domainId, timestamp, parentException);

            mapper.Map <LogModels.Exception, IException>(exception, innerException);
            allExceptions.Add(innerException);
            if (exception.InnerException != null)
            {
                Map(exception.InnerException, domainId, timestamp, exceptionFactory, mapper, allExceptions, innerException);
            }
            return(innerException);
        }
Ejemplo n.º 22
0
        public async Task <IActionResult> Create([FromBody] LogModels.Exception exception)
        {
            IActionResult result = null;

            try
            {
                if (result == null && (!exception.DomainId.HasValue || exception.DomainId.Value.Equals(Guid.Empty)))
                {
                    result = BadRequest("Missing domain guid value");
                }
                if (result == null)
                {
                    using ILifetimeScope scope = _container.BeginLifetimeScope();
                    SettingsFactory settingsFactory = scope.Resolve <SettingsFactory>();
                    if (!(await VerifyDomainAccountWriteAccess(exception.DomainId.Value, settingsFactory, _settings.Value, scope.Resolve <IDomainService>())))
                    {
                        result = StatusCode(StatusCodes.Status401Unauthorized);
                    }
                    if (result == null)
                    {
                        CoreSettings      settings       = settingsFactory.CreateCore(_settings.Value);
                        IExceptionFactory factory        = scope.Resolve <IExceptionFactory>();
                        IMapper           mapper         = MapperConfigurationFactory.CreateMapper();
                        List <IException> allExceptions  = new List <IException>();
                        IException        innerException = Map(exception, exception.DomainId.Value, exception.CreateTimestamp, factory, mapper, allExceptions);
                        IExceptionSaver   saver          = scope.Resolve <IExceptionSaver>();
                        await saver.Create(settings, allExceptions.ToArray());

                        result = Ok(
                            await Map(innerException, settings, mapper)
                            );
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                result = StatusCode(StatusCodes.Status500InternalServerError);
            }
            return(result);
        }
Ejemplo n.º 23
0
 public HomeController(IException e)
 {
     obj = e;
 }
Ejemplo n.º 24
0
 public static void ErrorThrow(IException err)
 {
     Error(err);
     throw err.Exception;
 }
Ejemplo n.º 25
0
 public static void Error(IException err)
 {
     LogStraightToFile($"{err.ShortDescription}\n{err.Exception.StackTrace}");
     LoggerSubj.OnNext(err);
 }
Ejemplo n.º 26
0
 public void Publish(IException exception)
 {
     Console.WriteLine("SMS wrote");
 }
Ejemplo n.º 27
0
 public FrameworkException(IException Exception)
 {
     this.Exception = Exception;
 }
        public static void Trace(IException exception)
        {
            ExceptionLogger.LogTrace(exception.ExceptionMessage);

            exception.Throw();
        }
Ejemplo n.º 29
0
 public ExceptionMessageModel GetExceptionMessageModel(IException myException)
 {
     return(BusinessOperationExceptionMessage(myException as IBusinessException));
 }
        public static void Debug(IException exception)
        {
            ExceptionLogger.LogDebug(exception.ExceptionMessage);

            exception.Throw();
        }
        public static void Warn(IException exception)
        {
            ExceptionLogger.LogWarn(exception.ExceptionMessage);

            exception.Throw();
        }