using System; using System.Collections.Generic; using System.IO; using System.Windows.Forms; using VisualTraceRoute.Net; using VisualTraceRoute.Text; namespace VisualTraceRoute.Graph.Flot { /// /// Flot form. /// public partial class Flot : Form { /// /// Initializes a new instance of the Flot class. /// public Flot() { this.InitializeComponent(); } /// /// Form load. /// /// Calling object. /// Event arguments. private void Flot_Load(object sender, EventArgs e) { // Load the trace HTML on loading. this.browser.Url = new System.Uri(new FileInfo(Path.Combine("Resources", "trace.html")).FullName); } /// /// Handle the Enter key press. /// /// Calling object. /// Key event arguments. private void address_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { this.StartTrace(); e.Handled = true; } } /// /// Begin trace route. /// /// Calling object. /// Event arguments. private void traceRoute_Click(object sender, EventArgs e) { this.StartTrace(); } /// /// Start a trace with the form data. /// private void StartTrace() { string addr = this.address.Text; // Ensure there is an address present. if (!string.IsNullOrEmpty(addr)) { List routes = new List(); routes.Add(TraceRoute.ByHostName(addr)); foreach (TraceRoute route in routes) { foreach (Hop hop in route.Hops) { this.console.AppendText(string.Format("{0}{1}", hop, Environment.NewLine)); } } // Map to the files. FileInfo templateFile = new FileInfo(Path.Combine("Resources", "flot-template.txt")); FileInfo jsonFile = new FileInfo(Path.Combine("Resources", "trace.html")); // Operate the text parser. Parser parser = new Parser(templateFile); parser.ReadTemplate(); parser.Write(jsonFile, routes.ToArray()); // Refresh contents. this.browser.Refresh(); } this.address.Focus(); } } }