public RoadSegmentLaneAttribute( AttributeId temporaryId, RoadSegmentLaneCount count, RoadSegmentLaneDirection direction, RoadSegmentPosition from, RoadSegmentPosition to ) : base(temporaryId, from, to) { Count = count; Direction = direction; }
public RoadSegmentLaneAttribute( AttributeId id, AttributeId temporaryId, RoadSegmentLaneCount count, RoadSegmentLaneDirection direction, RoadSegmentPosition from, RoadSegmentPosition to, GeometryVersion asOfGeometryVersion ) : base(id, temporaryId, from, to, asOfGeometryVersion) { Count = count; Direction = direction; }
public Task When_importing_road_nodes() { var random = new Random(); var data = _fixture .CreateMany <ImportedRoadSegment>(random.Next(1, 10)) .Select(segment => { segment.Lanes = _fixture .CreateMany <ImportedRoadSegmentLaneAttributes>(random.Next(1, 10)) .ToArray(); var expected = segment .Lanes .Select(lane => new RoadSegmentLaneAttributeRecord { Id = lane.AttributeId, RoadSegmentId = segment.Id, DbaseRecord = new RoadSegmentLaneAttributeDbaseRecord { RS_OIDN = { Value = lane.AttributeId }, WS_OIDN = { Value = segment.Id }, WS_GIDN = { Value = segment.Id + "_" + lane.AsOfGeometryVersion }, AANTAL = { Value = lane.Count }, RICHTING = { Value = RoadSegmentLaneDirection.Parse(lane.Direction).Translation.Identifier }, LBLRICHT = { Value = RoadSegmentLaneDirection.Parse(lane.Direction).Translation.Name }, VANPOS = { Value = (double)lane.FromPosition }, TOTPOS = { Value = (double)lane.ToPosition }, BEGINTIJD = { Value = lane.Origin.Since }, BEGINORG = { Value = lane.Origin.OrganizationId }, LBLBGNORG = { Value = lane.Origin.Organization } }.ToBytes(_services.MemoryStreamManager, Encoding.UTF8) }); return(new { importedRoadSegment = segment, expected }); }).ToList(); return(new RoadSegmentLaneAttributeRecordProjection(new RecyclableMemoryStreamManager(), Encoding.UTF8) .Scenario() .Given(data.Select(d => d.importedRoadSegment)) .Expect(data .SelectMany(d => d.expected) .Cast <object>() .ToArray() )); }
public RoadSegmentLaneAttributeRecordProjection(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.Lanes.Length == 0) { return(Task.CompletedTask); } var laneRecords = envelope.Message .Lanes .Select(lane => { var laneDirectionTranslation = RoadSegmentLaneDirection.Parse(lane.Direction).Translation; return(new RoadSegmentLaneAttributeRecord { Id = lane.AttributeId, RoadSegmentId = envelope.Message.Id, DbaseRecord = new RoadSegmentLaneAttributeDbaseRecord { RS_OIDN = { Value = lane.AttributeId }, WS_OIDN = { Value = envelope.Message.Id }, WS_GIDN = { Value = $"{envelope.Message.Id}_{lane.AsOfGeometryVersion}" }, AANTAL = { Value = lane.Count }, RICHTING = { Value = laneDirectionTranslation.Identifier }, LBLRICHT = { Value = laneDirectionTranslation.Name }, VANPOS = { Value = (double)lane.FromPosition }, TOTPOS = { Value = (double)lane.ToPosition }, BEGINTIJD = { Value = lane.Origin.Since }, BEGINORG = { Value = lane.Origin.OrganizationId }, LBLBGNORG = { Value = lane.Origin.Organization }, }.ToBytes(manager, encoding) }); }); return(context.RoadSegmentLaneAttributes.AddRangeAsync(laneRecords, token)); }); When <Envelope <RoadNetworkChangesBasedOnArchiveAccepted> >(async(context, envelope, token) => { foreach (var change in envelope.Message.Changes.Flatten()) { switch (change) { case RoadSegmentAdded segment: if (segment.Lanes.Length != 0) { var lanes = segment .Lanes .Select(lane => { var laneDirectionTranslation = RoadSegmentLaneDirection.Parse(lane.Direction).Translation; return(new RoadSegmentLaneAttributeRecord { Id = lane.AttributeId, RoadSegmentId = segment.Id, DbaseRecord = new RoadSegmentLaneAttributeDbaseRecord { RS_OIDN = { Value = lane.AttributeId }, WS_OIDN = { Value = segment.Id }, WS_GIDN = { Value = $"{segment.Id}_{lane.AsOfGeometryVersion}" }, AANTAL = { Value = lane.Count }, RICHTING = { Value = laneDirectionTranslation.Identifier }, LBLRICHT = { Value = laneDirectionTranslation.Name }, VANPOS = { Value = (double)lane.FromPosition }, TOTPOS = { Value = (double)lane.ToPosition }, BEGINTIJD = { Value = LocalDateTimeTranslator.TranslateFromWhen(envelope.Message.When) }, BEGINORG = { Value = envelope.Message.OrganizationId }, LBLBGNORG = { Value = envelope.Message.Organization } }.ToBytes(manager, encoding) }); }); await context.RoadSegmentLaneAttributes.AddRangeAsync(lanes); } // case RoadSegmentModified segment: // if (segment.Lanes.Length == 0) // { // context.RoadSegmentLaneAttributes.RemoveRange( // context // .RoadSegmentLaneAttributes // .Local.Where(a => a.RoadSegmentId == segment.Id) // .Concat(await context // .RoadSegmentLaneAttributes // .Where(a => a.RoadSegmentId == segment.Id) // .ToArrayAsync(token) // )); // } // else // { // var currentSet = context // .RoadSegmentLaneAttributes // .Local.Where(a => a.RoadSegmentId == segment.Id) // .Concat(await context // .RoadSegmentLaneAttributes // .Where(a => a.RoadSegmentId == segment.Id) // .ToArrayAsync(token) // ).ToDictionary(a => a.Id); // var nextSet = segment // .Lanes // .Select(lane => // { // var laneDirectionTranslation = RoadSegmentLaneDirection.Parse(lane.Direction).Translation; // return new RoadSegmentLaneAttributeRecord // { // Id = lane.AttributeId, // RoadSegmentId = segment.Id, // DbaseRecord = new RoadSegmentLaneAttributeDbaseRecord // { // RS_OIDN = {Value = lane.AttributeId}, // WS_OIDN = {Value = segment.Id}, // WS_GIDN = {Value = $"{segment.Id}_{lane.AsOfGeometryVersion}"}, // AANTAL = {Value = lane.Count}, // RICHTING = {Value = laneDirectionTranslation.Identifier}, // LBLRICHT = {Value = laneDirectionTranslation.Name}, // VANPOS = {Value = (double) lane.FromPosition}, // TOTPOS = {Value = (double) lane.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.RoadSegmentLaneAttributes.Synchronize(currentSet, nextSet, (current, next) => // { // current.DbaseRecord = next.DbaseRecord; // }); // } break; } } }); }
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 )); }