private void SaveGraphToFile() { using (var saveFileDialog = new SaveFileDialog()) { saveFileDialog.Filter = "GraphMaker files (*.gm)|*.gm"; saveFileDialog.FilterIndex = 1; saveFileDialog.RestoreDirectory = true; if (saveFileDialog.ShowDialog() == DialogResult.OK) { var fileName = saveFileDialog.FileName; string json; try { json = UiGraph.Serialize(graph); } catch (Exception ex) { MessageBox.Show($"Ошибка при сериализации графа: {ex.Message}"); return; } File.WriteAllText(fileName, json); draw(); } } }
public void ShouldBeSerializable() { var node1 = graph.AddNode(0, 0, Color.Red); var node2 = graph.AddNode(1, 1, Color.Green); graph.AddEdge(node1, node2, 42, Color.Blue); var json1 = UiGraph.Serialize(graph); var deserializedGraph = UiGraph.Deserialize(json1); var json2 = UiGraph.Serialize(deserializedGraph); json1.Should().Be(json2); }