Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public async Task <LogModels.Exception> Create(ISettings settings, LogModels.Exception exception)
        {
            IRequest request = _service.CreateRequest(new Uri(settings.BaseAddress), HttpMethod.Post, exception)
                               .AddPath("Exception")
                               .AddJwtAuthorizationToken(settings.GetToken)
            ;
            IResponse <LogModels.Exception> response = await Policy
                                                       .HandleResult <IResponse <LogModels.Exception> >(res => !res.IsSuccessStatusCode)
                                                       .WaitAndRetryAsync(3, retryAttempt => TimeSpan.FromSeconds(2.0 + Math.Pow(2, retryAttempt)))
                                                       .ExecuteAsync(() => _service.Send <LogModels.Exception>(request))
            ;

            _restUtil.CheckSuccess(response);
            return(response.Value);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
 private LogModels.Exception CreateException(Guid domainId, DateTime?createTimestamp, System.Exception exception)
 {
     LogModels.Exception innerException = null;
     if (exception.InnerException != null)
     {
         innerException = CreateException(domainId, createTimestamp, exception.InnerException);
     }
     return(new LogModels.Exception
     {
         AppDomain = AppDomain.CurrentDomain.FriendlyName,
         DomainId = domainId,
         Message = exception.Message,
         Source = exception.Source,
         StackTrace = exception.StackTrace,
         TargetSite = exception.TargetSite.ToString(),
         TypeName = exception.GetType().FullName,
         InnerException = innerException,
         Data = GetData(exception.Data),
         CreateTimestamp = createTimestamp
     });
 }