Rewrote XmlImporter to Write Region-files while reading from Stream

This commit is contained in:
2023-03-31 21:56:27 +02:00
parent 07ff9602b8
commit b621ff632b
5 changed files with 184 additions and 237 deletions

View File

@ -6,7 +6,7 @@ namespace OSMImporter
public class RegionManager
{
private string workingDirectory { get; }
private readonly Dictionary<int, Region> _regions = new();
private readonly Dictionary<ulong, Region> _regions = new();
public RegionManager(string workingDirectory)
{
@ -44,23 +44,7 @@ namespace OSMImporter
/// <exception cref="FileNotFoundException">If the Regionfile can not be found.</exception>
private Region LoadRegion(Coordinates coordinates)
{
string fullPath = Path.Combine(workingDirectory, Coordinates.GetRegionHashCode(coordinates).ToString());
DateTime startTime = DateTime.Now;
if (!File.Exists(fullPath))
{
throw new FileNotFoundException(string.Format("[{0}] Region does not exist: {1}", startTime, fullPath));
}
FileStream fileStream = new FileStream(fullPath, FileMode.Open);
long fileStreamLength = fileStream.Length;
Console.WriteLine("[{0}] Loading [{1}]bytes from {2}", startTime.ToLocalTime(), fileStreamLength, fullPath);
byte[] regionBytes = new byte[fileStream.Length];
int loadedBytesLength = fileStream.Read(regionBytes, 0, regionBytes.Length);
fileStream.Close();
Console.WriteLine("\tLoaded [{0}]bytes ({1:P1}) in [{2}]ms", loadedBytesLength, fileStreamLength / loadedBytesLength,DateTime.Now.Subtract(startTime).TotalMilliseconds);
return ByteConverter.ToRegion(regionBytes);
throw new NotImplementedException();
}
public OsmNode? GetNode(Coordinates coordinates)