Dispose of Region-filestream
This commit is contained in:
parent
58d1031524
commit
fc5d388ecd
@ -59,16 +59,4 @@ public class Region
|
|||||||
else return null;
|
else return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Region? FromFile(string filePath)
|
|
||||||
{
|
|
||||||
if (File.Exists(filePath))
|
|
||||||
return JsonSerializer.Deserialize<Region>(new FileStream(filePath, FileMode.Open), serializerOptions)!;
|
|
||||||
else return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Region? FromId(string path, ulong regionId)
|
|
||||||
{
|
|
||||||
string filePath = Path.Join(path, $"{regionId}.region");
|
|
||||||
return FromFile(filePath);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,3 +1,4 @@
|
|||||||
|
using System.Text.Json;
|
||||||
using OSMDatastructure;
|
using OSMDatastructure;
|
||||||
using OSMDatastructure.Graph;
|
using OSMDatastructure.Graph;
|
||||||
|
|
||||||
@ -24,7 +25,7 @@ namespace OSMImporter
|
|||||||
return value;
|
return value;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Region? loadedRegion = LoadRegion(id);
|
Region? loadedRegion = RegionFromId(id);
|
||||||
if(loadedRegion is not null)
|
if(loadedRegion is not null)
|
||||||
_regions.Add(loadedRegion!.regionHash, value: loadedRegion);
|
_regions.Add(loadedRegion!.regionHash, value: loadedRegion);
|
||||||
return loadedRegion;
|
return loadedRegion;
|
||||||
@ -36,17 +37,6 @@ namespace OSMImporter
|
|||||||
return this._regions.Values.ToArray();
|
return this._regions.Values.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Region? LoadRegion(Coordinates coordinates)
|
|
||||||
{
|
|
||||||
return LoadRegion(Coordinates.GetRegionHashCode(coordinates));
|
|
||||||
}
|
|
||||||
|
|
||||||
private Region? LoadRegion(ulong id)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Load Region {id}");
|
|
||||||
return Region.FromId(workingDirectory, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public OsmNode? GetNode(Coordinates coordinates)
|
public OsmNode? GetNode(Coordinates coordinates)
|
||||||
{
|
{
|
||||||
Region? regionWithNode = GetRegion(coordinates);
|
Region? regionWithNode = GetRegion(coordinates);
|
||||||
@ -60,5 +50,23 @@ namespace OSMImporter
|
|||||||
Region? r = GetRegion(regionId);
|
Region? r = GetRegion(regionId);
|
||||||
return r?.GetNode(nodeId);
|
return r?.GetNode(nodeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Region? RegionFromFile(string filePath)
|
||||||
|
{
|
||||||
|
Region? retRegion = null;
|
||||||
|
if (File.Exists(filePath))
|
||||||
|
{
|
||||||
|
FileStream regionFile = new FileStream(filePath, FileMode.Open);
|
||||||
|
retRegion = JsonSerializer.Deserialize<Region>(regionFile, Region.serializerOptions)!;
|
||||||
|
regionFile.Dispose();
|
||||||
|
}
|
||||||
|
return retRegion;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Region? RegionFromId(ulong regionId)
|
||||||
|
{
|
||||||
|
string filePath = Path.Join(workingDirectory, $"{regionId}.region");
|
||||||
|
return RegionFromFile(filePath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user