Beispiel #1
0
        public ValidatedRouteNetworkWalk Reverse()
        {
            var newRouteNetworkElementRefs = new RouteNetworkElementIdList();

            for (int i = 0; i < this.RouteNetworkElementRefs.Count; i++)
            {
                newRouteNetworkElementRefs.Add(RouteNetworkElementRefs[RouteNetworkElementRefs.Count - (i + 1)]);
            }

            return(new ValidatedRouteNetworkWalk(newRouteNetworkElementRefs));
        }
        private async void NotifyExternalServicesAboutSpanEquipmentChange(Guid spanEquipmentId, ValidatedRouteNetworkWalk existingWalk, ValidatedRouteNetworkWalk newWalk)
        {
            var routeIdsAffected = new RouteNetworkElementIdList();

            foreach (var id in existingWalk.RouteNetworkElementRefs)
            {
                routeIdsAffected.Add(id);
            }

            foreach (var id in newWalk.RouteNetworkElementRefs)
            {
                if (!routeIdsAffected.Contains(id))
                {
                    routeIdsAffected.Add(id);
                }
            }

            List <IdChangeSet> idChangeSets = new List <IdChangeSet>
            {
                new IdChangeSet("SpanEquipment", ChangeTypeEnum.Modification, new Guid[] { spanEquipmentId })
            };

            var updatedEvent =
                new RouteNetworkElementContainedEquipmentUpdated(
                    eventType: typeof(RouteNetworkElementContainedEquipmentUpdated).Name,
                    eventId: Guid.NewGuid(),
                    eventTimestamp: DateTime.UtcNow,
                    applicationName: "UtilityNetworkService",
                    applicationInfo: null,
                    category: "EquipmentModification.Moved",
                    idChangeSets: idChangeSets.ToArray(),
                    affectedRouteNetworkElementIds: routeIdsAffected.ToArray()
                    );

            await _externalEventProducer.Produce(_topicName, updatedEvent);
        }
Beispiel #3
0
        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);
            RouteNetworkElementIdList segmentsOnly = new();

            segmentsOnly.AddRange(walk.SegmentIds);
            return(segmentsOnly);
        }
        private RouteNetworkElementIdList CreateWalkFromSegmentSequence(List <RouteSegment> routeSegments, long versionId)
        {
            RouteNetworkElementIdList walkIds = new RouteNetworkElementIdList();

            var routeSegmentPosition = 0;

            // If only one route segment, inV and outV will be the node sequence
            if (routeSegments.Count == 1)
            {
                walkIds.Add(routeSegments[0].InV(versionId).Id);
                walkIds.Add(routeSegments[0].Id);
                walkIds.Add(routeSegments[0].OutV(versionId).Id);

                return(walkIds);
            }

            // We're dealing with multi segments, if we reach this code
            foreach (var routeSegment in routeSegments)
            {
                if (routeSegmentPosition > 0)
                {
                    var prevSegment = routeSegments[routeSegmentPosition - 1];

                    var sharedRouteNode = FindSharedNode(prevSegment, routeSegment, versionId);

                    // If prevSegment is the first segment then remember to add it incl. the first node and shared node
                    if (routeSegmentPosition == 1)
                    {
                        if (prevSegment.InV(versionId) != sharedRouteNode)
                        {
                            walkIds.Add(prevSegment.InV(versionId).Id);
                        }
                        else
                        {
                            walkIds.Add(prevSegment.OutV(versionId).Id);
                        }

                        // Add prev segment
                        walkIds.Add(prevSegment.Id);

                        // Add shared node
                        walkIds.Add(sharedRouteNode.Id);
                    }

                    // Add current segment and non shared node
                    walkIds.Add(routeSegment.Id);

                    if (routeSegment.InV(versionId) != sharedRouteNode)
                    {
                        walkIds.Add(routeSegment.InV(versionId).Id);
                    }
                    else
                    {
                        walkIds.Add(routeSegment.OutV(versionId).Id);
                    }
                }

                routeSegmentPosition++;
            }

            return(walkIds);
        }