Example #1
0
        public Task Handle(Mint command, IMessageContext context)
        {
            if (Data.IdempotencyToken == command.IdempotencyToken)
            {
                return(CompletedTask);
            }

            var @event    = new MintRequested(command.AggregateId, command.CatalogId, command.IdempotencyToken);
            var commands  = new List <StartMintJob>();
            var jobId     = 1;
            var start     = 1L;
            var remaining = command.Quantity;

            for ( ; start <= command.Quantity; start += MintBatchSize, remaining -= MintBatchSize, jobId++)
            {
                var count        = Min(remaining, MintBatchSize);
                var mintJob      = new MintJob(jobId, command.CatalogId, start, count);
                var startMintJob = new StartMintJob(@event.AggregateId,
                                                    jobId - 1,
                                                    mintJob.Id,
                                                    mintJob.CatalogId,
                                                    mintJob.StartOfSequence,
                                                    mintJob.Count);

                @event.MintJobs.Add(mintJob);
                commands.Add(startMintJob);
            }

            Record(@event);
            return(context.Send(commands));
        }
Example #2
0
        void Apply(MintRequested @event)
        {
            Data.Id               = @event.AggregateId;
            Data.State            = Started;
            Data.CatalogId        = @event.CatalogId;
            Data.IdempotencyToken = @event.IdempotencyToken;

            foreach (var mintJob in @event.MintJobs)
            {
                Data.MintJobs.Add(mintJob);
            }
        }