public async Task <Session> SignUp(string callSign, string firstName, string lastName, string password)
        {
            //TODO Validation
            try
            {
                using var dbContextScope = dbContextScopeFactory.Create();

                if (await playerRepository.Exists(callSign))
                {
                    throw new Exception();
                }

                var(passwordHash, passwordSalt) = Password.CreatePasswordHashWithSalt(password);

                var player = Player.SignUp(generator.NewReference <Player>(), callSign, firstName, lastName,
                                           passwordHash, passwordSalt);

                await playerRepository.Save(player);

                await dbContextScope.SaveChangesAsync();

                return(GetSession(player));
            }
            catch
            {
                throw new InvalidOperationException("Call sign in use.");
            }
        }
        public async Task Issue(ICommand command, DateTimeOffset?scheduledFor = null)
        {
            using var dbContextScope = dbContextScopeFactory.Create();
            await commandRepository.Save(Wrap(generator.NewReference <Message <ICommand> >(), command, scheduledFor));

            await dbContextScope.SaveChangesAsync();
        }
Esempio n. 3
0
        public async Task Publish(params IRaiseDomainEvents[] aggregates)
        {
            using var dbContextScope = dbContextScopeFactory.Create();
            foreach (var aggregate in aggregates)
            {
                foreach (var domainEvent in aggregate.Events)
                {
                    await eventRepository.Save(Event.Wrap(generator.NewReference <Message <IDomainEvent> >(),
                                                          domainEvent));
                }
            }

            await dbContextScope.SaveChangesAsync();
        }
Esempio n. 4
0
        async Task <bool> ForwardMessage <T>(Message <T> message, CancellationToken cancellationToken) where T :  IHaveType
        {
            var payload = message.Payload as IHaveType;

            var jobs = workerRegistry.GetHandlersFor(message.Payload)
                       .Select(handler => new Job(generator.NewReference <Job>(), payload.GetAddress(), handler, message.Id,
                                                  payload.GetQueueId(), message.Created))
                       .ToList();

            using (var dbContextScope = dbContextScopeFactory.Create())
            {
                await jobRepository.SaveAll(jobs);

                message.MarkAsProcessed();

                switch (message)
                {
                case Command command:
                    await commandRepository.Save(command);

                    break;

                case Event @event:
                    await eventRepository.Save(@event);

                    break;
                }

                await dbContextScope.SaveChangesAsync(cancellationToken);
            }

            foreach (var job in jobs)
            {
                jobScheduler.Add(job);
            }

            return(true);
        }
Esempio n. 5
0
 public async Task Handle(PlayerSignedUp @event, CancellationToken cancellationToken)
 {
     await commandService.Issue(new Domain.Ships.LaunchShip(generator.NewReference <Ship>(), @event.Player));
 }