Changed to JsonSerialization to permanently store regions.
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
using System.Globalization;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Text.Json;
|
||||
using System.Xml;
|
||||
using OSMDatastructure;
|
||||
using OSMDatastructure.Graph;
|
||||
@ -46,7 +47,6 @@ public class RegionConverter
|
||||
|
||||
private static Dictionary<ulong, ulong> GetNodesAndRegions(XmlReader xmlReader, string outputPath)
|
||||
{
|
||||
BinaryFormatter bFormatter = new BinaryFormatter();
|
||||
Dictionary<ulong, ulong> nodeRegions = new();
|
||||
Dictionary<ulong, FileStream> regionFileStreams = new();
|
||||
Dictionary<ulong, OsmNode> tmpAllNodes = new();
|
||||
@ -82,6 +82,7 @@ public class RegionConverter
|
||||
|
||||
foreach (ulong nodeId in currentIds.Where(key => tmpAllNodes.ContainsKey(key)))
|
||||
{
|
||||
BinaryFormatter bFormatter = new BinaryFormatter();
|
||||
if (isHighway)
|
||||
{
|
||||
ulong regionHash = Coordinates.GetRegionHashCode(tmpAllNodes[nodeId].coordinates);
|
||||
@ -97,7 +98,7 @@ public class RegionConverter
|
||||
regionFileStreams.Add(regionHash, nodesRegionStream);
|
||||
}
|
||||
nodeRegions.Add(nodeId, regionHash);
|
||||
|
||||
|
||||
#pragma warning disable SYSLIB0011 //eheheh
|
||||
bFormatter.Serialize(nodesRegionStream, tmpAllNodes[nodeId]);
|
||||
#pragma warning restore SYSLIB0011
|
||||
@ -221,7 +222,6 @@ public class RegionConverter
|
||||
|
||||
private static void CombineTmpFiles(string folderPath, HashSet<ulong> regionHashes)
|
||||
{
|
||||
BinaryFormatter bFormatter = new BinaryFormatter();
|
||||
foreach (ulong regionId in regionHashes)
|
||||
{
|
||||
ValueTuple<Region, HashSet<OsmEdge>> tmpRegion = LoadRegion(folderPath, regionId);
|
||||
@ -233,11 +233,11 @@ public class RegionConverter
|
||||
startNode.edges.Add(edge);
|
||||
}
|
||||
}
|
||||
FileStream tmpRegionFileStream = new FileStream(Path.Join(folderPath, $"{regionId}{RegionsFileName}"), FileMode.Create);
|
||||
#pragma warning disable SYSLIB0011
|
||||
bFormatter.Serialize(tmpRegionFileStream, tmpRegion.Item1);
|
||||
#pragma warning restore SYSLIB0011
|
||||
tmpRegionFileStream.Dispose();
|
||||
|
||||
using (FileStream tmpRegionFileStream = new FileStream(Path.Join(folderPath, $"{regionId}{RegionsFileName}"), FileMode.Create))
|
||||
{
|
||||
JsonSerializer.Serialize(tmpRegionFileStream, tmpRegion.Item1, typeof(Region), Region.serializerOptions);
|
||||
}
|
||||
Directory.Delete(Path.Join(folderPath, regionId.ToString()), true);
|
||||
}
|
||||
}
|
||||
|
@ -11,4 +11,8 @@
|
||||
<ProjectReference Include="..\Pathfinding\Pathfinding.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Runtime.Serialization.Json" Version="4.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
Reference in New Issue
Block a user