public async Task Handle(T message)
        {
            DataContext.PushCurrent(lookup.Get(localDbName));
            await inner.Handle(message);

            DataContext.PopCurrent();
        }
Esempio n. 2
0
        public async Task <IHttpActionResult> ScanFolderForShows(List <string> foldersToScan)
        {
            ScanShows scanShows = new ScanShows()
            {
                FoldersToScan = foldersToScan
            };

            return(Ok(await _handler.Handle(scanShows)));
        }
Esempio n. 3
0
        public async Task <IHttpActionResult> ScanFolderForMovies([FromUri] List <string> foldersToScan)
        {
            ScanMovies scanMovies = new ScanMovies()
            {
                FoldersToScan = foldersToScan
            };

            return(Ok(await _handler.Handle(scanMovies)));
        }
Esempio n. 4
0
        public async Task <IHttpActionResult> UpdateStudent()
        {
            await _updateStudent.Handle(new UpdateStudentCommand {
                Id        = 2,
                FirstName = "Judge",
                LastName  = "Dredd"
            });

            return(Ok());
        }
Esempio n. 5
0
        public async Task Handle(TCommand command, CancellationToken cancellationToken = default)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            command.EnsureIsValid();

            await asyncCommandHandler.Handle(command, cancellationToken).ConfigureAwait(false);
        }
Esempio n. 6
0
        public async Task <IHttpActionResult> CreateStudent()
        {
            var command = new CreateStudentCommand {
                FirstName = "Check",
                LastName  = "This"
            };

            await _createStudent.Handle(command);

            // retunr the new student id from the command
            return(Ok(command.Id));
        }
Esempio n. 7
0
        public async Task <TCommandResult> Handle <TCommand, TCommandResult>(TCommand command)
            where TCommand : ICommand
            where TCommandResult : ICommandResult, new()
        {
            bool async = false;

            IAsyncCommandHandler <TCommand, TCommandResult> asyncHandler = null;
            ICommandHandler <TCommand, TCommandResult>      handler      = _serviceProvider.GetService(typeof(ICommandHandler <TCommand, TCommandResult>)) as ICommandHandler <TCommand, TCommandResult>;

            if (handler == null)
            {
                async        = true;
                asyncHandler = _serviceProvider.GetService(typeof(IAsyncCommandHandler <TCommand, TCommandResult>)) as IAsyncCommandHandler <TCommand, TCommandResult>;
            }

            if (handler == null && asyncHandler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }

            TCommandResult result = new TCommandResult();

            try
            {
                _logService.Log <ICommandHandler <TCommand, TCommandResult> >(nameof(EOperations.Input), nameof(handler.Handle), new { Input = command }, LogLevel.Debug);

                result = async ? await asyncHandler.Handle(command) : handler.Handle(command);

                if (result == null)
                {
                    result = new TCommandResult();

                    IReadOnlyDictionary <string, IReadOnlyCollection <INotificationMessage> > notifications = async ? asyncHandler.Notifications : handler.Notifications;

                    if (notifications.Count > 0)
                    {
                        result.Populate(InvalidHandlerDefaultCode, notifications);
                    }
                }
            }
            catch (Exception exception)
            {
                _logService.Log <ICommandHandler <TCommand, TCommandResult> >(exception, new { Input = command }, LogLevel.Error);
            }
            finally
            {
                _logService.Log <ICommandHandler <TCommand, TCommandResult> >(nameof(EOperations.Output), nameof(handler.Handle), new { Output = result }, LogLevel.Debug);
            }

            return(result);
        }
Esempio n. 8
0
 public Task <EnableUserResponse> Enable([FromRoute] EnableUserCommand query)
 {
     return(_enableUserCommandHandler.Handle(query));
 }
Esempio n. 9
0
 public Task <DisableUserResponse> Disable([FromRoute] DisableUserCommand query)
 {
     return(_disableUserCommandHandler.Handle(query));
 }
Esempio n. 10
0
 public async Task <DeleteMealResponse> Delete([FromRoute] DeleteMealCommand command)
 {
     return(await _deleteMealCommandHandler.Handle(command));
 }
Esempio n. 11
0
 public Task <DeleteUserMealsReponse> Get([FromBody] DeleteUserMealsCommand command)
 {
     return(_deleteUserMeals.Handle(command));
 }
Esempio n. 12
0
        public async Task Handle(TCommand command)
        {
            await _decorated.Handle(command);

            await _uow.SaveChangesAsync();
        }
Esempio n. 13
0
        public async Task <IHttpActionResult> DeleteStudent(int id)
        {
            await _deleteStudent.Handle(new DeleteStudentCommand { Id = id });

            return(Ok());
        }
Esempio n. 14
0
 public Task <EditProductResponse> Edit([FromBody] EditProductCommand command)
 {
     return(_editProductCommandHandler.Handle(command));
 }
Esempio n. 15
0
 public Task <AddProductResponse> Add([FromBody] AddProductCommand command)
 {
     return(_addProductCommandHandler.Handle(command));
 }
Esempio n. 16
0
 public Task <RegisterUserResponse> Register(RegisterUserCommand command)
 {
     return(_registerUserCommandHandler.Handle(command));
 }
Esempio n. 17
0
 public Task <LoginUserResponse> Login(LoginUserCommand command)
 {
     return(_loginUserCommandHandler.Handle(command));
 }
        public async Task <IHttpActionResult> PostAsync(CommitSynchronisation toPost)
        {
            await commandHandler.Handle(new CommitSynchronisableCommits { Synchronisation = toPost });

            return(Ok());
        }
Esempio n. 19
0
 public Task <AddUserMealResponse> Add([FromBody] AddUserMealCommand command)
 {
     command.UserId = User.Claims.First(c => c.Type == "UserID").Value;
     return(_addUserMealCommandHandler.Handle(command));
 }
Esempio n. 20
0
 public Task <AddMealResponse> Add([FromBody] AddMealCommand command)
 {
     return(_addMealCommandHandler.Handle(command));
 }
 public async Task Handle(TCommand command, CancellationToken cancellationToken = default)
 {
     await CreateAsyncPolicy()
     .ExecuteAsync(async() => await asyncCommandHandler.Handle(command, cancellationToken));
 }
Esempio n. 22
0
 public async Task <EditMealResponse> Edit([FromBody] EditMealCommand command)
 {
     return(await _editMealCommandHandler.Handle(command));
 }