Ejemplo n.º 1
0
        private RoadNetworkView With(AddRoadSegment command)
        {
            var attributeHash = AttributeHash.None
                                .With(command.AccessRestriction)
                                .With(command.Category)
                                .With(command.Morphology)
                                .With(command.Status)
                                .WithLeftSide(command.LeftSideStreetNameId)
                                .WithRightSide(command.RightSideStreetNameId)
                                .With(command.MaintenanceAuthority);

            return(new RoadNetworkView(
                       _nodes
                       .TryReplace(command.StartNodeId, node => node.ConnectWith(command.Id))
                       .TryReplace(command.EndNodeId, node => node.ConnectWith(command.Id)),
                       _segments.Add(command.Id,
                                     new RoadSegment(command.Id, command.Geometry, command.StartNodeId, command.EndNodeId,
                                                     attributeHash)),
                       _maximumNodeId,
                       RoadSegmentId.Max(command.Id, _maximumSegmentId),
                       _maximumGradeSeparatedJunctionId,
                       _maximumEuropeanRoadAttributeId,
                       _maximumNationalRoadAttributeId,
                       _maximumNumberedRoadAttributeId,
                       _maximumLaneAttributeId,
                       _maximumWidthAttributeId,
                       _maximumSurfaceAttributeId,
                       _segmentReusableLaneAttributeIdentifiers.AddOrMergeDistinct(command.Id, command.Lanes.Select(lane => new AttributeId(lane.Id))),
                       _segmentReusableWidthAttributeIdentifiers.AddOrMergeDistinct(command.Id, command.Widths.Select(width => new AttributeId(width.Id))),
                       _segmentReusableSurfaceAttributeIdentifiers.AddOrMergeDistinct(command.Id, command.Surfaces.Select(surface => new AttributeId(surface.Id)))
                       ));
        }
Ejemplo n.º 2
0
        private RoadNetworkView Given(Messages.RoadSegmentAdded @event)
        {
            var id    = new RoadSegmentId(@event.Id);
            var start = new RoadNodeId(@event.StartNodeId);
            var end   = new RoadNodeId(@event.EndNodeId);

            var attributeHash = AttributeHash.None
                                .With(RoadSegmentAccessRestriction.Parse(@event.AccessRestriction))
                                .With(RoadSegmentCategory.Parse(@event.Category))
                                .With(RoadSegmentMorphology.Parse(@event.Morphology))
                                .With(RoadSegmentStatus.Parse(@event.Status))
                                .WithLeftSide(@event.LeftSide.StreetNameId.HasValue
                    ? new CrabStreetnameId(@event.LeftSide.StreetNameId.Value)
                    : new CrabStreetnameId?())
                                .WithRightSide(@event.RightSide.StreetNameId.HasValue
                    ? new CrabStreetnameId(@event.RightSide.StreetNameId.Value)
                    : new CrabStreetnameId?())
                                .With(new OrganizationId(@event.MaintenanceAuthority.Code));

            var segment = new RoadSegment(
                id,
                GeometryTranslator.Translate(@event.Geometry),
                start,
                end,
                attributeHash);

            return(new RoadNetworkView(
                       _nodes
                       .TryReplace(start, node => node.ConnectWith(id))
                       .TryReplace(end, node => node.ConnectWith(id)),
                       _segments.Add(id, segment),
                       _maximumNodeId,
                       RoadSegmentId.Max(id, _maximumSegmentId),
                       _maximumGradeSeparatedJunctionId,
                       _maximumEuropeanRoadAttributeId,
                       _maximumNationalRoadAttributeId,
                       _maximumNumberedRoadAttributeId,
                       @event.Lanes.Length != 0
                    ? AttributeId.Max(
                           new AttributeId(@event.Lanes.Max(_ => _.AttributeId)),
                           _maximumLaneAttributeId)
                    : _maximumLaneAttributeId,
                       @event.Widths.Length != 0
                    ? AttributeId.Max(
                           new AttributeId(@event.Widths.Max(_ => _.AttributeId)),
                           _maximumWidthAttributeId)
                    : _maximumWidthAttributeId,
                       @event.Surfaces.Length != 0
                    ? AttributeId.Max(
                           new AttributeId(@event.Surfaces.Max(_ => _.AttributeId)),
                           _maximumSurfaceAttributeId)
                    : _maximumSurfaceAttributeId,
                       _segmentReusableLaneAttributeIdentifiers.AddOrMergeDistinct(id, @event.Lanes.Select(lane => new AttributeId(lane.AttributeId))),
                       _segmentReusableWidthAttributeIdentifiers.AddOrMergeDistinct(id, @event.Widths.Select(width => new AttributeId(width.AttributeId))),
                       _segmentReusableSurfaceAttributeIdentifiers.AddOrMergeDistinct(id, @event.Surfaces.Select(surface => new AttributeId(surface.AttributeId)))
                       ));
        }