private async Task MarkToBeDeleted(object message, string errorMessage)
        {
            if (message is RouteSegmentMessage)
            {
                var routeSegmentMessage = (RouteSegmentMessage)message;

                // We get this to check if it is deleted it is deleted if it is null
                var shadowTableSegment = await _geoDatabase.GetRouteSegmentShadowTable(routeSegmentMessage.After.Mrid);

                if (!routeSegmentMessage.After.MarkAsDeleted || shadowTableSegment != null)
                {
                    _logger.LogError($"RouteSegement with id {routeSegmentMessage.After.Mrid}, error message: {errorMessage}");
                    await _geoDatabase.MarkDeleteRouteSegment(routeSegmentMessage.After.Mrid);
                }
            }
            else if (message is RouteNodeMessage)
            {
                var routeNodeMessage = (RouteNodeMessage)message;

                // We get this to check if it is deleted it is deleted if it is null
                var shadowTableNode = await _geoDatabase.GetRouteNodeShadowTable(routeNodeMessage.After.Mrid);

                if (!routeNodeMessage.After.MarkAsDeleted || shadowTableNode != null)
                {
                    _logger.LogError($"RouteNode with id {routeNodeMessage.After.Mrid}, error message: {errorMessage}");
                    await _geoDatabase.MarkDeleteRouteNode(routeNodeMessage.After.Mrid);
                }
            }
            else
            {
                throw new Exception($"Message of type '{message.GetType()}' is not supported.");
            }
        }
        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);
        }
示例#3
0
        public async Task <IEnumerable <INotification> > Create(RouteSegment before, RouteSegment after)
        {
            var notifications = new List <INotification>();

            if (before is null || after is null)
            {
                notifications.Add(new DoNothing($"Before or after route node is null, cannot update info."));
                return(notifications);
            }

            var routeSegmentShadowTable = await _geoDatabase.GetRouteSegmentShadowTable(after.Mrid, true);

            if (routeSegmentShadowTable is null)
            {
                notifications.Add(
                    new DoNothing(
                        $"Could not find {nameof(RouteSegment)} in shadowtable with id '{after.Mrid}'"));
                return(notifications);
            }

            if (AlreadyUpdated(after, routeSegmentShadowTable))
            {
                notifications.Add(
                    new DoNothing(
                        $"{nameof(RouteSegment)} with id '{after.Mrid}' is already updated, therefore do nothing."));
                return(notifications);
            }

            if (routeSegmentShadowTable.MarkAsDeleted)
            {
                notifications.Add(
                    new DoNothing(
                        $"Shadowtable {nameof(RouteSegment)} with id '{after.Mrid}' is marked to be deleted, info cannot be updated."));
                return(notifications);
            }

            if (IsRouteSegmentInfoModified(before, after))
            {
                notifications.Add(new RouteSegmentInfoUpdated(after));
            }

            if (IsLifecycleInfoModified(before, after))
            {
                notifications.Add(new RouteSegmentLifecycleInfoUpdated(after));
            }

            if (IsMappingInfoModified(before, after))
            {
                notifications.Add(new RouteSegmentMappingInfoUpdated(after));
            }

            if (IsNamingInfoModified(before, after))
            {
                notifications.Add(new RouteSegmentNamingInfoUpdated(after));
            }

            if (IsSafetyInfoModified(before, after))
            {
                notifications.Add(new RouteSegmentSafetyInfoUpdated(after));
            }

            if (notifications.Any())
            {
                await _geoDatabase.UpdateRouteSegmentInfosShadowTable(after);
            }

            return(notifications);
        }