private MapStream GetAggregateStream(Stream mapStream, MapStreamTransform streamTransform) { var stream = new MapStream(streamTransform(mapStream)); foreach (var(key, map) in this.config.AncillaryMaps) { var fs = new ReadOnlyFileStream(Path.Combine(this.config.MapRoot, map)); stream.UseAncillaryMap(key, streamTransform(fs)); } return(stream); }
/// <summary> /// Loads the specified stream as a map. /// </summary> /// <param name="mapStream">The stream to load data from. This stream will be processed by streamTransform (which will take ownership)</param> /// /// <param name="streamTransform">A delegate to tranform the map streams into a format that can be read. Typical use case is if the maps on disk are compressed.</param> /// <param name="loadCallback">An optional callback that will be invoked after each map is created</param> public TMap Load <TMap>(Stream mapStream, MapStreamTransform streamTransform, MapLoadCallback loadCallback = null) where TMap : IMap, new() { var reader = this.GetAggregateStream(mapStream, streamTransform); var map = this.CreateMap <TMap>(reader); foreach (var id in this.config.AncillaryMaps.Keys) { var anc = this.CreateMap <TMap>(reader, id); map.UseAncillaryMap(id, anc); loadCallback?.Invoke(anc, reader.GetStream(id)); } loadCallback?.Invoke(map, reader.Map); return(map); }
/// <summary> /// Loads the specified file as a map. /// </summary> /// <param name="mapName">The filename to load map data from. Will be combined with the current config's MapRoot</param> /// <param name="streamTransform">A delegate to tranform the map streams into a format that can be read. Typical use case is if the maps on disk are compressed.</param> /// <param name="loadCallback">An optional callback that will be invoked after each map is created</param> public TMap Load <TMap>(string mapName, MapStreamTransform streamTransform, MapLoadCallback loadCallback = null) where TMap : IMap, new() { var fs = new ReadOnlyFileStream(Path.Combine(this.config.MapRoot, mapName)); return(this.Load <TMap>(fs, streamTransform, loadCallback)); }