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.");
            }
        }
Beispiel #2
0
        public async Task <IEnumerable <INotification> > Create(RouteNode before, RouteNode 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 routeNodeShadowTable = await _geoDatabase.GetRouteNodeShadowTable(after.Mrid, true);

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

            if (AlreadyUpdated(after, routeNodeShadowTable))
            {
                notifications.Add(
                    new DoNothing($"{nameof(RouteNode)} with id '{after.Mrid}' is already updated"));
                return(notifications);
            }

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

            if (IsRouteNodeInfoUpdated(before, after))
            {
                notifications.Add(new RouteNodeInfoUpdated(after));
            }

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

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

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

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

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

            return(notifications);
        }
Beispiel #3
0
        public async Task <List <INotification> > CreateUpdatedEvent(RouteNode before, RouteNode after)
        {
            if (before is null || after is null)
            {
                throw new ArgumentNullException($"Parameter {nameof(before)} or {nameof(after)} cannot be null");
            }

            var shadowTableNode = await _geoDatabase.GetRouteNodeShadowTable(after.Mrid);

            if (shadowTableNode is null)
            {
                return new List <INotification> {
                           new DoNothing($"{nameof(RouteNode)} is already deleted, so do nothing.")
                }
            }
            ;

            if (AlreadyUpdated(after, shadowTableNode))
            {
                return new List <INotification> {
                           new DoNothing($"{nameof(RouteNode)} with id: '{after.Mrid}' was already updated therefore do nothing.")
                }
            }
            ;

            await _geoDatabase.UpdateRouteNodeShadowTable(after);

            if (!(await IsValidNodeUpdate(before, after)))
            {
                return new List <INotification> {
                           new RollbackInvalidRouteNode(before, "Is not a valid route node update")
                }
            }
            ;

            // We roll back in-case the update-command intersects with new route-segments
            var intersectingRouteSegments = await _geoDatabase.GetIntersectingRouteSegments(after);

            if (intersectingRouteSegments.Count > 0)
            {
                var previousIntersectingRouteSegments = await _geoDatabase.GetIntersectingRouteSegments(before.Coord);

                var newIntersectingRouteSegments = intersectingRouteSegments
                                                   .Where(x => !previousIntersectingRouteSegments.Any(y => y.Mrid == x.Mrid)).ToList();
                if (newIntersectingRouteSegments.Count > 0)
                {
                    return new List <INotification> {
                               new RollbackInvalidRouteNode(before, "Update to route node is invalid because it is insecting with route-segments.")
                    }
                }
                ;
            }

            if (after.MarkAsDeleted)
            {
                return new List <INotification> {
                           new RouteNodeDeleted {
                               RouteNode = after
                           }
                }
            }
            ;

            return(new List <INotification> {
                new RouteNodeLocationChanged {
                    RouteNodeAfter = after, RouteNodeBefore = before
                }
            });
        }