예제 #1
0
        public async Task <List <INotification> > CreateDigitizedEvent(RouteNode routeNode)
        {
            if (routeNode is null)
            {
                throw new ArgumentNullException($"Parameter {nameof(routeNode)} cannot be null");
            }

            if (IsCreatedByApplication(routeNode))
            {
                return new List <INotification> {
                           new DoNothing($"{nameof(RouteNode)} with id: '{routeNode.Mrid}' was created by {routeNode.ApplicationName} therefore do nothing.")
                }
            }
            ;

            await _geoDatabase.InsertRouteNodeShadowTable(routeNode);

            var intersectingRouteSegments = await _geoDatabase.GetIntersectingRouteSegments(routeNode);

            var intersectingRouteNodes = await _geoDatabase.GetIntersectingRouteNodes(routeNode);

            if (intersectingRouteNodes.Count > 0)
            {
                return(new List <INotification> {
                    new InvalidRouteNodeOperation {
                        RouteNode = routeNode, Message = "RouteNode intersects with another RouteNode"
                    }
                });
            }

            if (intersectingRouteSegments.Count == 0)
            {
                return new List <INotification> {
                           new NewRouteNodeDigitized {
                               RouteNode = routeNode
                           }
                }
            }
            ;

            if (intersectingRouteSegments.Count == 1)
            {
                var notifications = new List <INotification>();

                notifications.Add(new ExistingRouteSegmentSplitted
                {
                    RouteNode            = routeNode,
                    InsertNode           = false,
                    CreateNodeAddedEvent = true
                });

                return(notifications);
            }

            return(new List <INotification> {
                new InvalidRouteNodeOperation {
                    RouteNode = routeNode, Message = "Route node did not fit any condition in command factory."
                }
            });
        }