示例#1
0
        private async Task <bool> IsValidNodeUpdate(RouteNode before, RouteNode after)
        {
            var startRouteSegment = await _geoDatabase.GetIntersectingStartRouteSegments(before);

            var endRouteSegment = await _geoDatabase.GetIntersectingEndRouteSegments(before);

            var intersectingRouteNodes = await _geoDatabase.GetIntersectingRouteNodes(after);

            if (((startRouteSegment.Count + endRouteSegment.Count) > 0 && after.MarkAsDeleted) || intersectingRouteNodes.Count > 0)
            {
                return(false);
            }

            return(true);
        }
示例#2
0
        private async Task <bool> IsRouteNodeDeleteable(RouteNode routeNode)
        {
            var hasRelatedEquipment = true;

            try
            {
                hasRelatedEquipment = await _validationService.HasRelatedEquipment(routeNode.Mrid);
            }
            catch
            {
                _logger.LogWarning($"Could not reach validation service, so we do not delete the RouteNode with mrid '{routeNode.Mrid}'");
            }

            var intersectingStartRouteSegments = await _geoDatabase.GetIntersectingStartRouteSegments(routeNode);

            var intersectingEndRouteSegments = await _geoDatabase.GetIntersectingEndRouteSegments(routeNode);

            var intersectingRouteSegmentsCount = intersectingStartRouteSegments.Count + intersectingEndRouteSegments.Count;

            return(routeNode.RouteNodeInfo?.Kind == null &&
                   String.IsNullOrEmpty(routeNode.NamingInfo?.Name) &&
                   intersectingRouteSegmentsCount == 0 &&
                   !hasRelatedEquipment);
        }
        public async Task <IEnumerable <INotification> > CreateUpdatedEvent(RouteSegment before, RouteSegment after)
        {
            var routeSegmentShadowTableBeforeUpdate = await _geoDatabase.GetRouteSegmentShadowTable(after.Mrid);

            if (routeSegmentShadowTableBeforeUpdate is null)
            {
                return new List <INotification> {
                           new DoNothing($"{nameof(RouteSegment)} is already deleted, therefore do nothing")
                }
            }
            ;

            if (AlreadyUpdated(after, routeSegmentShadowTableBeforeUpdate))
            {
                return new List <INotification> {
                           new DoNothing($"{nameof(RouteSegment)} is already updated, therefore do nothing.")
                }
            }
            ;

            if (!_routeSegmentValidator.LineIsValid(after.GetLineString()))
            {
                throw new Exception("Linestring is not valid.");
            }

            await _geoDatabase.UpdateRouteSegmentShadowTable(after);

            if (after.MarkAsDeleted)
            {
                return new List <INotification> {
                           CreateRouteSegmentDeleted(after)
                }
            }
            ;

            var intersectingStartSegments = await _geoDatabase.GetIntersectingStartRouteSegments(after);

            var intersectingEndSegments = await _geoDatabase.GetIntersectingEndRouteSegments(after);

            var intersectingStartNodes = await _geoDatabase.GetIntersectingStartRouteNodes(after);

            var intersectingEndNodes = await _geoDatabase.GetIntersectingEndRouteNodes(after);

            var allIntersectingRouteNodesNoEdges = await _geoDatabase.GetAllIntersectingRouteNodesNotIncludingEdges(after);

            if (intersectingStartNodes.Count >= 2 || intersectingEndNodes.Count >= 2)
            {
                throw new Exception("Has more than 2 intersecting start or end nodes.");
            }

            if (await IsGeometryChanged(intersectingStartNodes.FirstOrDefault(), intersectingEndNodes.FirstOrDefault(), routeSegmentShadowTableBeforeUpdate))
            {
                var events = new List <INotification>();
                events.Add(new RouteSegmentLocationChanged {
                    RouteSegment = after
                });

                if (allIntersectingRouteNodesNoEdges.Count > 0)
                {
                    foreach (var intersectingRouteNode in allIntersectingRouteNodesNoEdges)
                    {
                        var routeSegmentSplitted = CreateExistingRouteSegmentSplitted(null, intersectingRouteNode, false);
                        events.Add(routeSegmentSplitted);
                    }
                }

                return(events);
            }

            var notifications = new List <INotification>();

            notifications.AddRange(HandleExistingRouteSegmentSplitted(intersectingStartSegments.Count, intersectingStartNodes.Count, after.FindStartPoint(), after));
            notifications.AddRange(HandleExistingRouteSegmentSplitted(intersectingEndSegments.Count, intersectingEndNodes.Count, after.FindEndPoint(), after));

            notifications.Add(new RouteSegmentConnectivityChanged(before, after));

            return(notifications);
        }