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);
        }
        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.GetObject(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.GetObject(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 envelope = GeoJsonConversionHelper.ConvertFromLineGeoJson(request.Geometry).Envelope.EnvelopeInternal;

            transaction.Add(new RouteSegment(request.SegmentId, fromNode, toNode, envelope), ignoreDublicates: true);
        }
예제 #3
0
        private bool CheckSegmentAddedEventProperties(RouteSegmentAdded routeSegmentAddedEvent, RouteSegmentRecord sourceSegment)
        {
            var allTestsOk = true;

            if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.Id, routeSegmentAddedEvent.SegmentId, "SegmentId"))
            {
                allTestsOk = false;
            }

            // Check route segment info
            if (!TestPropertyValueNoEquals(routeSegmentAddedEvent, sourceSegment.RouteSegmentInfo, routeSegmentAddedEvent.RouteSegmentInfo, "RouteSegmentInfo"))
            {
                allTestsOk = false;
            }
            else if (routeSegmentAddedEvent.RouteSegmentInfo != null)
            {
                if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.RouteSegmentInfo.Kind, routeSegmentAddedEvent.RouteSegmentInfo.Kind, "RouteSegmentInfo.Kind"))
                {
                    allTestsOk = false;
                }

                if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.RouteSegmentInfo.Width, routeSegmentAddedEvent.RouteSegmentInfo.Width, "RouteSegmentInfo.Width"))
                {
                    allTestsOk = false;
                }

                if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.RouteSegmentInfo.Height, routeSegmentAddedEvent.RouteSegmentInfo.Height, "RouteSegmentInfo.Height"))
                {
                    allTestsOk = false;
                }
            }

            // Check from node id
            if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.StartNode.Id, routeSegmentAddedEvent.FromNodeId, "FromNodeId"))
            {
                allTestsOk = false;
            }

            // Check to node id
            if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.EndNode.Id, routeSegmentAddedEvent.ToNodeId, "ToNodeId"))
            {
                allTestsOk = false;
            }


            // general

            // Check event type
            if (!TestPropertyValue(routeSegmentAddedEvent, "RouteSegmentAdded", routeSegmentAddedEvent.EventType, "EventType"))
            {
                allTestsOk = false;
            }

            // Check command type
            if (!TestPropertyValue(routeSegmentAddedEvent, "NewRouteSegmentDigitized", routeSegmentAddedEvent.CmdType, "CmdType"))
            {
                allTestsOk = false;
            }

            // Check IsLastEventInCmd
            if (!TestPropertyValue(routeSegmentAddedEvent, true, routeSegmentAddedEvent.IsLastEventInCmd, "IsLastEventInCmd"))
            {
                allTestsOk = false;
            }

            // Check event id uniqueness
            if (!TestIfIdNotAlreadyUsed(routeSegmentAddedEvent, routeSegmentAddedEvent.EventId, _ids, "EventId"))
            {
                allTestsOk = false;
            }

            // Check cmd id uniqueness
            if (!TestIfIdNotAlreadyUsed(routeSegmentAddedEvent, routeSegmentAddedEvent.CmdId, _ids, "CmdId"))
            {
                allTestsOk = false;
            }

            if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.ApplicationName, routeSegmentAddedEvent.ApplicationName, "ApplicationName"))
            {
                allTestsOk = false;
            }

            if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.ApplicationInfo, routeSegmentAddedEvent.ApplicationInfo, "ApplicationInfo"))
            {
                allTestsOk = false;
            }

            if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.Username, routeSegmentAddedEvent.UserName, "UserName"))
            {
                allTestsOk = false;
            }

            if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.WorkTaskMrid, routeSegmentAddedEvent.WorkTaskMrid, "WorkTaskMrid"))
            {
                allTestsOk = false;
            }


            // Check naming info
            if (!TestPropertyValueNoEquals(routeSegmentAddedEvent, sourceSegment.NamingInfo, routeSegmentAddedEvent.NamingInfo, "NamingInfo"))
            {
                allTestsOk = false;
            }
            else if (routeSegmentAddedEvent.NamingInfo != null)
            {
                if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.NamingInfo.Name, routeSegmentAddedEvent.NamingInfo.Name, "NamingInfo.Name"))
                {
                    allTestsOk = false;
                }

                if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.NamingInfo.Description, routeSegmentAddedEvent.NamingInfo.Description, "NamingInfo.Description"))
                {
                    allTestsOk = false;
                }
            }


            // Check mapping info
            if (!TestPropertyValueNoEquals(routeSegmentAddedEvent, sourceSegment.MappingInfo, routeSegmentAddedEvent.MappingInfo, "MappingInfo"))
            {
                allTestsOk = false;
            }
            else if (routeSegmentAddedEvent.MappingInfo != null)
            {
                if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.MappingInfo.Method, routeSegmentAddedEvent.MappingInfo.Method, "MappingInfo.Method"))
                {
                    allTestsOk = false;
                }

                if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.MappingInfo.HorizontalAccuracy, routeSegmentAddedEvent.MappingInfo.HorizontalAccuracy, "MappingInfo.HorizontalAccuracy"))
                {
                    allTestsOk = false;
                }

                if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.MappingInfo.VerticalAccuracy, routeSegmentAddedEvent.MappingInfo.VerticalAccuracy, "MappingInfo.VerticalAccuracy"))
                {
                    allTestsOk = false;
                }

                if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.MappingInfo.SurveyDate, routeSegmentAddedEvent.MappingInfo.SurveyDate, "MappingInfo.SurveyDate"))
                {
                    allTestsOk = false;
                }

                if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.MappingInfo.SourceInfo, routeSegmentAddedEvent.MappingInfo.SourceInfo, "MappingInfo.SourceInfo"))
                {
                    allTestsOk = false;
                }
            }

            // Check lifecycle info
            if (!TestPropertyValueNoEquals(routeSegmentAddedEvent, sourceSegment.LifecycleInfo, routeSegmentAddedEvent.LifecyleInfo, "LifecycleInfo"))
            {
                allTestsOk = false;
            }
            else if (routeSegmentAddedEvent.LifecyleInfo != null)
            {
                if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.LifecycleInfo.DeploymentState, routeSegmentAddedEvent.LifecyleInfo.DeploymentState, "LifecycleInfo.DeploymentState"))
                {
                    allTestsOk = false;
                }

                if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.LifecycleInfo.InstallationDate, routeSegmentAddedEvent.LifecyleInfo.InstallationDate, "LifecycleInfo.InstallationDate"))
                {
                    allTestsOk = false;
                }

                if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.LifecycleInfo.RemovalDate, routeSegmentAddedEvent.LifecyleInfo.RemovalDate, "LifecycleInfo.RemovalDate"))
                {
                    allTestsOk = false;
                }
            }

            // Check safety info
            if (!TestPropertyValueNoEquals(routeSegmentAddedEvent, sourceSegment.SafetyInfo, routeSegmentAddedEvent.SafetyInfo, "SafetyInfo"))
            {
                allTestsOk = false;
            }
            else if (routeSegmentAddedEvent.SafetyInfo != null)
            {
                if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.SafetyInfo.Classification, routeSegmentAddedEvent.SafetyInfo.Classification, "SafetyInfo.Classification"))
                {
                    allTestsOk = false;
                }

                if (!TestPropertyValue(routeSegmentAddedEvent, sourceSegment.SafetyInfo.Remark, routeSegmentAddedEvent.SafetyInfo.Remark, "SafetyInfo.Remark"))
                {
                    allTestsOk = false;
                }
            }

            return(allTestsOk);
        }
        private RouteNetworkElementIdList CreateNewRouteNetworkElementIdListFromSplit(RouteNetworkElementIdList existingRouteNetworkElementIds, Guid removedSegmentId, Guid newNodeId, RouteSegmentAdded newFromSegmentEvent, RouteSegmentAdded newToSegmentEvent)
        {
            RouteNetworkElementIdList result = new RouteNetworkElementIdList();

            for (int i = 0; i < existingRouteNetworkElementIds.Count; i++)
            {
                var existingId = existingRouteNetworkElementIds[i];

                if (existingId == removedSegmentId)
                {
                    // Check if the from segment is the one connected to the from node of the removed segment in the walk
                    if (newFromSegmentEvent.FromNodeId == existingRouteNetworkElementIds[i - 1] || newFromSegmentEvent.ToNodeId == existingRouteNetworkElementIds[i - 1])
                    {
                        // The from segment is comming first
                        result.Add(newFromSegmentEvent.SegmentId);
                        result.Add(newNodeId);
                        result.Add(newToSegmentEvent.SegmentId);
                    }
                    else
                    {
                        // The to segment is comming first
                        result.Add(newToSegmentEvent.SegmentId);
                        result.Add(newNodeId);
                        result.Add(newFromSegmentEvent.SegmentId);
                    }
                }
                else
                {
                    result.Add(existingId);
                }
            }

            var walk = new ValidatedRouteNetworkWalk(result);

            return(walk.RouteNetworkElementRefs);
        }