Ejemplo n.º 1
0
        public async void HandleXX(CreateSchemaCommand command)
        {
            Guid gSchemaId     = new Guid("42E5B6A3-0B76-4FE7-B780-71935086B8ED");
            var  storedSchemaX = await _repository.Load <Schema>(gSchemaId, Int32.MaxValue);

            if (storedSchemaX == null)
            {
                Console.WriteLine("Item is not found. Create a new one.");
            }

            var schema = new Schema(gSchemaId); // = _repository.LoadNew<Schema>();

            schema.AddProperty("A");
            schema.AddProperty("BC");
            await _repository.Save(schema);


            // query event store for events
            var storedSchema = await _repository.Load <Schema>(gSchemaId, Int32.MaxValue);

            if (storedSchema == null)
            {
                Console.WriteLine("Item STILL not found.");
            }
            else
            {
                storedSchema.AddProperty("CD");
                await _repository.Save(storedSchema);
            }
        }
Ejemplo n.º 2
0
        public async Task <Either <Error, Nothing> > Handle(CancellationToken cancelationToken, NonEmptyGuid id, Action <TAggregate> whatToDo)
        {
            var aggregate = await _aggregateStore.Load <TAggregate>(id, cancelationToken);

            whatToDo(aggregate);

            await _aggregateStore.Save(aggregate, cancelationToken);

            return(Nothing.Instance);
        }
Ejemplo n.º 3
0
        public Task <Unit> Handle(CutInnerConduitCommand request, CancellationToken cancellationToken)
        {
            // Id check
            if (request.InnerConduitId == null && request.MultiConduitId == null)
            {
                throw new ArgumentException("Either InnerConduitId or MultiConduitId + InnerConduitSequenceNumber must be provided.");
            }


            if (request.MultiConduitId == null || request.MultiConduitId == Guid.Empty)
            {
                var conduitRelations = conduitNetworkQueryService.GetConduitSegmentsRelatedToPointOfInterest(request.PointOfInterestId);

                if (!conduitRelations.Any(c => c.Segment.Line.Id == request.InnerConduitId))
                {
                    throw new ArgumentException("Cannot find inner conduit with id: " + request.InnerConduitId + " in point of interest: " + request.PointOfInterestId);
                }

                var innerConduitSegment = conduitRelations.Find(c => c.Segment.Line.Id == request.InnerConduitId);

                request.MultiConduitId             = ((ConduitInfo)innerConduitSegment.Segment.Line).GetRootConduit().Id;
                request.InnerConduitSequenceNumber = innerConduitSegment.Segment.Line.SequenceNumber;
            }


            var multiConduit = repo.Load <MultiConduit>(request.MultiConduitId);

            multiConduit.CutInnerConduit(request.InnerConduitSequenceNumber, request.PointOfInterestId, routeNetworkQueryService, conduitNetworkQueryService);
            repo.Store(multiConduit);

            return(Unit.Task);
        }
        public Task <Unit> Handle(CutSingleConduitCommand request, CancellationToken cancellationToken)
        {
            // Id check
            if (request.SingleConduitId == null || request.SingleConduitId == Guid.Empty)
            {
                throw new ArgumentException("MultiConduitId cannot be null or empty");
            }


            var singleConduit = repo.Load <SingleConduit>(request.SingleConduitId);

            singleConduit.Cut(request.PointOfInterestId, routeNetworkQueryService, conduitNetworkQueryService);
            repo.Store(singleConduit);

            return(Unit.Task);
        }
Ejemplo n.º 5
0
        public Task <Unit> Handle(RemoveConduitClosureCommand request, CancellationToken cancellationToken)
        {
            // Id check
            if (request.ConduitClosureId == null || request.ConduitClosureId == Guid.Empty)
            {
                throw new ArgumentException("ConduitClosureId cannot be null or empty");
            }

            var conduitClosure = repo.Load <ConduitClosure>(request.ConduitClosureId);

            conduitClosure.Remove();

            repo.Store(conduitClosure);

            return(Unit.Task);
        }
Ejemplo n.º 6
0
        public void Handle(RemoveProductFromCart removeProductFromCart)
        {
            var cart = _repository.Load <ShoppingCart>(removeProductFromCart.CartId);

            cart.RemoveProduct(removeProductFromCart.ProductId);

            _repository.SaveChanges(cart);
        }
        public void Handle(AddProductToCart message)
        {
            var cart = _repository.Load <ShoppingCart>(message.CartId);

            cart.AddProduct(message.ProductId);

            _repository.SaveChanges(cart);
        }
Ejemplo n.º 8
0
        private static async Task CancelOrder(IAggregateRepository repository, ILogger log, OrderPlaced @event)
        {
            var order = await repository.Load <Order>(@event.OrderId);

            log.LogInformation("The customer cancelled");
            if (order != null)
            {
                order.Cancel("Customer requested cancellation");
                await repository.Save(order);
            }
        }
Ejemplo n.º 9
0
        private static async Task ProvisionOrder(IAggregateRepository repository, ILogger log, OrderPlaced @event)
        {
            log.LogInformation("The cooldown expired");
            var order = await repository.Load <Order>(@event.OrderId);

            // order is ready to go, cooling period expired
            if (order != null)
            {
                order.Provision();
                await repository.Save(order);
            }
        }
        /// <summary>
        /// Executes an action to an existing AR. Use this method only if you are 100% sure that the AR must exist.
        /// If the AR does not exists the method throws an exception.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="update"></param>
        public virtual void Update(IAggregateRootId id, Action <AR> update)
        {
            ReadResult <AR> result = repository.Load <AR>(id);

            if (result.IsSuccess)
            {
                update(result.Data);
                repository.Save(result.Data);
            }
            else
            {
                throw new Exception($"Failed to load an aggregate. {result}");
            }
        }
Ejemplo n.º 11
0
 public async Task <TAggregateRoot> Load(TId aggregateId, bool throwIfNotFound = true)
 {
     return(await repository.Load(aggregateId, throwIfNotFound));
 }
Ejemplo n.º 12
0
 public ReadResult <AR> Load <AR>(IAggregateRootId id) where AR : IAggregateRoot
 {
     return(aggregateRepository.Load <AR>(id));
 }
 public AR Load <AR>(IAggregateRootId id) where AR : IAggregateRoot
 {
     return(aggregateRepository.Load <AR>(id));
 }