Esempio n. 1
0
        public Task When_adding_grade_separated_junctions()
        {
            var message         = _fixture.Create <BackOffice.Messages.RoadNetworkChangesBasedOnArchiveAccepted>();
            var expectedRecords = Array.ConvertAll(message.Changes, change =>
            {
                var junction = change.GradeSeparatedJunctionAdded;
                return((object)new GradeSeparatedJunctionRecord
                {
                    Id = junction.Id,
                    DbaseRecord = new GradeSeparatedJunctionDbaseRecord
                    {
                        OK_OIDN = { Value = junction.Id },
                        TYPE = { Value = GradeSeparatedJunctionType.Parse(junction.Type).Translation.Identifier },
                        LBLTYPE = { Value = GradeSeparatedJunctionType.Parse(junction.Type).Translation.Name },
                        BO_WS_OIDN = { Value = junction.UpperRoadSegmentId },
                        ON_WS_OIDN = { Value = junction.LowerRoadSegmentId },
                        BEGINTIJD = { Value = LocalDateTimeTranslator.TranslateFromWhen(message.When) },
                        BEGINORG = { Value = message.OrganizationId },
                        LBLBGNORG = { Value = message.Organization }
                    }.ToBytes(_services.MemoryStreamManager, Encoding.UTF8)
                });
            });

            return(new GradeSeparatedJunctionRecordProjection(_services.MemoryStreamManager, Encoding.UTF8)
                   .Scenario()
                   .Given(message)
                   .Expect(expectedRecords));
        }
        public RoadNodeRecordProjection(RecyclableMemoryStreamManager manager, Encoding encoding)
        {
            if (manager == null)
            {
                throw new ArgumentNullException(nameof(manager));
            }
            if (encoding == null)
            {
                throw new ArgumentNullException(nameof(encoding));
            }

            When <Envelope <ImportedRoadNode> >(async(context, envelope, token) =>
            {
                var typeTranslation = RoadNodeType.Parse(envelope.Message.Type).Translation;
                var dbaseRecord     = new RoadNodeDbaseRecord
                {
                    WK_OIDN   = { Value = envelope.Message.Id },
                    WK_UIDN   = { Value = envelope.Message.Id + "_" + envelope.Message.Version },
                    TYPE      = { Value = typeTranslation.Identifier },
                    LBLTYPE   = { Value = typeTranslation.Name },
                    BEGINTIJD = { Value = envelope.Message.Origin.Since },
                    BEGINORG  = { Value = envelope.Message.Origin.OrganizationId },
                    LBLBGNORG = { Value = envelope.Message.Origin.Organization }
                };

                var point             = GeometryTranslator.FromGeometryPoint(BackOffice.Core.GeometryTranslator.Translate(envelope.Message.Geometry));
                var pointShapeContent = new PointShapeContent(point);

                await context.RoadNodes.AddAsync(new RoadNodeRecord
                {
                    Id = envelope.Message.Id,
                    ShapeRecordContent       = pointShapeContent.ToBytes(manager, encoding),
                    ShapeRecordContentLength = pointShapeContent.ContentLength.ToInt32(),
                    DbaseRecord = dbaseRecord.ToBytes(manager, encoding),
                    BoundingBox = RoadNodeBoundingBox.From(pointShapeContent.Shape)
                }, token);
            });

            When <Envelope <RoadNetworkChangesBasedOnArchiveAccepted> >(async(context, envelope, token) =>
            {
                foreach (var message in envelope.Message.Changes.Flatten())
                {
                    switch (message)
                    {
                    case RoadNodeAdded node:
                        var typeTranslation = RoadNodeType.Parse(node.Type).Translation;
                        var dbaseRecord     = new RoadNodeDbaseRecord
                        {
                            WK_OIDN   = { Value = node.Id },
                            WK_UIDN   = { Value = node.Id + "_0" },  // 1?
                            TYPE      = { Value = typeTranslation.Identifier },
                            LBLTYPE   = { Value = typeTranslation.Name },
                            BEGINTIJD = { Value = LocalDateTimeTranslator.TranslateFromWhen(envelope.Message.When) },
                            BEGINORG  = { Value = envelope.Message.OrganizationId },
                            LBLBGNORG = { Value = envelope.Message.Organization }
                        };

                        var point             = GeometryTranslator.FromGeometryPoint(BackOffice.Core.GeometryTranslator.Translate(node.Geometry));
                        var pointShapeContent = new PointShapeContent(point);

                        await context.RoadNodes.AddAsync(new RoadNodeRecord
                        {
                            Id = node.Id,
                            ShapeRecordContent       = pointShapeContent.ToBytes(manager, encoding),
                            ShapeRecordContentLength = pointShapeContent.ContentLength.ToInt32(),
                            DbaseRecord = dbaseRecord.ToBytes(manager, encoding),
                            BoundingBox = RoadNodeBoundingBox.From(pointShapeContent.Shape)
                        }, token);
                        break;
                    }
                }
            });
        }
Esempio n. 3
0
        public RoadSegmentSurfaceAttributeRecordProjection(RecyclableMemoryStreamManager manager,
                                                           Encoding encoding)
        {
            if (manager == null)
            {
                throw new ArgumentNullException(nameof(manager));
            }
            if (encoding == null)
            {
                throw new ArgumentNullException(nameof(encoding));
            }
            When <Envelope <ImportedRoadSegment> >((context, envelope, token) =>
            {
                if (envelope.Message.Surfaces.Length == 0)
                {
                    return(Task.CompletedTask);
                }

                var surfaces = envelope.Message
                               .Surfaces
                               .Select(surface =>
                {
                    var typeTranslation = RoadSegmentSurfaceType.Parse(surface.Type).Translation;
                    return(new RoadSegmentSurfaceAttributeRecord
                    {
                        Id = surface.AttributeId,
                        RoadSegmentId = envelope.Message.Id,
                        DbaseRecord = new RoadSegmentSurfaceAttributeDbaseRecord
                        {
                            WV_OIDN = { Value = surface.AttributeId },
                            WS_OIDN = { Value = envelope.Message.Id },
                            WS_GIDN = { Value = $"{envelope.Message.Id}_{surface.AsOfGeometryVersion}" },
                            TYPE = { Value = typeTranslation.Identifier },
                            LBLTYPE = { Value = typeTranslation.Name },
                            VANPOS = { Value = (double)surface.FromPosition },
                            TOTPOS = { Value = (double)surface.ToPosition },
                            BEGINTIJD = { Value = surface.Origin.Since },
                            BEGINORG = { Value = surface.Origin.OrganizationId },
                            LBLBGNORG = { Value = surface.Origin.Organization },
                        }.ToBytes(manager, encoding)
                    });
                });

                return(context.RoadSegmentSurfaceAttributes.AddRangeAsync(surfaces, token));
            });

            When <Envelope <RoadNetworkChangesBasedOnArchiveAccepted> >(async(context, envelope, token) =>
            {
                foreach (var change in envelope.Message.Changes.Flatten())
                {
                    switch (change)
                    {
                    case RoadSegmentAdded segment:
                        if (segment.Surfaces.Length != 0)
                        {
                            var surfaces = segment
                                           .Surfaces
                                           .Select(surface =>
                            {
                                var typeTranslation = RoadSegmentSurfaceType.Parse(surface.Type).Translation;
                                return(new RoadSegmentSurfaceAttributeRecord
                                {
                                    Id = surface.AttributeId,
                                    RoadSegmentId = segment.Id,
                                    DbaseRecord = new RoadSegmentSurfaceAttributeDbaseRecord
                                    {
                                        WV_OIDN = { Value = surface.AttributeId },
                                        WS_OIDN = { Value = segment.Id },
                                        WS_GIDN = { Value = $"{segment.Id}_{surface.AsOfGeometryVersion}" },
                                        TYPE = { Value = typeTranslation.Identifier },
                                        LBLTYPE = { Value = typeTranslation.Name },
                                        VANPOS = { Value = (double)surface.FromPosition },
                                        TOTPOS = { Value = (double)surface.ToPosition },
                                        BEGINTIJD = { Value = LocalDateTimeTranslator.TranslateFromWhen(envelope.Message.When) },
                                        BEGINORG = { Value = envelope.Message.OrganizationId },
                                        LBLBGNORG = { Value = envelope.Message.Organization }
                                    }.ToBytes(manager, encoding)
                                });
                            });

                            await context.RoadSegmentSurfaceAttributes.AddRangeAsync(surfaces);
                        }

//                        case RoadSegmentModified segment:
//                            if (segment.Surfaces.Length == 0)
//                            {
//                                context.RoadSegmentSurfaceAttributes.RemoveRange(
//                                    context
//                                        .RoadSegmentSurfaceAttributes
//                                        .Local.Where(a => a.RoadSegmentId == segment.Id)
//                                        .Concat(await context
//                                            .RoadSegmentSurfaceAttributes
//                                            .Where(a => a.RoadSegmentId == segment.Id)
//                                            .ToArrayAsync(token)
//                                        ));
//                            }
//                            else
//                            {
//                                var currentSet = context
//                                    .RoadSegmentSurfaceAttributes
//                                    .Local.Where(a => a.RoadSegmentId == segment.Id)
//                                    .Concat(await context
//                                        .RoadSegmentSurfaceAttributes
//                                        .Where(a => a.RoadSegmentId == segment.Id)
//                                        .ToArrayAsync(token)
//                                    ).ToDictionary(a => a.Id);
//                                var nextSet = segment
//                                    .Surfaces
//                                    .Select(surface =>
//                                    {
//                                        var typeTranslation = RoadSegmentSurfaceType.Parse(surface.Type).Translation;
//                                        return new RoadSegmentSurfaceAttributeRecord
//                                        {
//                                            Id = surface.AttributeId,
//                                            RoadSegmentId = segment.Id,
//                                            DbaseRecord = new RoadSegmentSurfaceAttributeDbaseRecord
//                                            {
//                                                WV_OIDN = {Value = surface.AttributeId},
//                                                WS_OIDN = {Value = segment.Id},
//                                                WS_GIDN = {Value = $"{segment.Id}_{surface.AsOfGeometryVersion}"},
//                                                TYPE = {Value = typeTranslation.Identifier},
//                                                LBLTYPE = {Value = typeTranslation.Name},
//                                                VANPOS = {Value = (double) surface.FromPosition},
//                                                TOTPOS = {Value = (double) surface.ToPosition},
//                                                // TODO: This should come from the event
//                                                BEGINTIJD = {Value = null},
//                                                BEGINORG = {Value = null},
//                                                LBLBGNORG = {Value = null}
//                                            }.ToBytes(manager, encoding)
//                                        };
//                                    })
//                                    .ToDictionary(a => a.Id);
//                                context.RoadSegmentSurfaceAttributes.Synchronize(currentSet, nextSet, (current, next) =>
//                                    {
//                                        current.DbaseRecord = next.DbaseRecord;
//                                    });
//                            }
                        break;
                    }
                }
            });
        }
Esempio n. 4
0
        public GradeSeparatedJunctionRecordProjection(RecyclableMemoryStreamManager manager, Encoding encoding)
        {
            if (manager == null)
            {
                throw new ArgumentNullException(nameof(manager));
            }
            if (encoding == null)
            {
                throw new ArgumentNullException(nameof(encoding));
            }

            When <Envelope <ImportedGradeSeparatedJunction> >(async(context, envelope, token) =>
            {
                var translation    = GradeSeparatedJunctionType.Parse(envelope.Message.Type).Translation;
                var junctionRecord = new GradeSeparatedJunctionRecord
                {
                    Id          = envelope.Message.Id,
                    DbaseRecord = new GradeSeparatedJunctionDbaseRecord
                    {
                        OK_OIDN    = { Value = envelope.Message.Id },
                        TYPE       = { Value = translation.Identifier },
                        LBLTYPE    = { Value = translation.Name },
                        BO_WS_OIDN = { Value = envelope.Message.UpperRoadSegmentId },
                        ON_WS_OIDN = { Value = envelope.Message.LowerRoadSegmentId },
                        BEGINTIJD  = { Value = envelope.Message.Origin.Since },
                        BEGINORG   = { Value = envelope.Message.Origin.OrganizationId },
                        LBLBGNORG  = { Value = envelope.Message.Origin.Organization },
                    }.ToBytes(manager, encoding)
                };

                await context.AddAsync(junctionRecord, token);
            });

            When <Envelope <RoadNetworkChangesBasedOnArchiveAccepted> >(async(context, envelope, token) =>
            {
                foreach (var change in envelope.Message.Changes.Flatten())
                {
                    switch (change)
                    {
                    case GradeSeparatedJunctionAdded junction:
                        var translation    = GradeSeparatedJunctionType.Parse(junction.Type).Translation;
                        var junctionRecord = new GradeSeparatedJunctionRecord
                        {
                            Id          = junction.Id,
                            DbaseRecord = new GradeSeparatedJunctionDbaseRecord
                            {
                                OK_OIDN    = { Value = junction.Id },
                                TYPE       = { Value = translation.Identifier },
                                LBLTYPE    = { Value = translation.Name },
                                BO_WS_OIDN = { Value = junction.UpperRoadSegmentId },
                                ON_WS_OIDN = { Value = junction.LowerRoadSegmentId },
                                BEGINTIJD  =
                                {
                                    Value = LocalDateTimeTranslator.TranslateFromWhen(envelope.Message.When)
                                },
                                BEGINORG  = { Value = envelope.Message.OrganizationId },
                                LBLBGNORG = { Value = envelope.Message.Organization },
                            }.ToBytes(manager, encoding)
                        };

                        await context.AddAsync(junctionRecord, token);
                        break;
                    }
                }
            });
        }
        public RoadSegmentNationalRoadAttributeRecordProjection(RecyclableMemoryStreamManager manager,
                                                                Encoding encoding)
        {
            if (manager == null)
            {
                throw new ArgumentNullException(nameof(manager));
            }
            if (encoding == null)
            {
                throw new ArgumentNullException(nameof(encoding));
            }

            When <Envelope <ImportedRoadSegment> >((context, envelope, token) =>
            {
                if (envelope.Message.PartOfNationalRoads.Length == 0)
                {
                    return(Task.CompletedTask);
                }


                var nationalRoadAttributes = envelope.Message
                                             .PartOfNationalRoads
                                             .Select(nationalRoad => new RoadSegmentNationalRoadAttributeRecord
                {
                    Id            = nationalRoad.AttributeId,
                    RoadSegmentId = envelope.Message.Id,
                    DbaseRecord   = new RoadSegmentNationalRoadAttributeDbaseRecord
                    {
                        NW_OIDN   = { Value = nationalRoad.AttributeId },
                        WS_OIDN   = { Value = envelope.Message.Id },
                        IDENT2    = { Value = nationalRoad.Ident2 },
                        BEGINTIJD = { Value = nationalRoad.Origin.Since },
                        BEGINORG  = { Value = nationalRoad.Origin.OrganizationId },
                        LBLBGNORG = { Value = nationalRoad.Origin.Organization },
                    }.ToBytes(manager, encoding)
                });

                return(context.RoadSegmentNationalRoadAttributes.AddRangeAsync(nationalRoadAttributes, token));
            });

            When <Envelope <RoadNetworkChangesBasedOnArchiveAccepted> >(async(context, envelope, token) =>
            {
                foreach (var change in envelope.Message.Changes.Flatten())
                {
                    switch (change)
                    {
                    case RoadSegmentAddedToNationalRoad nationalRoad:
                        await context.RoadSegmentNationalRoadAttributes.AddAsync(new RoadSegmentNationalRoadAttributeRecord
                        {
                            Id            = nationalRoad.AttributeId,
                            RoadSegmentId = nationalRoad.SegmentId,
                            DbaseRecord   = new RoadSegmentNationalRoadAttributeDbaseRecord
                            {
                                NW_OIDN   = { Value = nationalRoad.AttributeId },
                                WS_OIDN   = { Value = nationalRoad.SegmentId },
                                IDENT2    = { Value = nationalRoad.Ident2 },
                                BEGINTIJD = { Value = LocalDateTimeTranslator.TranslateFromWhen(envelope.Message.When) },
                                BEGINORG  = { Value = envelope.Message.OrganizationId },
                                LBLBGNORG = { Value = envelope.Message.Organization }
                            }.ToBytes(manager, encoding)
                        });
                        break;
                    }
                }
            });
        }
        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;
                    }
                }
            });
        }