protected override void SheduleAuctionEndTask(Auction auction, AtomicSequence <Auction> context)
        {
            if (SchedulerServiceThrows)
            {
                throw new NotImplementedException();
            }

            base.SheduleAuctionEndTask(auction, context);
        }
 protected virtual void AddToRepository_Rollback(Auction auction, AtomicSequence<Auction> context)
 {
     try
     {
         _deps.auctionRepository.RemoveAuction(auction.AggregateId);
     }
     catch (Exception e)
     {
         throw new CommandException("Cannot rollback add auction to repository", e);
     }
 }
 protected virtual void AddToRepository(Auction auction, AtomicSequence<Auction> context)
 {
     try
     {
         _deps.auctionRepository.AddAuction(auction);
     }
     catch (Exception e)
     {
         throw new CommandException("Cannot add auction to repository", e);
     }
 }
        protected override void AddToRepository(Auction auction, AtomicSequence <Auction> context)
        {
            CreateAuctionCommand_Tests.called[auction.AggregateId] = false;
            AddedAuction = auction;
            if (AuctionRepositoryThrows)
            {
                throw new NotImplementedException();
            }

            base.AddToRepository(auction, context);
        }
 protected virtual void ScheduleAuctionEndTask_Rollback(Auction auction, AtomicSequence<Auction> context)
 {
     try
     {
         var scheduledTaskId = (ScheduledTaskId) context.TransactionContext;
         _deps.auctionSchedulerService.CancelAuctionEndTask(scheduledTaskId);
     }
     catch (Exception e)
     {
         throw new CommandException("Cannot schedule auction end", e);
     }
 }
 protected virtual void SheduleAuctionEndTask(Auction auction, AtomicSequence<Auction> context)
 {
     try
     {
         var scheduledTaskId = _deps.auctionSchedulerService.ScheduleAuctionEndTask(auction)
             .Result;
         context.TransactionContext = scheduledTaskId;
     }
     catch (Exception e)
     {
         throw new CommandException("Cannot schedule auction end", e);
     }
 }
        protected override Task<RequestStatus> HandleCommand(CreateAuctionCommand request, CancellationToken cancellationToken)
        {
            var user = GetSignedInUser(request);
            var auction = request.AuctionCreateSession.CreateAuction(GetAuctionArgs(request, user.UserIdentity));

            var response = RequestStatus.CreateFromCommandContext(request.CommandContext, Status.PENDING);
            var addAuctionSequence = new AtomicSequence<Auction>()
                .AddTask(AddToRepository, AddToRepository_Rollback)
                .AddTask(SheduleAuctionEndTask, ScheduleAuctionEndTask_Rollback)
                .AddTask(ChangeImagesMetadata, ChangeImagesMetadata_Rollback)
                .AddTask((param, _) => PublishEvents(auction, user, request, response.CorrelationId), null);

            addAuctionSequence.ExecuteSequence(auction);

            return Task.FromResult(response);
        }
        protected virtual void ChangeImagesMetadata(Auction auction, AtomicSequence<Auction> context)
        {
            if (auction.AuctionImages.Count(img => img == null) == auction.AuctionImages.Count)
            {
                return;
            }

            try
            {
                _deps.auctionImageRepository.UpdateManyMetadata(auction.AuctionImages
                    .Where(image => image != null)
                    .SelectMany(img => new string[3] {img.Size1Id, img.Size2Id, img.Size3Id}.AsEnumerable())
                    .ToArray(), new AuctionImageMetadata(null)
                {
                    IsAssignedToAuction = true
                });
            }
            catch (Exception)
            {
                _deps.logger.LogError("Cannot set auction images metadata for an auction: {@auction}", auction);
                throw;
            }
        }