/// <summary> /// Saves the PropertyTree into a file (.tlp) /// </summary> /// <param name="tree"> The property tree to save. </param> /// <param name="path"> Contains the path and the name of the file (Do not mention the extension). </param> public void SaveToFile(PropertyTree tree, string path) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(@path + ".tlp")) { // First line file.WriteLine("(tlp \"2.0\""); // List of all nodes file.Write("(nodes"); foreach (int node in tree.parent.Keys) { file.Write(" " + node); } file.WriteLine(")"); // List of all edges int countEdges = 0; foreach (int edge in tree.parent.Keys) { if (edge != 0) { countEdges++; file.WriteLine("(edge " + countEdges + " " + (int)tree.Parent(edge) + " " + edge + ")"); } } // List of all clusters int clusterId = 1; foreach (string name in tree.PropertyNames()) { file.WriteLine("(cluster " + clusterId + " " + name); file.Write("(nodes"); foreach (int node in tree.Property(name).Keys) { file.Write(" " + node); } file.WriteLine("))"); clusterId++; } // List of all properties int propertyId = 1; foreach (string name in tree.PropertyNames()) { file.WriteLine("(property " + propertyId + " string \"" + name + "\""); Dictionary <int, dynamic> property = tree.Property(name); foreach (int id in property.Keys) { file.WriteLine("(node " + id + " " + property[id] + ")"); } file.WriteLine(")"); propertyId++; } } }