private static async Task DumpHyperGraphFromCollection(IMongoCollection <BsonDocument> collection) { var watch = new Stopwatch(); Console.WriteLine($"Parse {collection.CollectionNamespace.FullName} Start!"); watch.Start(); var file = new FileInfo($@"{DumpDir.FullName}\{collection.CollectionNamespace.FullName}.bin"); if (file.Exists) { file.Delete(); } var hg = await BsonParser.CollectionToHyperGraphTaskAsync(collection); await using var fs = new FileStream(file.FullName, FileMode.Create); fs.Write(hg.Serialize()); watch.Stop(); lock (Lock) { _curCount++; Console.WriteLine( $"Parse {collection.CollectionNamespace.FullName} Done![{_curCount}\\{_allCount}] {watch.ElapsedMilliseconds} ms"); Console.Beep(); } }
private static async Task ParseCollectionAsync(IMongoCollection <BsonDocument> collection) { var watch = new Stopwatch(); Console.WriteLine($"Parse {collection.CollectionNamespace.FullName} Start!"); watch.Start(); var file = new FileInfo($@"{WorkDir.FullName}\{collection.CollectionNamespace.FullName}.log"); if (file.Exists) { file.Delete(); } var hg = await BsonParser.CollectionToHyperGraphTaskAsync(collection); await using var fs = new FileStream(file.FullName, FileMode.Create); await using var sw = new StreamWriter(fs) { AutoFlush = true }; sw.WriteLine("Vertices:"); foreach (var vertex in hg.Vertices) { sw.WriteLine("Data: " + vertex.Data); sw.WriteLine($"Vertex edges: {vertex.HyperEdges.Count}"); sw.WriteLine("".PadLeft(50, '-')); } sw.WriteLine("Edges:"); foreach (var edge in hg.HyperEdges) { sw.WriteLine("Edge weight: " + edge.Weight); sw.WriteLine($"Edge vertices {edge.Vertices.Count}:"); foreach (var vertex in edge.Vertices) { sw.WriteLine('\t' + vertex.Data); } sw.WriteLine("".PadLeft(50, '-')); } sw.WriteLine("Vertices count: " + hg.Vertices.Count); sw.WriteLine("Edges count: " + hg.HyperEdges.Count); watch.Stop(); _curCount++; Console.WriteLine( $"Parse {collection.CollectionNamespace.FullName} Done![{_curCount}\\{_allCount}] {watch.ElapsedMilliseconds} ms"); }