Ejemplo n.º 1
0
        /// <summary>
        /// Add a new node to the route network
        /// </summary>
        /// <param name="routeNodeId"></param>
        /// <param name="name"></param>
        /// <param name="nodeKind"></param>
        /// <param name="functionKind"></param>
        /// <param name="geometry"></param>
        /// <param name="locationInfo"></param>
        public void AddRouteNode(Guid routeNodeId, string name, RouteNodeKindEnum nodeKind, RouteNodeFunctionKindEnum functionKind, RouteNetwork.Events.Model.Geometry geometry, LocationInfo locationInfo)
        {
            // Id check
            if (routeNodeId == null || routeNodeId == Guid.Empty)
            {
                throw new ArgumentException("Id cannot be null or empty");
            }

            // Check that node not already exists
            if (routeNetworkState.CheckIfRouteNodeIdExists(routeNodeId))
            {
                throw new ArgumentException("A route node with id: " + routeNodeId + " already exists");
            }

            // Check that we got some valid geometry
            if (geometry == null)
            {
                throw new ArgumentException("Cannot create route node with id: " + routeNodeId + " because Geometry is null, which is not allowed.");
            }

            if (geometry.GeoJsonType == null)
            {
                throw new ArgumentException("Cannot create route node with id: " + routeNodeId + " because Geometry.GeoJsonType is null, which is not allowed.");
            }

            if (geometry.GeoJsonType.ToLower() != "point")
            {
                throw new ArgumentException("Cannot create route node with id: " + routeNodeId + " because Geometry.GeoJsonType is: " + geometry.GeoJsonType + ", which is not allowed in route nodes. Expected Point.");
            }

            if (geometry.GeoJsonCoordinates == null)
            {
                throw new ArgumentException("Cannot create route node with id: " + routeNodeId + " because Geometry.GeoJsonCoordinates is null, which is not allowed.");
            }

            // Try parse geojson
            var point = GeometryConversionHelper.ConvertFromPointGeoJson(geometry.GeoJsonCoordinates);

            // Create domain event
            var routeNodePlanned = new RouteNodePlanned()
            {
                Id               = routeNodeId,
                Name             = name,
                NodeKind         = nodeKind,
                NodeFunctionKind = functionKind,
                InitialGeometry  = geometry,
                LocationInfo     = locationInfo
            };

            RaiseEvent(routeNodePlanned, false);
        }
Ejemplo n.º 2
0
        public ConduitClosure(Guid conduitClosureId, Guid pointOfInterestId, IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkQueryService, IConduitClosureRepository conduitClosureRepository) : this()
        {
            // Id check
            if (conduitClosureId == null || conduitClosureId == Guid.Empty)
            {
                throw new ArgumentException("ConduitClosureId cannot be null or empty");
            }

            // Point of interest id check
            if (pointOfInterestId == null || pointOfInterestId == Guid.Empty)
            {
                throw new ArgumentException("PointOfInterestId cannot be null or empty");
            }

            // Check that point of interest (node) exists
            if (!routeNetworkQueryService.CheckIfRouteNodeIdExists(pointOfInterestId))
            {
                throw new ArgumentException("PointOfInterestId: " + pointOfInterestId + " not found in the route network.");
            }

            // Check that conduit closure do not already exists
            if (conduitClosureRepository.CheckIfConduitClosureAlreadyExists(conduitClosureId))
            {
                throw new ArgumentException("A conduit closure with id: " + conduitClosureId + " already exists.");
            }

            // Check that a conduit closure is not already added to point of interest. This is not allowed, each conduit closure must be placed in its own node.
            if (conduitClosureRepository.CheckIfRouteNodeContainsConduitClosure(pointOfInterestId))
            {
                throw new ArgumentException("A conduit closure: " + conduitClosureRepository.GetConduitClosureInfoByRouteNodeId(pointOfInterestId).Id + " is already placed in the specified point of interest (route node): " + pointOfInterestId + " Only one conduit closure is allowed per point of interest (route node).");
            }


            var conduitClosurePlaced = new ConduitClosurePlaced()
            {
                ConduitClosureId  = conduitClosureId,
                PointOfInterestId = pointOfInterestId
            };

            RaiseEvent(conduitClosurePlaced);
        }
        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);
        }