示例#1
0
        public virtual void Execute(UpdateEntityUseCaseRequest <T> useCaseRequest, IOutputPort <UpdateEntityUseCaseResponse> outputPort)
        {
            if (!EntityValidator.IsValid(useCaseRequest.Entity))
            {
                outputPort.HandleError(new SimpleUseCaseError(1, "Not Valid Entity"));
                return;
            }

            bool updated;

            try
            {
                updated = Repository.Update(useCaseRequest.Entity);
            }
            catch (Exception exception)
            {
                CoreLogger.LogError(exception);

                outputPort.HandleError(new SimpleUseCaseError(2, "Update Not Found"));
                return;
            }

            if (!updated)
            {
                outputPort.HandleError(new SimpleUseCaseError(2, "Update Not Found"));
                return;
            }

            var updateEntityUseCaseResponse = new UpdateEntityUseCaseResponse(useCaseRequest.Entity.Id);

            outputPort.HandleSuccess(updateEntityUseCaseResponse);
        }
示例#2
0
        private static void InspectDll(string assemblyPath, IPluginLibrary library)
        {
            try
            {
                var assembly = Assembly.LoadFrom(assemblyPath);
                foreach (var assemblyInspector in _assemblyInspectors)
                {
                    var plugins = new List <IPluginDescriptor>();
                    try
                    {
                        plugins = assemblyInspector.InspectAssembly(assembly);
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError($"{assemblyInspector.GetType().Name} failed to inpect assembly at {assemblyPath}", ex);
                    }

                    foreach (var plugin in plugins)
                    {
                        library.Add(plugin);
                        _logger.Log($"Loaded {plugin.Metadata.Type} '{plugin.Metadata.DisplayName}' from {assemblyPath}");
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to load assembly at {assemblyPath}", ex);
            }
        }
示例#3
0
        public virtual void Execute(CreateEntityUseCaseRequest <T> useCaseRequest, IOutputPort <CreateEntityUseCaseResponse> outputPort)
        {
            if (!EntityValidator.IsValid(useCaseRequest.Entity))
            {
                outputPort.HandleError(new SimpleUseCaseError(1, "Not Valid Entity"));
                return;
            }

            long id;

            try
            {
                id = Repository.Add(useCaseRequest.Entity);
            }
            catch (Exception exception)
            {
                CoreLogger.LogError(exception);

                outputPort.HandleError(new SimpleUseCaseError(2, "Add Not Found"));
                return;
            }

            if (id == default(long))
            {
                outputPort.HandleError(new SimpleUseCaseError(2, "Add Not Found"));
                return;
            }

            var createEntityUseCaseResponse = new CreateEntityUseCaseResponse(id);

            outputPort.HandleSuccess(createEntityUseCaseResponse);
        }
示例#4
0
        public virtual void Execute(GetEntityByIdUseCaseRequest useCaseRequest, IOutputPort <GetEntityByIdUseCaseResponse <T> > outputPort)
        {
            T entity;

            try
            {
                entity = Repository.GetById(useCaseRequest.Id);
            }
            catch (Exception exception)
            {
                CoreLogger.LogError(exception);

                outputPort.HandleError(new SimpleUseCaseError(2, "Unknown Error"));
                return;
            }

            if (entity == default(T))
            {
                outputPort.HandleError(new SimpleUseCaseError(1, $"{typeof(T).Name} with {nameof(useCaseRequest.Id)} {useCaseRequest.Id} not exists"));
                return;
            }

            var getByIdEntityUseCaseResponse = new GetEntityByIdUseCaseResponse <T>(entity);

            outputPort.HandleSuccess(getByIdEntityUseCaseResponse);
        }
        public virtual void Execute(DeleteEntityUseCaseRequest useCaseRequest, IOutputPort <DeleteEntityUseCaseResponse> outputPort)
        {
            var entityToBeDeleted = new T {
                Id = useCaseRequest.Id
            };

            bool deleted;

            try
            {
                deleted = Repository.Delete(entityToBeDeleted);
            }
            catch (Exception exception)
            {
                CoreLogger.LogError(exception);

                outputPort.HandleError(new SimpleUseCaseError(1, "Delete Not Found"));
                return;
            }

            if (!deleted)
            {
                outputPort.HandleError(new SimpleUseCaseError(1, "Delete Not Found"));
                return;
            }

            var deleteEntityUseCaseResponse = new DeleteEntityUseCaseResponse(useCaseRequest.Id);

            outputPort.HandleSuccess(deleteEntityUseCaseResponse);
        }
示例#6
0
 public void Draw(ICanvas canvas)
 {
     try
     {
         _figure.Draw(canvas, Parameters);
     }
     catch (Exception ex)
     {
         _logger.LogError($"{Metadata.DisplayName} failed to execute Draw()", ex);
     }
 }
示例#7
0
 public Stream OnSerialized(Stream stream)
 {
     try
     {
         return(_extension.OnSerialized(stream));
     }
     catch (Exception ex)
     {
         _logger.LogError($"{Metadata.DisplayName} failed to execute OnSerialized()", ex);
         return(null);
     }
 }
        public void Execute(GetFooByNameUseCaseRequest useCaseRequest, IOutputPort <GetFooByNameUseCaseResponse> outputPort)
        {
            Foo foo;

            try
            {
                foo = _fooRepository.GetByName(useCaseRequest.Name);
            }
            catch (Exception exception)
            {
                _coreLogger.LogError(exception);

                outputPort.HandleError(new SimpleUseCaseError(2, "Unknown Error"));
                return;
            }

            if (foo == default(Foo))
            {
                outputPort.HandleError(new SimpleUseCaseError(1, $"{nameof(Foo)} with {nameof(useCaseRequest.Name)} {useCaseRequest.Name} not exists"));
                return;
            }

            var getFooByNameUseCaseResponse = new GetFooByNameUseCaseResponse(foo);

            outputPort.HandleSuccess(getFooByNameUseCaseResponse);
        }
        public virtual void Execute(GetAllEntitysUseCaseRequest useCaseRequest, IOutputPort <GetAllEntityUseCaseResponse <T> > outputPort)
        {
            IEnumerable <T> entities;

            try
            {
                entities = Repository.GetAll();
            }
            catch (Exception exception)
            {
                CoreLogger.LogError(exception);

                outputPort.HandleError(new SimpleUseCaseError(1, "Unknown Error"));
                return;
            }

            var getAllEntityUseCaseResponse = new GetAllEntityUseCaseResponse <T>(entities);

            outputPort.HandleSuccess(getAllEntityUseCaseResponse);
        }
        public async Task Invoke(HttpContext context)
        {
            try
            {
                await _next(context);

                if (_logger.Configuration.MinLevel == LogLevel.Trace &&
                    (context.Response.StatusCode != (int)HttpStatusCode.NotFound && context.Response.StatusCode != (int)HttpStatusCode.GatewayTimeout))
                {
                    var sb = new System.Text.StringBuilder();
                    sb.Append($"REQUEST:");
                    sb.Append($" TRACEIDENTIFIER:{context.TraceIdentifier}");
                    sb.Append($" - HOST:{context.Request.Host}");
                    sb.Append($" - HTTPS:{context.Request.IsHttps}");
                    sb.Append($" - PATH:{context.Request.Path}");
                    sb.Append($" - QUERYSTRING:{context.Request.QueryString}");
                    sb.Append($" - METHOD:{context.Request.Method}");
                    sb.Append($" - CONTENT-TYPE:{context.Request.ContentType}");
                    sb.Append($" - RESPONSE STATUSCODE:{context.Response.StatusCode}");
                    await _logger.LogTrace(message : sb.ToString());
                }

                if (context.Response.StatusCode == (int)HttpStatusCode.NotFound || context.Response.StatusCode == (int)HttpStatusCode.GatewayTimeout)
                {
                    if (_logger.Configuration.MinLevel == LogLevel.Warning)
                    {
                        var sb = new System.Text.StringBuilder();
                        sb.Append($"REQUEST:");
                        sb.Append($" TRACEIDENTIFIER:{context.TraceIdentifier}");
                        sb.Append($" - HOST:{context.Request.Host}");
                        sb.Append($" - HTTPS:{context.Request.IsHttps}");
                        sb.Append($" - PATH:{context.Request.Path}");
                        sb.Append($" - QUERYSTRING:{context.Request.QueryString}");
                        sb.Append($" - METHOD:{context.Request.Method}");
                        sb.Append($" - CONTENT-TYPE:{context.Request.ContentType}");
                        sb.Append($" - RESPONSE STATUSCODE:{context.Response.StatusCode}");
                        await _logger.LogWarning(message : sb.ToString());
                    }

                    if (_logger.Configuration.ErrorPages?.Count() > 0)
                    {
                        if (_logger.Configuration.ErrorPages.Select(t => t.Key).Contains(context.Response.StatusCode))
                        {
                            context.Response.Redirect(_logger.Configuration.ErrorPages.FirstOrDefault(t => t.Key == context.Response.StatusCode).Value);
                        }
                    }
                    if (!string.IsNullOrWhiteSpace(_logger.Configuration.ErrorPage))
                    {
                        context.Response.Redirect(_logger.Configuration.ErrorPage);
                    }
                }
            }
            catch (Exception e)
            {
                var fulldata = JsonConvert.SerializeObject(e, Formatting.Indented);
                await _logger.LogError(e.Message, fulldata);

                if (_logger.Configuration.ErrorPages?.Count() > 0)
                {
                    if (_logger.Configuration.ErrorPages.Select(t => t.Key).Contains(context.Response.StatusCode))
                    {
                        context.Response.Redirect(_logger.Configuration.ErrorPages.FirstOrDefault(t => t.Key == context.Response.StatusCode).Value);
                    }
                }
                if (!string.IsNullOrWhiteSpace(_logger.Configuration.ErrorPage))
                {
                    context.Response.Redirect(_logger.Configuration.ErrorPage);
                }
            }
        }
示例#11
0
 public async Task LogError(Log_Master item, Exception exception = null)
 {
     await _logger.LogError(item.Message, exception, item.CallerMemberName, item.CallerMemberLineNumber);
 }