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); }
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); } }
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); }
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); }
public void Draw(ICanvas canvas) { try { _figure.Draw(canvas, Parameters); } catch (Exception ex) { _logger.LogError($"{Metadata.DisplayName} failed to execute Draw()", ex); } }
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); } } }
public async Task LogError(Log_Master item, Exception exception = null) { await _logger.LogError(item.Message, exception, item.CallerMemberName, item.CallerMemberLineNumber); }