Exemple #1
0
        private AddRoadNode Translate(Messages.AddRoadNode command)
        {
            var permanent = _nextRoadNodeId();
            var temporary = new RoadNodeId(command.TemporaryId);

            return(new AddRoadNode
                   (
                       permanent,
                       temporary,
                       RoadNodeType.Parse(command.Type),
                       GeometryTranslator.Translate(command.Geometry)
                   ));
        }
Exemple #2
0
        public Task When_road_nodes_were_imported()
        {
            var data = _fixture
                       .CreateMany <ImportedRoadNode>(new Random().Next(1, 100))
                       .Select(@event =>
            {
                var point             = BackOffice.Core.GeometryTranslator.Translate(@event.Geometry);
                var pointShapeContent = new PointShapeContent(
                    Be.Vlaanderen.Basisregisters.Shaperon.Geometries.GeometryTranslator.FromGeometryPoint(
                        new NetTopologySuite.Geometries.Point(point.X, point.Y)
                        )
                    );
                var expectedRecord = new RoadNodeRecord
                {
                    Id          = @event.Id,
                    DbaseRecord = new RoadNodeDbaseRecord
                    {
                        WK_OIDN = { Value = @event.Id },
                        WK_UIDN = { Value = @event.Id + "_" + @event.Version },
                        TYPE    = { Value = RoadNodeType.Parse(@event.Type).Translation.Identifier },
                        LBLTYPE =
                        {
                            Value = RoadNodeType.Parse(@event.Type).Translation.Name
                        },
                        BEGINTIJD = { Value = @event.Origin.Since },
                        BEGINORG  = { Value = @event.Origin.OrganizationId },
                        LBLBGNORG = { Value = @event.Origin.Organization }
                    }.ToBytes(_services.MemoryStreamManager, Encoding.UTF8),
                    ShapeRecordContent       = pointShapeContent.ToBytes(_services.MemoryStreamManager, Encoding.UTF8),
                    ShapeRecordContentLength = pointShapeContent.ContentLength.ToInt32(),
                    BoundingBox = RoadNodeBoundingBox.From(pointShapeContent.Shape)
                };

                return(new
                {
                    ImportedRoadNode = @event,
                    ExpectedRecord = expectedRecord
                });
            }).ToList();

            return(new RoadNodeRecordProjection(new RecyclableMemoryStreamManager(), Encoding.UTF8)
                   .Scenario()
                   .Given(data.Select(d => d.ImportedRoadNode))
                   .Expect(data.Select(d => d.ExpectedRecord)));
        }
        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;
                    }
                }
            });
        }