示例#1
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)))
                       ));
        }
        public Task When_road_segments_are_imported()
        {
            var random = new Random();
            var data   = _fixture
                         .CreateMany <ImportedRoadSegment>(random.Next(1, 10))
                         .Select(importedRoadSegment =>
            {
                var geometry = GeometryTranslator.Translate(importedRoadSegment.Geometry);
                var polyLineMShapeContent = new PolyLineMShapeContent(Be.Vlaanderen.Basisregisters.Shaperon.Geometries.GeometryTranslator.FromGeometryMultiLineString(geometry));

                var expected = new RoadSegmentRecord
                {
                    Id = importedRoadSegment.Id,
                    ShapeRecordContent       = polyLineMShapeContent.ToBytes(_services.MemoryStreamManager, Encoding.UTF8),
                    ShapeRecordContentLength = polyLineMShapeContent.ContentLength.ToInt32(),
                    BoundingBox = RoadSegmentBoundingBox.From(polyLineMShapeContent.Shape),
                    DbaseRecord = new RoadSegmentDbaseRecord
                    {
                        WS_OIDN   = { Value = importedRoadSegment.Id },
                        WS_UIDN   = { Value = importedRoadSegment.Id + "_" + importedRoadSegment.Version },
                        WS_GIDN   = { Value = importedRoadSegment.Id + "_" + importedRoadSegment.GeometryVersion },
                        B_WK_OIDN = { Value = importedRoadSegment.StartNodeId },
                        E_WK_OIDN = { Value = importedRoadSegment.EndNodeId },
                        STATUS    = { Value = RoadSegmentStatus.Parse(importedRoadSegment.Status).Translation.Identifier },
                        LBLSTATUS = { Value = RoadSegmentStatus.Parse(importedRoadSegment.Status).Translation.Name },
                        MORF      = { Value = RoadSegmentMorphology.Parse(importedRoadSegment.Morphology).Translation.Identifier },
                        LBLMORF   = { Value = RoadSegmentMorphology.Parse(importedRoadSegment.Morphology).Translation.Name },
                        WEGCAT    = { Value = RoadSegmentCategory.Parse(importedRoadSegment.Category).Translation.Identifier },
                        LBLWEGCAT = { Value = RoadSegmentCategory.Parse(importedRoadSegment.Category).Translation.Name },
                        LSTRNMID  = { Value = importedRoadSegment.LeftSide.StreetNameId },
                        LSTRNM    = { Value = importedRoadSegment.LeftSide.StreetName },
                        RSTRNMID  = { Value = importedRoadSegment.RightSide.StreetNameId },
                        RSTRNM    = { Value = importedRoadSegment.RightSide.StreetName },
                        BEHEER    = { Value = importedRoadSegment.MaintenanceAuthority.Code },
                        LBLBEHEER = { Value = importedRoadSegment.MaintenanceAuthority.Name },
                        METHODE   = { Value = RoadSegmentGeometryDrawMethod.Parse(importedRoadSegment.GeometryDrawMethod).Translation.Identifier },
                        LBLMETHOD = { Value = RoadSegmentGeometryDrawMethod.Parse(importedRoadSegment.GeometryDrawMethod).Translation.Name },
                        OPNDATUM  = { Value = importedRoadSegment.RecordingDate },
                        BEGINTIJD = { Value = importedRoadSegment.Origin.Since },
                        BEGINORG  = { Value = importedRoadSegment.Origin.OrganizationId },
                        LBLBGNORG = { Value = importedRoadSegment.Origin.Organization },
                        TGBEP     = { Value = RoadSegmentAccessRestriction.Parse(importedRoadSegment.AccessRestriction).Translation.Identifier },
                        LBLTGBEP  = { Value = RoadSegmentAccessRestriction.Parse(importedRoadSegment.AccessRestriction).Translation.Name }
                    }.ToBytes(_services.MemoryStreamManager, Encoding.UTF8)
                };
                return(new { importedRoadSegment, expected });
            }).ToList();

            return(new RoadRegistry.Product.Projections.RoadSegmentRecordProjection(_services.MemoryStreamManager, Encoding.UTF8)
                   .Scenario()
                   .Given(data.Select(d => d.importedRoadSegment))
                   .Expect(data.Select(d => d.expected)));
        }
示例#3
0
        public RoadSegmentRecordProjection(RecyclableMemoryStreamManager manager,
                                           Encoding encoding)
        {
            if (manager == null)
            {
                throw new ArgumentNullException(nameof(manager));
            }
            if (encoding == null)
            {
                throw new ArgumentNullException(nameof(encoding));
            }

            When <Envelope <ImportedRoadSegment> >(async(context, envelope, token) =>
            {
                var geometry =
                    GeometryTranslator.FromGeometryMultiLineString(BackOffice.Core.GeometryTranslator.Translate(envelope.Message.Geometry));
                var polyLineMShapeContent         = new PolyLineMShapeContent(geometry);
                var statusTranslation             = RoadSegmentStatus.Parse(envelope.Message.Status).Translation;
                var morphologyTranslation         = RoadSegmentMorphology.Parse(envelope.Message.Morphology).Translation;
                var categoryTranslation           = RoadSegmentCategory.Parse(envelope.Message.Category).Translation;
                var geometryDrawMethodTranslation =
                    RoadSegmentGeometryDrawMethod.Parse(envelope.Message.GeometryDrawMethod).Translation;
                var accessRestrictionTranslation =
                    RoadSegmentAccessRestriction.Parse(envelope.Message.AccessRestriction).Translation;
                await context.RoadSegments.AddAsync(
                    new RoadSegmentRecord
                {
                    Id = envelope.Message.Id,
                    ShapeRecordContent       = polyLineMShapeContent.ToBytes(manager, encoding),
                    ShapeRecordContentLength = polyLineMShapeContent.ContentLength.ToInt32(),
                    BoundingBox = RoadSegmentBoundingBox.From(polyLineMShapeContent.Shape),
                    DbaseRecord = new RoadSegmentDbaseRecord
                    {
                        WS_OIDN   = { Value = envelope.Message.Id },
                        WS_UIDN   = { Value = $"{envelope.Message.Id}_{envelope.Message.Version}" },
                        WS_GIDN   = { Value = $"{envelope.Message.Id}_{envelope.Message.GeometryVersion}" },
                        B_WK_OIDN = { Value = envelope.Message.StartNodeId },
                        E_WK_OIDN = { Value = envelope.Message.EndNodeId },
                        STATUS    = { Value = statusTranslation.Identifier },
                        LBLSTATUS = { Value = statusTranslation.Name },
                        MORF      = { Value = morphologyTranslation.Identifier },
                        LBLMORF   = { Value = morphologyTranslation.Name },
                        WEGCAT    = { Value = categoryTranslation.Identifier },
                        LBLWEGCAT = { Value = categoryTranslation.Name },
                        LSTRNMID  = { Value = envelope.Message.LeftSide.StreetNameId },
                        LSTRNM    = { Value = envelope.Message.LeftSide.StreetName },
                        RSTRNMID  = { Value = envelope.Message.RightSide.StreetNameId },
                        RSTRNM    = { Value = envelope.Message.RightSide.StreetName },
                        BEHEER    = { Value = envelope.Message.MaintenanceAuthority.Code },
                        LBLBEHEER = { Value = envelope.Message.MaintenanceAuthority.Name },
                        METHODE   = { Value = geometryDrawMethodTranslation.Identifier },
                        LBLMETHOD = { Value = geometryDrawMethodTranslation.Name },
                        OPNDATUM  = { Value = envelope.Message.RecordingDate },
                        BEGINTIJD = { Value = envelope.Message.Origin.Since },
                        BEGINORG  = { Value = envelope.Message.Origin.OrganizationId },
                        LBLBGNORG = { Value = envelope.Message.Origin.Organization },
                        TGBEP     = { Value = accessRestrictionTranslation.Identifier },
                        LBLTGBEP  = { Value = accessRestrictionTranslation.Name }
                    }.ToBytes(manager, encoding)
                },
                    token);
            });

            When <Envelope <RoadNetworkChangesBasedOnArchiveAccepted> >(async(context, envelope, token) =>
            {
                foreach (var message in envelope.Message.Changes.Flatten())
                {
                    switch (message)
                    {
                    case RoadSegmentAdded segment:
                        var geometry =
                            GeometryTranslator.FromGeometryMultiLineString(BackOffice.Core.GeometryTranslator.Translate(segment.Geometry));
                        var polyLineMShapeContent         = new PolyLineMShapeContent(geometry);
                        var statusTranslation             = RoadSegmentStatus.Parse(segment.Status).Translation;
                        var morphologyTranslation         = RoadSegmentMorphology.Parse(segment.Morphology).Translation;
                        var categoryTranslation           = RoadSegmentCategory.Parse(segment.Category).Translation;
                        var geometryDrawMethodTranslation =
                            RoadSegmentGeometryDrawMethod.Parse(segment.GeometryDrawMethod).Translation;
                        var accessRestrictionTranslation =
                            RoadSegmentAccessRestriction.Parse(segment.AccessRestriction).Translation;
                        await context.RoadSegments.AddAsync(
                            new RoadSegmentRecord
                        {
                            Id = segment.Id,
                            ShapeRecordContent       = polyLineMShapeContent.ToBytes(manager, encoding),
                            ShapeRecordContentLength = polyLineMShapeContent.ContentLength.ToInt32(),
                            BoundingBox = RoadSegmentBoundingBox.From(polyLineMShapeContent.Shape),
                            DbaseRecord = new RoadSegmentDbaseRecord
                            {
                                WS_OIDN   = { Value = segment.Id },
                                WS_UIDN   = { Value = $"{segment.Id}_{segment.Version}" },
                                WS_GIDN   = { Value = $"{segment.Id}_{segment.GeometryVersion}" },
                                B_WK_OIDN = { Value = segment.StartNodeId },
                                E_WK_OIDN = { Value = segment.EndNodeId },
                                STATUS    = { Value = statusTranslation.Identifier },
                                LBLSTATUS = { Value = statusTranslation.Name },
                                MORF      = { Value = morphologyTranslation.Identifier },
                                LBLMORF   = { Value = morphologyTranslation.Name },
                                WEGCAT    = { Value = categoryTranslation.Identifier },
                                LBLWEGCAT = { Value = categoryTranslation.Name },
                                LSTRNMID  = { Value = segment.LeftSide.StreetNameId },
                                // TODO: Where does this come from?
                                LSTRNM   = { Value = null },
                                RSTRNMID = { Value = segment.RightSide.StreetNameId },
                                // TODO: Where does this come from?
                                RSTRNM    = { Value = null },
                                BEHEER    = { Value = segment.MaintenanceAuthority.Code },
                                LBLBEHEER = { Value = segment.MaintenanceAuthority.Name },
                                METHODE   = { Value = geometryDrawMethodTranslation.Identifier },
                                LBLMETHOD = { Value = geometryDrawMethodTranslation.Name },
                                OPNDATUM  = { Value = LocalDateTimeTranslator.TranslateFromWhen(envelope.Message.When) },
                                BEGINTIJD = { Value = LocalDateTimeTranslator.TranslateFromWhen(envelope.Message.When) },
                                BEGINORG  = { Value = envelope.Message.OrganizationId },
                                LBLBGNORG = { Value = envelope.Message.Organization },
                                TGBEP     = { Value = accessRestrictionTranslation.Identifier },
                                LBLTGBEP  = { Value = accessRestrictionTranslation.Name }
                            }.ToBytes(manager, encoding)
                        },
                            token);
                        break;
                    }
                }
            });
        }
示例#4
0
        private AddRoadSegment Translate(Messages.AddRoadSegment command, IRequestedChangeIdentityTranslator translator)
        {
            var permanent = _nextRoadSegmentId();
            var temporary = new RoadSegmentId(command.TemporaryId);

            var        startNodeId = new RoadNodeId(command.StartNodeId);
            RoadNodeId?temporaryStartNodeId;

            if (translator.TryTranslateToPermanent(startNodeId, out var permanentStartNodeId))
            {
                temporaryStartNodeId = startNodeId;
                startNodeId          = permanentStartNodeId;
            }
            else
            {
                temporaryStartNodeId = null;
            }

            var        endNodeId = new RoadNodeId(command.EndNodeId);
            RoadNodeId?temporaryEndNodeId;

            if (translator.TryTranslateToPermanent(endNodeId, out var permanentEndNodeId))
            {
                temporaryEndNodeId = endNodeId;
                endNodeId          = permanentEndNodeId;
            }
            else
            {
                temporaryEndNodeId = null;
            }

            var geometry             = GeometryTranslator.Translate(command.Geometry);
            var maintainer           = new OrganizationId(command.MaintenanceAuthority);
            var geometryDrawMethod   = RoadSegmentGeometryDrawMethod.Parse(command.GeometryDrawMethod);
            var morphology           = RoadSegmentMorphology.Parse(command.Morphology);
            var status               = RoadSegmentStatus.Parse(command.Status);
            var category             = RoadSegmentCategory.Parse(command.Category);
            var accessRestriction    = RoadSegmentAccessRestriction.Parse(command.AccessRestriction);
            var leftSideStreetNameId = command.LeftSideStreetNameId.HasValue
                ? new CrabStreetnameId(command.LeftSideStreetNameId.Value)
                : new CrabStreetnameId?();
            var rightSideStreetNameId = command.RightSideStreetNameId.HasValue
                ? new CrabStreetnameId(command.RightSideStreetNameId.Value)
                : new CrabStreetnameId?();
            var nextLaneAttributeId = _nextRoadSegmentLaneAttributeId(permanent);
            var laneAttributes      = Array.ConvertAll(
                command.Lanes,
                item => new RoadSegmentLaneAttribute(
                    nextLaneAttributeId(),
                    new AttributeId(item.AttributeId),
                    new RoadSegmentLaneCount(item.Count),
                    RoadSegmentLaneDirection.Parse(item.Direction),
                    new RoadSegmentPosition(item.FromPosition),
                    new RoadSegmentPosition(item.ToPosition),
                    new GeometryVersion(0)
                    )
                );
            var nextWidthAttributeId = _nextRoadSegmentWidthAttributeId(permanent);
            var widthAttributes      = Array.ConvertAll(
                command.Widths,
                item => new RoadSegmentWidthAttribute(
                    nextWidthAttributeId(),
                    new AttributeId(item.AttributeId),
                    new RoadSegmentWidth(item.Width),
                    new RoadSegmentPosition(item.FromPosition),
                    new RoadSegmentPosition(item.ToPosition),
                    new GeometryVersion(0)
                    )
                );
            var nextSurfaceAttributeId = _nextRoadSegmentSurfaceAttributeId(permanent);
            var surfaceAttributes      = Array.ConvertAll(
                command.Surfaces,
                item => new RoadSegmentSurfaceAttribute(
                    nextSurfaceAttributeId(),
                    new AttributeId(item.AttributeId),
                    RoadSegmentSurfaceType.Parse(item.Type),
                    new RoadSegmentPosition(item.FromPosition),
                    new RoadSegmentPosition(item.ToPosition),
                    new GeometryVersion(0)
                    )
                );

            return(new AddRoadSegment
                   (
                       permanent,
                       temporary,
                       startNodeId,
                       temporaryStartNodeId,
                       endNodeId,
                       temporaryEndNodeId,
                       geometry,
                       maintainer,
                       geometryDrawMethod,
                       morphology,
                       status,
                       category,
                       accessRestriction,
                       leftSideStreetNameId,
                       rightSideStreetNameId,
                       laneAttributes,
                       widthAttributes,
                       surfaceAttributes
                   ));
        }