public async Task <AttemptMade> ProcessFireAt([QueueTrigger("fire-attempt", Connection = "AzureWebJobsStorage")]
                                                      FireAt fireAt,
                                                      ILogger log)
        {
            log.LogInformation($"Processed startRound: gameId={fireAt.GameId}, position={fireAt.Position}");

            var(message, blob) = await execute
                                 .Once <FireAt>(fireAt.AttemptId)
                                 .On <ShootingRangeState>(fireAt.GameId)
                                 .WithOutput(sr =>
            {
                var attemptMade = new AttemptMade
                {
                    AttemptId = fireAt.AttemptId,
                    GameId    = fireAt.GameId
                };

                if (sr.TargetPosition == fireAt.Position)
                {
                    attemptMade.IsHit = true;
                }
                else
                {
                    attemptMade.IsHit = false;
                }

                return(attemptMade, new BlobInfo {
                    BlobName = "This also a side effect"
                });
            });


            return(message);
        }
Ejemplo n.º 2
0
        public async Task <AttemptMade> ProcessFireAt(
            [QueueTrigger("fire-attempt")] FireAt fireAt,
            [ExactlyOnce(requestId: "{attemptId}", stateId: "{gameId}")] IOnceExecutor <ShootingRangeState> execute,
            ILogger log)
        {
            log.LogInformation($"Processed startRound: gameId={fireAt.GameId}, position={fireAt.Position}");

            var(message, blob) = await execute.Once(sr =>
            {
                var attemptMade = new AttemptMade
                {
                    AttemptId = fireAt.AttemptId,
                    GameId    = fireAt.GameId
                };

                if (sr.TargetPosition == fireAt.Position)
                {
                    attemptMade.IsHit = true;
                }
                else
                {
                    attemptMade.IsHit = false;
                }

                return(attemptMade, new BlobInfo {
                    BlobName = "This also a side effect"
                });
            });

            return(message);
        }
Ejemplo n.º 3
0
        public void UpdateLeaderBoard([QueueTrigger("attempt-updates", Connection = "AzureWebJobsStorage")]
                                      AttemptMade attempt, ILogger log)
        {
            log.LogInformation($"Processing attempt result: gameId={attempt.GameId}, isHit={attempt.IsHit}");

            execute.Once <AttemptMade>(attempt.AttemptId)
            .On <LeaderBoardState>(attempt.GameId, board =>
            {
                board.NumberOfAttempts++;

                if (attempt.IsHit)
                {
                    board.NumberOfHits++;
                }
            });
        }
Ejemplo n.º 4
0
        public async Task UpdateLeaderBoard(
            [QueueTrigger("attempt-updates")] AttemptMade attempt,
            [ExactlyOnce(requestId: "{attemptId}", stateId: "{gameId}")] IOnceExecutor <LeaderBoardState> execute,
            ILogger log)
        {
            log.LogWarning($"Processing attempt result: gameId={attempt.GameId}, isHit={attempt.IsHit}");

            await execute.Once(board =>
            {
                board.NumberOfAttempts++;

                if (attempt.IsHit)
                {
                    board.NumberOfHits++;
                }
            });
        }