public static void load(string fileName, Graph holder) { string line; string[] lineItem; try { StreamReader sr = new StreamReader(File.Open(fileName, FileMode.Open)); line = ""; while ((line = sr.ReadLine()) != null) { lineItem = line.Split(';'); holder.addPoint(new Point( Convert.ToInt32(lineItem[0]), lineItem[1], Convert.ToSingle(lineItem[2]), Convert.ToSingle(lineItem[3]), Convert.ToSingle(lineItem[4]), Convert.ToByte(lineItem[5]), Convert.ToByte(lineItem[6]), Convert.ToByte(lineItem[7]))); } sr.Close(); } catch (Exception e) { // } }
public static void load(string fileName, Graph graph) { StreamReader reader = null; try { reader = new StreamReader(File.Open(fileName, FileMode.Open)); String line = ""; while ((line = reader.ReadLine()) != null) { graph.add(Edge.parse(graph, line)); } reader.Close(); } catch (Exception e) { throw new BadFileFormatException("Unexpected error while parsing '" + fileName + "'.", e); } finally { if (reader != null) { reader.Close(); } } }
public GraphForm() { InitializeComponent(); this.pbCanvas.Image = new Bitmap(GraphForm.IMG_X, GraphForm.IMG_Y); this.pbCanvas.SizeMode = PictureBoxSizeMode.StretchImage; this.clear(); this.graph = new Graph(); }
private static Edge parse(Graph graph, String line) { try { string[] lineItem = line.Split(Edge.DELIMITER); return new Edge( graph.getPoint(Convert.ToInt32(lineItem[0])), graph.getPoint(Convert.ToInt32(lineItem[1])), Convert.ToSingle(lineItem[2])); } catch (Exception e) { throw new GraphParseException("Edge parse error.", line, e); } }
private void bOpen_Click(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Graph files|graph*.txt"; if (dialog.ShowDialog() == DialogResult.OK) { try { this.graph = Graph.load(dialog.FileName); } catch ( BadFileFormatException exc ) { MessageBox.Show(exc.ToString()); } } this.fillComboBox(); this.draw(); }
public static Graph load(String fileName) { Graph graph = new Graph(); StreamReader reader = null; try { reader = new StreamReader(File.Open(fileName, FileMode.Open)); GraphPoint.load(reader.ReadLine(), graph); Edge.load(reader.ReadLine(), graph); } catch (Exception e) { throw new BadFileFormatException("Unexpected error while parsing '" + fileName + "'.", e); } finally { if (reader != null) { reader.Close(); } } return graph; }