private void HandleEvent(RouteSegmentAdded request, ITransaction transaction)
        {
            _logger.LogDebug($"Handler got {request.GetType().Name} event seq no: {request.EventSequenceNumber}");

            if (AlreadyProcessed(request.EventId))
            {
                return;
            }


            if (!(_networkState.GetRouteNetworkElement(request.FromNodeId) is RouteNode fromNode))
            {
                _logger.LogError($"Route network event stream seems to be broken! RouteSegmentAdded event with id: {request.EventId} and segment id: {request.SegmentId} has a FromNodeId: {request.FromNodeId} that don't exists in the current state.");
                return;
            }


            if (!(_networkState.GetRouteNetworkElement(request.ToNodeId) is RouteNode toNode))
            {
                _logger.LogError($"Route network event stream seems to be broken! RouteSegmentAdded event with id: {request.EventId} and segment id: {request.SegmentId} has a ToNodeId: {request.ToNodeId} that don't exists in the current state.");
                return;
            }

            var routeSegment = new RouteSegment(request.SegmentId, request.Geometry, fromNode, toNode)
            {
                RouteSegmentInfo = request.RouteSegmentInfo,
                NamingInfo       = request.NamingInfo,
                MappingInfo      = request.MappingInfo,
                LifecycleInfo    = request.LifecyleInfo,
                SafetyInfo       = request.SafetyInfo
            };

            transaction.Add(routeSegment, ignoreDublicates: true);
        }
Ejemplo n.º 2
0
        public Result <List <IRouteNetworkElement> > GetRouteElements(RouteNetworkElementIdList routeNetworkElementIds, bool createSubstitudesForMissingRouteNetworkElements = false)
        {
            var routeNetworkElementFetched = new List <IRouteNetworkElement>();

            foreach (var routeElementId in routeNetworkElementIds)
            {
                var routeNetworkElement = _routeNetworkState.GetRouteNetworkElement(routeElementId);

                if (routeNetworkElement == null)
                {
                    if (createSubstitudesForMissingRouteNetworkElements)
                    {
                        routeNetworkElement = new RouteNode(routeElementId, "[559000,6210000]")
                        {
                            NamingInfo = new NamingInfo()
                            {
                                Name = "#NA"
                            }
                        };
                    }
                    else
                    {
                        return(Result.Fail <List <IRouteNetworkElement> >($"Cannot find any route network element with id: {routeElementId}"));
                    }
                }

                routeNetworkElementFetched.Add(routeNetworkElement as IRouteNetworkElement);
            }

            return(Result.Ok <List <IRouteNetworkElement> >(routeNetworkElementFetched));
        }