Beispiel #1
0
        public static void Start(string simulationID)
        {
            //Always prepare analysis.  Take snap shot of data.
            PrepareAnalysis.Simulation(simulationID);
            bool isStartNewSimulation = true;

            if (RunSimulation.Simulations.ContainsKey(simulationID))
            {
                Thread runningThread = RunSimulation.Simulations[simulationID];
                if (runningThread.IsAlive)
                {
                    isStartNewSimulation = false;
                }
                else
                {
                    RunSimulation.Simulations.Remove(simulationID);
                }
            }
            if (isStartNewSimulation)
            {
                Simulation.SimulationMessaging.ClearProgressList(simulationID);
                Simulation.Simulation simulation = new Simulation.Simulation("", "", simulationID, "1", DB.ConnectionString);
                Thread simulationThread          = new Thread(new ParameterizedThreadStart(simulation.CompileSimulation));
                RunSimulation.Simulations.Add(simulationID, simulationThread);
                simulationThread.Start(false);
            }
        }
Beispiel #2
0
        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;
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var connectionString = args[0];
            var networkId        = args[1];
            var simulationId     = args[2];


            var simulation = new Simulation.Simulation("", "", simulationId, networkId, connectionString);

            simulation.CompileSimulation(false);
        }
Beispiel #4
0
        public static string UpdateResultActivity(string sessionID, int rowIndex, string action, string treatment, int fromYear, string value)
        {
            SessionStore session   = OMS.Sessions.Find(delegate(SessionStore s) { return(s.SessionID == sessionID); });
            string       sectionID = session.OIDs[rowIndex];

            if (session == null)
            {
                return("Error: Expired sessionID=" + sessionID);
            }
            string encoded = null;

            Simulation.SimulationMessaging.ClearProgressList(session.SimulationID);
            Simulation.Simulation simulation = new Simulation.Simulation(session.SimulationID, sectionID, action, treatment, fromYear, value, DB.ConnectionString);
            simulation.UpdateSimulation();
            encoded = SelectScenario.GetActivityResults(session.SessionID, sectionID);
            return(encoded);
        }
Beispiel #5
0
 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;
     }
 }
Beispiel #6
0
        static void Main(string[] args)
        {
            if (GlobalSettings.DevelopmentMode)
            {
                Simulation simulation = new Simulation();
                simulation.Run();
                return;
            }

            try
            {
                Simulation simulation = new Simulation();
                simulation.Run();
            }
            catch (Exception e)
            {
                try
                {
                    if (!Directory.Exists("error_logs"))
                        Directory.CreateDirectory("error_logs");
                    string errorFilename = @"error_logs\error-" + DateTime.Now.ToFileTime() + ".txt";
                    StreamWriter writer = new StreamWriter(errorFilename, true, System.Text.Encoding.ASCII);
                    writer.WriteLine("Date: " + DateTime.Now.ToLongDateString() + "\n");
                    writer.WriteLine("Time: " + DateTime.Now.ToLongTimeString() + "\n\n");
                    writer.WriteLine(e.ToString());
                    writer.Close();
                } catch(Exception secondException)
                {
                    try
                    {
                        MessageBox(new IntPtr(0), "Encountered an error while running, and was unable to " +
                            "save to an error log.\n\nInitial Exception: " + e.ToString() + "\n\nError log exception: " +
                            secondException.ToString(), "Error", 0);
                    }
                    catch (Exception criticalError)
                    {
                        criticalError.ToString();
                    }
                    secondException.ToString();
                }
            }
        }