public void SaveGraph(EntityGraph graph, string fileName) { fileName = PathUtils.Decode(fileName); using (StreamWriter sw = new StreamWriter(fileName, false, Encoding.UTF8)) { NewLine = sw.NewLine; sw.WriteLine(PrintHeader()); foreach (IEntity entity in graph.GetAllEntities().GetItems()) { string str = string.Empty; if (entity is PropertyEntity) { str = PrintEntity((PropertyEntity)entity); } else if (entity is ClassEntity) { str = PrintEntity((IClassEntity)entity); } else if (entity is IndividualEntity) { str = PrintEntity((IndividualEntity)entity); } else if (entity is SeparatorEntity) { str = PrintEntity((SeparatorEntity)entity); } else { str = PrintEntity(entity); } if (str != string.Empty) { sw.WriteLine(); sw.WriteLine(str); } } sw.WriteLine(PrintFooter()); sw.Close(); } }
public void SaveGraph(EntityGraph entityTree, string fileName) { fileName = PathUtils.Decode(fileName); using (StreamWriter sw = new StreamWriter(fileName)) { //Write header sw.WriteLine("<TestOntology>"); //Write Entities foreach (IEntity entity in entityTree.GetAllEntities().GetItems()) { sw.WriteLine(); PrintEntity(sw, entity); } //Write Relationships foreach (IRelationship relationship in entityTree.GetAllRelationships()) { sw.WriteLine(); if (relationship is ConditionalRuleRelationship) { PrintRule(sw, relationship as ConditionalRuleRelationship); } else { PrintRelationship(sw, relationship); } } //Write header sw.WriteLine(); sw.WriteLine("</TestOntology>"); sw.Close(); } }