/// <summary> /// Creates a model based on the given domain entity. /// </summary> /// <param name="entity">The domain entity.</param> /// <param name="serializer">The JSON serializer.</param> /// <returns>The domain entity as a model.</returns> public static TaskModel Create(TaskEntity entity, IDefaultJsonSerializer serializer) { if (entity == null) { return(null); } var model = new TaskModel { Id = entity.Id.ToString(), CreatedDate = entity.CreatedDate, ModifiedDate = entity.ModifiedDate, Status = Enum.TryParse(entity.Status.ToString(), out TaskStatus status) ? status : TaskStatus.Created, Message = entity.Message, Position = entity.Position, Progress = entity.Progress }; if (Enum.TryParse(entity.CommandType.ToString(), out CommandType commandType)) { switch (commandType) { case CommandType.ProcessObjectCommand: model.Command = serializer.Deserialize <ProcessObjectCommand>(entity.CommandSerialized); break; default: break; } } return(model); }
/// <summary> /// Creates a model based on the given domain entity. /// </summary> /// <param name="entity">The domain entity.</param> /// <param name="serializer">The JSON serializer.</param> /// <returns>The domain entity as a model.</returns> public static new ProcessResultModel Create(ResultEntity entity, IDefaultJsonSerializer serializer) { if (entity == null) { return(null); } var model = new ProcessResultModel { Id = entity.Id.ToString(), CreatedDate = entity.CreatedDate, ModifiedDate = entity.ModifiedDate, Version = entity.Version, JsonFilename = entity.JsonFilename }; var deserialized = serializer.Deserialize <ProcessResultModel>(entity.ResultSerialized); if (deserialized != null) { model.Version = deserialized.Version; model.JsonFilename = deserialized.JsonFilename; model.LabelCount = deserialized.LabelCount; model.Size = deserialized.Size; model.Images = deserialized.Images; model.Gifs = deserialized.Gifs; model.CombinedGif = deserialized.CombinedGif; } return(model); }
/// <summary> /// Creates a model based on the given domain entity. /// </summary> /// <param name="entity">The domain entity.</param> /// <param name="serializer">The JSON serializer.</param> /// <returns>The domain entity as a model.</returns> public static EventModel Create(EventEntity entity, IDefaultJsonSerializer serializer) { if (entity == null) { return(null); } var model = new EventModel { Id = entity.Id.ToString(), CreatedDate = entity.CreatedDate, ModifiedDate = entity.ModifiedDate, ApiVersion = entity.ApiVersion, EventType = Enum.TryParse(entity.EventType.ToString(), out EventType eventType) ? eventType : EventType.Unknown, UserId = entity.UserId }; try { switch (model.EventType) { case EventType.TaskCreated: case EventType.TaskUpdated: case EventType.TaskDeleted: model.Data = new TaskEventDataModel() { Object = serializer.Deserialize <TaskModel>(entity.EventSerialized) }; break; case EventType.ObjectCreated: case EventType.ObjectUpdated: case EventType.ObjectDeleted: model.Data = new ObjectEventDataModel() { Object = serializer.Deserialize <ObjectModel>(entity.EventSerialized) }; break; case EventType.AuditEventCreated: model.Data = new AuditEventDataModel() { Object = serializer.Deserialize <AuditEventModel>(entity.EventSerialized) }; break; default: break; } } catch (Exception) { model.DataSerialized = entity.EventSerialized; } return(model); } }
/// <summary> /// Initializes a new instance of the <see cref="CreateCommandHandler"/> class. /// </summary> /// <param name="module">The command handler module.</param> /// <param name="idGenerator">The generator for unique identifiers.</param> /// <param name="serializer">The JSON serializer.</param> public CreateCommandHandler( ICommandHandlerModule module, IIdGenerator idGenerator, IDefaultJsonSerializer serializer) : base(module) { this.idGenerator = idGenerator ?? throw new ArgumentNullException(nameof(idGenerator)); this.serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); }
/// <summary> /// Initializes a new instance of the <see cref="UpdateCommandHandler"/> class. /// </summary> /// <param name="module">The command handler module.</param> /// <param name="serializer">The JSON serializer.</param> /// <param name="mediator">The mediator.</param> public UpdateCommandHandler( ICommandHandlerModule module, IDefaultJsonSerializer serializer, IMediator mediator) : base(module) { this.serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); this.mediator = mediator ?? throw new ArgumentNullException(nameof(mediator)); }
/// <summary> /// Initializes a new instance of the <see cref="QueryHandlerModule"/> class. /// </summary> /// <param name="context">The context.</param> /// <param name="constants">The application constants.</param> /// <param name="principalProvider">The principal provider.</param> /// <param name="serializer">The JSON serializer.</param> public QueryHandlerModule( IAmiUnitOfWork context, IApplicationConstants constants, ICustomPrincipalProvider principalProvider, IDefaultJsonSerializer serializer) { Context = context ?? throw new ArgumentNullException(nameof(context)); Constants = constants ?? throw new ArgumentNullException(nameof(constants)); PrincipalProvider = principalProvider ?? throw new ArgumentNullException(nameof(principalProvider)); Serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); }
/// <summary> /// Initializes a new instance of the <see cref="ProcessCommandHandler"/> class. /// </summary> /// <param name="module">The command handler module.</param> /// <param name="idGenerator">The generator for unique identifiers.</param> /// <param name="serializer">The JSON serializer.</param> /// <param name="imageService">The image service.</param> public ProcessCommandHandler( ICommandHandlerModule module, IIdGenerator idGenerator, IDefaultJsonSerializer serializer, IImageService imageService) : base(module) { this.idGenerator = idGenerator ?? throw new ArgumentNullException(nameof(idGenerator)); this.serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); this.imageService = imageService ?? throw new ArgumentNullException(nameof(imageService)); }
/// <summary> /// Initializes a new instance of the <see cref="AppLogReader"/> class. /// </summary> /// <param name="configuration">The application configuration.</param> /// <param name="constants">The application constants.</param> /// <param name="fileSystemStrategy">The file system strategy.</param> /// <param name="serializer">The JSON serializer.</param> public AppLogReader( IAppConfiguration configuration, IApplicationConstants constants, IFileSystemStrategy fileSystemStrategy, IDefaultJsonSerializer serializer) { this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); this.constants = constants ?? throw new ArgumentNullException(nameof(constants)); this.fileSystemStrategy = fileSystemStrategy ?? throw new ArgumentNullException(nameof(fileSystemStrategy)); this.serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); }
/// <summary> /// Initializes a new instance of the <see cref="ResetCommandHandler"/> class. /// </summary> /// <param name="module">The command handler module.</param> /// <param name="configuration">The API configuration.</param> /// <param name="serializer">The JSON serializer.</param> public ResetCommandHandler( ICommandHandlerModule module, IApiConfiguration configuration, IDefaultJsonSerializer serializer) : base(module) { this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); this.serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); batchSize = configuration.Options.BatchSize > 0 ? configuration.Options.BatchSize : 1000; }
/// <summary> /// Initializes a new instance of the <see cref="ProcessCommandHandler"/> class. /// </summary> /// <param name="context">The context.</param> /// <param name="idGenService">The service to generate unique identifiers.</param> /// <param name="serializer">The JSON serializer.</param> /// <param name="imageService">The image service.</param> public ProcessCommandHandler( IAmiUnitOfWork context, IIdGenService idGenService, IDefaultJsonSerializer serializer, IImageService imageService) : base() { this.context = context ?? throw new ArgumentNullException(nameof(context)); this.idGenService = idGenService ?? throw new ArgumentNullException(nameof(idGenService)); this.serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); this.imageService = imageService ?? throw new ArgumentNullException(nameof(imageService)); }
/// <summary> /// Initializes a new instance of the <see cref="CreateCommandHandler"/> class. /// </summary> /// <param name="context">The context.</param> /// <param name="idGenService">The service to generate unique identifiers.</param> /// <param name="serializer">The JSON serializer.</param> /// <param name="queue">The task queue.</param> public CreateCommandHandler( IAmiUnitOfWork context, IIdGenService idGenService, IDefaultJsonSerializer serializer, ITaskQueue queue) : base() { this.context = context ?? throw new ArgumentNullException(nameof(context)); this.idGenService = idGenService ?? throw new ArgumentNullException(nameof(idGenService)); this.serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); this.queue = queue ?? throw new ArgumentNullException(nameof(queue)); }
/// <summary> /// Initializes a new instance of the <see cref="CreateCommandHandler"/> class. /// </summary> /// <param name="module">The command handler module.</param> /// <param name="idGenerator">The generator for unique identifiers.</param> /// <param name="serializer">The JSON serializer.</param> /// <param name="mediator">The mediator.</param> /// <param name="backgroundService">The background service.</param> public CreateCommandHandler( ICommandHandlerModule module, IIdGenerator idGenerator, IDefaultJsonSerializer serializer, IMediator mediator, IBackgroundService backgroundService) : base(module) { this.idGenerator = idGenerator ?? throw new ArgumentNullException(nameof(idGenerator)); this.serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); this.mediator = mediator ?? throw new ArgumentNullException(nameof(mediator)); this.backgroundService = backgroundService ?? throw new ArgumentNullException(nameof(backgroundService)); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultJsonWriter"/> class. /// </summary> /// <param name="serializer">The JSON serializer.</param> /// <param name="fileSystemStrategy">The file system strategy.</param> /// <exception cref="ArgumentNullException"> /// serializer /// or /// fileSystemStrategy /// </exception> public DefaultJsonWriter(IDefaultJsonSerializer serializer, IFileSystemStrategy fileSystemStrategy) { this.serializer = serializer; if (this.serializer == null) { throw new ArgumentNullException(nameof(serializer)); } this.fileSystemStrategy = fileSystemStrategy; if (this.fileSystemStrategy == null) { throw new ArgumentNullException(nameof(fileSystemStrategy)); } }
/// <summary> /// Creates a model based on the given domain entity. /// </summary> /// <param name="entity">The domain entity.</param> /// <param name="serializer">The JSON serializer.</param> /// <returns>The domain entity as a model.</returns> public static AuditEventModel Create(AuditEventEntity entity, IDefaultJsonSerializer serializer) { if (entity == null) { return(null); } var model = new AuditEventModel { Timestamp = entity.Timestamp, EventType = Enum.TryParse(entity.EventType.ToString(), out EventType eventType) ? eventType : EventType.INVOKE_SERVICE, SubEventType = Enum.TryParse(entity.SubEventType.ToString(), out SubEventType subEventType) ? subEventType : SubEventType.None, Xdas = serializer.Deserialize <XDASv2Event>(entity.EventSerialized) }; return(model); } }
/// <summary> /// Creates a model based on the given domain entity. /// </summary> /// <param name="entity">The domain entity.</param> /// <param name="serializer">The JSON serializer.</param> /// <returns>The domain entity as a model.</returns> public static ResultModel Create(ResultEntity entity, IDefaultJsonSerializer serializer) { if (entity == null) { return(null); } if (Enum.TryParse(entity.ResultType.ToString(), out ResultType resultType)) { switch (resultType) { case ResultType.ProcessResult: return(ProcessResultModel.Create(entity, serializer)); default: break; } } return(null); }
/// <summary> /// Initializes a new instance of the <see cref="ThrottleMiddleware"/> class. /// </summary> /// <param name="next">The next.</param> /// <param name="options">The options.</param> /// <param name="counterStore">The counter store.</param> /// <param name="policyStore">The policy store.</param> /// <param name="config">The rate limit configuration.</param> /// <param name="logger">The logger.</param> /// <param name="configuration">The API configuration.</param> /// <param name="serializer">The JSON serializer.</param> /// <exception cref="ArgumentNullException">configuration</exception> public ThrottleMiddleware( RequestDelegate next, IOptions <IpRateLimitOptions> options, IRateLimitCounterStore counterStore, IIpPolicyStore policyStore, IRateLimitConfiguration config, ILogger <IpRateLimitMiddleware> logger, IApiConfiguration configuration, IDefaultJsonSerializer serializer) : base(next, options, counterStore, policyStore, config, logger) { Ensure.ArgumentNotNull(options, nameof(options)); if (options.Value == null) { throw new UnexpectedNullException("The options value is null."); } this.options = options.Value; this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); this.serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); }
/// <summary> /// Initializes a new instance of the <see cref="TokenService"/> class. /// </summary> /// <param name="loggerFactory">The logger factory.</param> /// <param name="configuration">The API configuration.</param> /// <param name="constants">The application constants.</param> /// <param name="mediator">The mediator.</param> /// <param name="serializer">The serializer.</param> /// <param name="userManager">The user manager.</param> public TokenService( ILoggerFactory loggerFactory, IApiConfiguration configuration, IApplicationConstants constants, IMediator mediator, IDefaultJsonSerializer serializer, UserManager <UserEntity> userManager) { logger = loggerFactory?.CreateLogger <TokenService>() ?? throw new ArgumentNullException(nameof(loggerFactory)); this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); this.constants = constants ?? throw new ArgumentNullException(nameof(constants)); this.mediator = mediator ?? throw new ArgumentNullException(nameof(mediator)); this.userManager = userManager ?? throw new ArgumentNullException(nameof(userManager)); this.serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); var serializerWrapper = new JwtJsonSerializerWrapper(serializer); var urlEncoder = new JwtBase64UrlEncoder(); encoder = new JwtEncoder(new HMACSHA256Algorithm(), serializerWrapper, urlEncoder); var validator = new JwtValidator(serializerWrapper, new UtcDateTimeProvider()); decoder = new JwtDecoder(serializerWrapper, validator, urlEncoder); }
/// <summary> /// Initializes a new instance of the <see cref="ProcessCommandHandler"/> class. /// </summary> /// <param name="context">The context.</param> /// <param name="idGenService">The service to generate unique identifiers.</param> /// <param name="serializer">The JSON serializer.</param> /// <param name="mediator">The mediator.</param> /// <param name="configuration">The configuration.</param> /// <param name="fileSystemStrategy">The file system strategy.</param> public ProcessCommandHandler( IAmiUnitOfWork context, IIdGenService idGenService, IDefaultJsonSerializer serializer, IMediator mediator, IAmiConfigurationManager configuration, IFileSystemStrategy fileSystemStrategy) : base() { this.context = context ?? throw new ArgumentNullException(nameof(context)); this.idGenService = idGenService ?? throw new ArgumentNullException(nameof(idGenService)); this.serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); this.mediator = mediator ?? throw new ArgumentNullException(nameof(mediator)); this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); if (fileSystemStrategy == null) { throw new ArgumentNullException(nameof(fileSystemStrategy)); } fileSystem = fileSystemStrategy.Create(configuration.WorkingDirectory); }
/// <summary> /// Initializes a new instance of the <see cref="JwtJsonSerializerWrapper"/> class. /// </summary> /// <param name="serializer">The serializer.</param> /// <exception cref="ArgumentNullException">serializer</exception> public JwtJsonSerializerWrapper(IDefaultJsonSerializer serializer) { this.serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); }
/// <summary> /// Creates a model based on the given domain entities. /// </summary> /// <param name="entity">The domain entity.</param> /// <param name="objectEntity">The domain object entity.</param> /// <param name="resultEntity">The domain result entity.</param> /// <param name="serializer">The JSON serializer.</param> /// <returns>The domain entity as a model.</returns> public static TaskModel Create(TaskEntity entity, ObjectEntity objectEntity, ResultEntity resultEntity, IDefaultJsonSerializer serializer) { var model = Create(entity, serializer); if (model == null) { return(null); } if (objectEntity != null) { model.Object = ObjectModel.Create(objectEntity); } if (resultEntity != null) { model.Result = ResultModel.Create(resultEntity, serializer); } return(model); }
/// <summary> /// Initializes a new instance of the <see cref="JsonHttpClient"/> class. /// </summary> /// <param name="serializer">The JSON serializer.</param> public JsonHttpClient(IDefaultJsonSerializer serializer) { this.serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType)); }
/// <summary> /// Initializes a new instance of the <see cref="UpdateCommandHandler"/> class. /// </summary> /// <param name="context">The context.</param> /// <param name="serializer">The JSON serializer.</param> public UpdateCommandHandler(IAmiUnitOfWork context, IDefaultJsonSerializer serializer) : base() { this.context = context ?? throw new ArgumentNullException(nameof(context)); this.serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); }
/// <summary> /// Initializes a new instance of the <see cref="GetObjectsQueryHandler"/> class. /// </summary> /// <param name="context">The context.</param> /// <param name="serializer">The JSON serializer.</param> public GetObjectsQueryHandler(IAmiUnitOfWork context, IDefaultJsonSerializer serializer) { this.context = context ?? throw new ArgumentNullException(nameof(context)); this.serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); }
/// <summary> /// Initializes a new instance of the <see cref="GetByIdQueryHandler"/> class. /// </summary> /// <param name="context">The context.</param> /// <param name="constants">The application constants.</param> /// <param name="serializer">The JSON serializer.</param> public GetByIdQueryHandler(IAmiUnitOfWork context, IApplicationConstants constants, IDefaultJsonSerializer serializer) { this.context = context ?? throw new ArgumentNullException(nameof(context)); this.constants = constants ?? throw new ArgumentNullException(nameof(constants)); this.serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); }
/// <summary> /// Initializes a new instance of the <see cref="CustomExceptionHandler"/> class. /// </summary> /// <param name="configuration">The configuration.</param> /// <param name="loggerFactory">The logger factory.</param> /// <param name="serializer">The serializer.</param> /// <exception cref="ArgumentNullException"> /// configuration /// or /// loggerFactory /// or /// serializer /// </exception> public CustomExceptionHandler(IAmiConfigurationManager configuration, ILoggerFactory loggerFactory, IDefaultJsonSerializer serializer) { this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); logger = loggerFactory?.CreateLogger <CustomExceptionHandler>() ?? throw new ArgumentNullException(nameof(loggerFactory)); this.serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); }