コード例 #1
0
        public async Task <ICommandResult> Start(string group = "tea")
        {
            var context = await GetContextAsync().ConfigureAwait(false);

            var roomItemGroup = await _mediator.Send(new GetRoomItemGroupByNameQuery(roomId : context.Room.Id, userId : context.User.Id, name : group)).ConfigureAwait(false);

            if (roomItemGroup == null)
            {
                return(Response(ErrorStrings.StartRun_GroupInvalidName(group), ResponseType.User));
            }

            if (!roomItemGroup.Options.Any())
            {
                return(Response(ErrorStrings.StartRun_GroupNoOptions(roomItemGroup.Name), ResponseType.User));
            }

            var command = new StartRunCommand(
                id: await _idGenerator.GenerateAsync().ConfigureAwait(false),
                userId: context.User.Id,
                roomId: context.Room.Id,
                roomGroupId: roomItemGroup.Id,
                startTime: _clock.UtcNow());

            await _mediator.Send(command).ConfigureAwait(false);

            return(Response(new SlashCommandResponse
            {
                Text = ResponseStrings.RunStarted(context.Command.UserId, roomItemGroup.Name),
                Type = ResponseType.Channel,
                Attachments = AttachmentBuilder.BuildOptions(roomItemGroup.Options)
            }));
        }
コード例 #2
0
        private async Task ProcessAsync(StartRunCommand request, CancellationToken cancellationToken)
        {
            //try to create the run lock
            var created = await _lockService.CreateLockAsync(request.RoomId).ConfigureAwait(false);

            if (!created)
            {
                throw new RunStartException("There is already an active run in this room", RunStartException.RunStartExceptionReason.ExistingActiveRun);
            }

            //run lock created, so everything is ok
        }