public async Task WriteSnapshot(Messages.RoadNetworkSnapshot snapshot, int version, CancellationToken cancellationToken) { var snapshotBlobName = SnapshotPrefix.Append(new BlobName(version.ToString())); using (var stream = _streamManager.GetStream()) { await MessagePackSerializer.SerializeAsync(stream, snapshot, cancellationToken : cancellationToken); stream.Position = 0; await _client.CreateBlobAsync( snapshotBlobName, Metadata.None.AtVersion(version), MessagePackContentType, stream, cancellationToken); } if (await _client.BlobExistsAsync(SnapshotHead, cancellationToken)) { await _client.DeleteBlobAsync(SnapshotHead, cancellationToken); } var snapshotHead = new Messages.RoadNetworkSnapshotHead { SnapshotBlobName = snapshotBlobName.ToString() }; using (var stream = _streamManager.GetStream()) { await MessagePackSerializer.SerializeAsync(stream, snapshotHead, cancellationToken : cancellationToken); stream.Position = 0; await _client.CreateBlobAsync( SnapshotHead, Metadata.None, MessagePackContentType, stream, cancellationToken); } }
public RoadNetworkView RestoreFromSnapshot(Messages.RoadNetworkSnapshot snapshot) { if (snapshot == null) { throw new ArgumentNullException(nameof(snapshot)); } return(new RoadNetworkView( snapshot.Nodes.ToImmutableDictionary(node => new RoadNodeId(node.Id), node => new RoadNode(new RoadNodeId(node.Id), GeometryTranslator.Translate(node.Geometry))), snapshot.Segments.ToImmutableDictionary(segment => new RoadSegmentId(segment.Id), segment => new RoadSegment(new RoadSegmentId(segment.Id), GeometryTranslator.Translate(segment.Geometry), new RoadNodeId(segment.StartNodeId), new RoadNodeId(segment.EndNodeId), AttributeHash.FromHashCode(segment.AttributeHash))), new RoadNodeId(snapshot.MaximumNodeId), new RoadSegmentId(snapshot.MaximumSegmentId), new GradeSeparatedJunctionId(snapshot.MaximumGradeSeparatedJunctionId), new AttributeId(snapshot.MaximumEuropeanRoadAttributeId), new AttributeId(snapshot.MaximumNationalRoadAttributeId), new AttributeId(snapshot.MaximumNumberedRoadAttributeId), new AttributeId(snapshot.MaximumLaneAttributeId), new AttributeId(snapshot.MaximumWidthAttributeId), new AttributeId(snapshot.MaximumSurfaceAttributeId), snapshot.SegmentReusableLaneAttributeIdentifiers.ToImmutableDictionary( segment => new RoadSegmentId(segment.SegmentId), segment => (IReadOnlyList <AttributeId>)segment.ReusableAttributeIdentifiers .Select(identifier => new AttributeId(identifier)).ToArray()), snapshot.SegmentReusableWidthAttributeIdentifiers.ToImmutableDictionary( segment => new RoadSegmentId(segment.SegmentId), segment => (IReadOnlyList <AttributeId>)segment.ReusableAttributeIdentifiers .Select(identifier => new AttributeId(identifier)).ToArray()), snapshot.SegmentReusableSurfaceAttributeIdentifiers.ToImmutableDictionary( segment => new RoadSegmentId(segment.SegmentId), segment => (IReadOnlyList <AttributeId>)segment.ReusableAttributeIdentifiers .Select(identifier => new AttributeId(identifier)).ToArray()) )); }