private void UpdateModel(OMSSimulation oms) { string sectionID = textBoxSectionID.Text; string treatment = comboBoxTreatment.Text; string action = comboBoxAction.Text; if (string.IsNullOrWhiteSpace(sectionID) || string.IsNullOrWhiteSpace(treatment) || string.IsNullOrWhiteSpace(action) || string.IsNullOrWhiteSpace(comboBoxYear.Text)) { MessageBox.Show("All fields save for value are mandatory."); return; } int year = Convert.ToInt32(comboBoxYear.Text); string value = textBoxValue.Text; try { if (SimulationMessaging.Valid) { oms.TextBox.Text = "Beginning Update Simulation " + oms.ToString() + " at " + DateTime.Now.ToString(); Simulation.Simulation simulation = new Simulation.Simulation(oms.SimulationID, sectionID, action, treatment, year, value, null); oms.Thread = new Thread(new ThreadStart(simulation.UpdateSimulation)); oms.Thread.Start(); timerSimulation.Start(); } } catch (Exception e) { oms.TextBox.Text = "Error starting Update simulation " + oms.ToString() + ". " + e.Message; } }
private void closeToolStripMenuItem_Click(object sender, EventArgs e) { foreach (object item in comboBoxSimulationDescription.Items) { OMSSimulation oms = (OMSSimulation)item; if (tabControlOutput.SelectedTab == oms.TabPage) { oms.TabPage = null; if (oms.Thread != null) { oms.Thread.Abort(); oms.Thread = null; } } } tabControlOutput.TabPages.Remove(tabControlOutput.SelectedTab); }
private void buttonUpdate_Click(object sender, EventArgs e) { OMSSimulation oms = (OMSSimulation)comboBoxSimulationDescription.SelectedItem; if (oms != null && oms.TabPage == null) { tabControlOutput.TabPages.Add(oms.CreateNewTabPage()); tabControlOutput.SelectedTab = oms.TabPage; UpdateModel(oms); } else if (oms != null && oms.TabPage != null) { oms.TextBox.Clear(); oms.Thread = null; UpdateModel(oms); } }
private void RunModel(OMSSimulation oms) { try { if (SimulationMessaging.Valid) { oms.TextBox.Text = "Beginning Simulation " + oms.ToString() + " at " + DateTime.Now.ToString(); Simulation.Simulation simulation = new Simulation.Simulation(oms.Simulation, "", oms.SimulationID, oms.NetworkID); oms.Thread = new Thread(new ParameterizedThreadStart(simulation.CompileSimulation)); oms.Thread.Start(false); timerSimulation.Start(); } } catch (Exception e) { oms.TextBox.Text = "Error starting simulation " + oms.ToString() + ". " + e.Message; } }
private void timerSimulation_Tick(object sender, EventArgs e) { bool isOneAlive = false; List <SimulationMessage> listSimulation = Simulation.SimulationMessaging.GetProgressList(); lock (listSimulation) { foreach (object item in comboBoxSimulationDescription.Items) { OMSSimulation oms = (OMSSimulation)item; if (oms.Thread != null && oms.Thread.IsAlive) { List <SimulationMessage> listOMS = listSimulation.FindAll(delegate(SimulationMessage sm) { return(sm.SimulationID == oms.SimulationID); }); foreach (SimulationMessage message in listOMS) { oms.TextBox.Text += "\r\n"; oms.TextBox.Text += message.Message + "(" + message.Percent.ToString() + "%)"; oms.TextBox.SelectionStart = oms.TextBox.Text.Length; oms.TextBox.ScrollToCaret(); oms.TextBox.Refresh(); } isOneAlive = true; _isLastTick = false; } } } //Updates user web user interface for Cartegraph on progress. Checks if it is running. If not running tells interface. Simulation.SimulationMessaging.ClearProgressList(); if (!isOneAlive) { if (!_isLastTick) { _isLastTick = true; } else { timerSimulation.Stop(); } } }