Exemple #1
0
        protected async Task HandleCommand <TCommand>(TCommand command, Func <TAggregateRoot, TCommand, IEnumerable <Event <TAggregateIdentity> > > handler, Func <IEnumerable <Event <TAggregateIdentity> >, Task> dispatchEvents) where TCommand : Command <TAggregateIdentity>
        {
            var isAlreadyProcessed = await _idempotencyCheck.IsProcessed(command.Id).ConfigureAwait(false);

            if (isAlreadyProcessed)
            {
                return;
            }

            var aggregateRoot = await _aggregateRepository
                                .GetById <TAggregateRoot, TAggregateIdentity>(command.AggregateIdentity).ConfigureAwait(false);

            var events = handler(aggregateRoot, command);

            foreach (var @event in events)
            {
                aggregateRoot.PlayEvent(@event, true);
            }

            await _aggregateRepository.Store <TAggregateRoot, TAggregateIdentity>(aggregateRoot).ConfigureAwait(false);

            await dispatchEvents(events).ConfigureAwait(false);

            await _idempotencyCheck.MarkProcessed(command.Id).ConfigureAwait(false);
        }
Exemple #2
0
        public Task <Unit> Handle(PlaceMultiConduitCommand request, CancellationToken cancellationToken)
        {
            var multiConduit = new MultiConduit(request.MultiConduitId, request.WalkOfInterestId, request.ConduitSpecificationId, request.Name, request.MarkingColor, request.MarkingText, conduitNetworkQueryService, conduitSpecificationRepository, request.DemoDataSpec);

            repo.Store(multiConduit);

            return(Unit.Task);
        }
Exemple #3
0
        public Task <Unit> Handle(PlaceConduitClosureCommand request, CancellationToken cancellationToken)
        {
            // Check if aggregate id has been used
            if (repo.CheckIfAggregateIdHasBeenUsed(request.ConduitClosureId))
            {
                throw new ArgumentException("The uuid: " + request.ConduitClosureId + " has allready been used. This is an event sourced system, so you're not allowed to reuse object uuids.");
            }

            var conduitClosure = new ConduitClosure(request.ConduitClosureId, request.PointOfInterestId, routeNetworkQueryService, conduitNetworkQueryService, conduitClosureRepository);

            repo.Store(conduitClosure);

            return(Unit.Task);
        }
Exemple #4
0
        public Task <Unit> Handle(PlaceFiberCableCommand request, CancellationToken cancellationToken)
        {
            var fiberCable = new FiberCable(request.FiberCableId, request.WalkOfInterestId, request.NumberOfFibers, request.Name, fiberNetworkQueryService);

            repo.Store(fiberCable);

            return(Unit.Task);
        }
        public Task <Unit> Handle(AddNodeCommand request, CancellationToken cancellationToken)
        {
            routeNetworkAggregate.AddRouteNode(request.Id, request.Name, request.NodeKind, request.NodeFunctionKind, request.Geometry, request.LocationInfo);
            repo.Store(routeNetworkAggregate);

            /*
             * // Id check
             * if (request.Id == null || request.Id == Guid.Empty)
             *  throw new ArgumentException("Id cannot be null or empty");
             *
             * // Check that not already exists
             * if (routeQueryService.CheckIfRouteNodeIdExists(request.Id))
             * {
             *  throw new ArgumentException("A route node with id: " + request.Id + " already exists");
             * }
             *
             * var routeNode = new RouteNode(request.Id, request.Name, request.NodeKind, request.NodeFunctionKind, request.Geometry, request.LocationInfo);
             *
             *
             * repo.Store(routeNode);
             */

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

            // Basic check that some route element ids are filled in at all
            if (request.RouteElementIds == null || request.RouteElementIds.Count < 3)
            {
                throw new ArgumentException("The route element id list is empty or has less than 3 ids, which cannot possible be a valid walk. A minumum walk is from one node, through a segment, to another node (node->segment->node) - i.e. 3 ids.");
            }

            // Check if the chain of route element ids are valid (is proper connected to each other in the route network graph)
            bool         shouldBeNode      = true;
            bool         firstElement      = true;
            GraphElement previousElement   = null;
            Guid         previousElementId = Guid.Empty;

            int position = 1;

            foreach (var routeElementId in request.RouteElementIds)
            {
                GraphElement currentElement = null;

                // Node
                if (shouldBeNode)
                {
                    if (!routeQueryService.CheckIfRouteNodeIdExists(routeElementId))
                    {
                        throw new ArgumentException("Route element id: " + routeElementId + " at position: " + position + " (in the route element ids property) is expected to be a node. But no node could be found with that id.");
                    }

                    currentElement = routeQueryService.GetRouteNodeInfo(routeElementId);

                    shouldBeNode = false;
                }

                // Segment
                else if (!shouldBeNode)
                {
                    if (!routeQueryService.CheckIfRouteSegmentIdExists(routeElementId))
                    {
                        throw new ArgumentException("Route element id: " + routeElementId + " at position: " + position + " (in the route element ids property) is expected to be a segment. But no segment could be found with that id.");
                    }

                    currentElement = routeQueryService.GetRouteSegmentInfo(routeElementId);

                    shouldBeNode = true;
                }

                // Check that the element is connected to the previous specified element in the route network graph
                if (!firstElement)
                {
                    if (!currentElement.NeighborElements.Exists(n => n == previousElement))
                    {
                        throw new ArgumentException("Route element id: " + routeElementId + " at position: " + position + " (in the route element ids property) is not neighboor to previous id: " + previousElementId + " according to the route network graph. Please check that the walk is valid.");
                    }
                }

                position++;
                firstElement      = false;
                previousElementId = routeElementId;
                previousElement   = currentElement;
            }

            // Check if first id is a node
            if (!(routeQueryService.GetRouteElementInfo(request.RouteElementIds[0]) is RouteNodeInfo))
            {
                throw new ArgumentException("First route element id (in the route element ids property) must be a node, but it's not.");
            }

            // Check if last id is a node
            if (!(routeQueryService.GetRouteElementInfo(request.RouteElementIds[request.RouteElementIds.Count - 1]) is RouteNodeInfo))
            {
                throw new ArgumentException("Last route element id (in the route element ids property) must be a node, but it's not.");
            }


            var walkOfInterest = new WalkOfInterest(request.WalkOfInterestId, request.RouteElementIds);

            repo.Store(walkOfInterest);

            return(Unit.Task);
        }