/// <summary> /// Loads a recent rndf and mdf /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void LoadRecentToolStripMenuItem_Click(object sender, EventArgs e) { // path to saved recent string relativePath = "Recent.txt"; try { using (StreamReader sr = new StreamReader(relativePath)) { // get rndf string rndfPath = sr.ReadLine(); RemoraOutput.WriteLine("Loading Rndf: " + rndfPath); // get mdf string mdfPath = sr.ReadLine(); RemoraOutput.WriteLine("Loading Mdf: " + mdfPath); sr.Dispose(); sr.Close(); } } catch (Exception ex) { RemoraOutput.WriteLine(ex.ToString()); } }
/// <summary> /// Cleas up when closing /// </summary> /// <param name="e"></param> protected override void OnClosing(CancelEventArgs e) { // stop data stream runOutput = false; // shut down communications this.communicator.ShutDown(); // path to saved recent string relativePath = "Recent.txt"; try { using (StreamWriter sw = new StreamWriter(relativePath)) { // set rndf save sw.WriteLine(rndfPathSave); // set mdf save sw.WriteLine(mdfPathSave); // close the file sw.Close(); } } catch (Exception ex) { RemoraOutput.WriteLine(ex.ToString()); } // run usual stuff base.OnClosing(e); }
/// <summary> /// load mdf from a file /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void loadMdfToolStripMenuItem_Click(object sender, EventArgs e) { // create new openFileDialog openFileDialog1 = new OpenFileDialog(); // settings for openFileDialog openFileDialog1.InitialDirectory = "Desktop\\"; openFileDialog1.Filter = "Mdf Network Files (*.mnet)|*.mnet|All files (*.*)|*.*"; openFileDialog1.FilterIndex = 1; openFileDialog1.RestoreDirectory = true; // check if everything was selected alright if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { // Get Rndf Filename string fileName = openFileDialog1.FileName; this.mdfPathSave = fileName; // create a new network handler MdfHandler mdfHandler = new MdfHandler(); // deserialize this.roadDisplay1.SetMdf(mdfHandler.Load(fileName)); // notify RemoraOutput.WriteLine("Mdf Network Loaded: " + fileName); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } }
/// <summary> /// set the display's mdf /// </summary> /// <param name="mdf"></param> public void SetMdf(Mdf mdf) { if (mdf != null) { this.roadDisplay1.mdf = mdf; } else { RemoraOutput.WriteLine("Received Null Rndf"); } }
/// <summary> /// Set the display's rndf /// </summary> /// <param name="rndf"></param> public void SetRndf(RndfNetwork rndf) { if (rndf != null) { this.roadDisplay1.SetRndf(rndf); } else { RemoraOutput.WriteLine("Received Null Rndf"); } }
/// <summary> /// Constructor /// </summary> public RemoraDisplay() { // construct InitializeComponent(); // don't run code in design mode if (!this.DesignMode) { // output RemoraOutput.SetTextBox(this.richTextBox1); } }
/// <summary> /// Stop the vehicle /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Stop_Click(object sender, EventArgs e) { try { this.communicator.StopArbiter(); RemoraOutput.WriteLine("Stopped Arbiter"); } catch (Exception ex) { RemoraOutput.WriteLine(ex.ToString()); } }
/// <summary> /// Sends mdf to arbiter /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void updateMdfToolStripMenuItem_Click(object sender, EventArgs e) { if (this.roadDisplay1.mdf == null) { MessageBox.Show("Need to load mdf before sending mdf to arbiter"); } else { if (!communicator.UpdateMdf(this.roadDisplay1.mdf)) { RemoraOutput.WriteLine("Error setting mdf"); } } }
/// <summary> /// pings the arbiter /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PingArbiterToolStripButton_Click(object sender, EventArgs e) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Reset(); stopwatch.Start(); if (this.communicator.PingArbiter()) { stopwatch.Stop(); RemoraOutput.WriteLine("Ping Response Received: " + stopwatch.ElapsedMilliseconds.ToString() + " ms"); } else { RemoraOutput.WriteLine("Ping Response Failed!"); stopwatch.Stop(); } }
/// <summary> /// Restarts the arbiter /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RestartArbiterButton_Click(object sender, EventArgs e) { try { if (this.roadDisplay1.rndf != null && this.roadDisplay1.mdf != null) { this.communicator.RestartArbiter(this.roadDisplay1.rndf, this.roadDisplay1.mdf); } else { RemoraOutput.WriteLine("Cannot start arbiter with rndf or mdf null"); } } catch (Exception ex) { RemoraOutput.WriteLine(ex.ToString()); } }
/// <summary> /// Binds the arbiter as an ArbiterRemote facade to provide remote control /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ConnectArbiter_Click(object sender, EventArgs e) { //check if we have initialized remoting if (this.communicator.RemotingInitialized) { try { this.communicator.ConnectToArbiter(); } catch (Exception ex) { RemoraOutput.WriteLine(ex.ToString()); } } else { MessageBox.Show("Need to Successfully Initialize Remoting Communication"); } }