Exemple #1
0
 private void tbSeed_Leave(object sender, EventArgs e)
 {
     if (!LoadLib.SetSeed(tbSeed.Text))
     {
         MessageBox.Show("Invalid Seed, must be a number");
         tbSeed.Text = "";
     }
 }
Exemple #2
0
        private void btnValidateModel_Click(object sender, EventArgs e)
        {
            Cursor saveCurs = Cursor.Current;

            Cursor.Current = Cursors.WaitCursor;

            txtMStatus.Text = LoadLib.ValidateModel(ref _sim, txtModel.Text, Path.GetDirectoryName(_modelPath));
            _validSim       = txtMStatus.Text == "";
            if (txtMStatus.Text != "")
            {
                txtMStatus.ForeColor = Color.Maroon;
                Console.Write(txtMStatus.Text);
            }

            InitSimTabInfo();
            Cursor.Current = saveCurs;
        }
Exemple #3
0
        private void OpenModel(string path)
        {
            Cursor saveCurs = Cursor.Current;

            Cursor.Current = Cursors.WaitCursor;

            this.Text = "EMRALD (" + path + ");";

            string errorStr = "";

            txtModel.Text = LoadLib.LoadModel(path, ref errorStr);
            _modelPath    = path;
            if (errorStr != "")
            {
                txtMStatus.ForeColor = Color.Maroon;
                txtMStatus.Text      = errorStr;
                Console.Write(errorStr);
            }

            btnValidateModel_Click(null, null);

            Cursor.Current = saveCurs;
        }
Exemple #4
0
        public FormMain(string[] args, IAppSettingsService appSettingsService)
        {
            _appSettingsService = appSettingsService;
            InitializeComponent();
            lvResults.Columns[3].Text = "Mean Time or Failed Components";
            lvResults.Columns[1].Text = "Count";

            //System.IO.File.Wri
            curDir = System.IO.Path.GetDirectoryName(Application.ExecutablePath);

            //System.IO.File.WriteAllLines(curDir + "\\simRunLog.txt", args);
            //System.IO.File.AppendAllText(curDir + "\\simRunLog.txt", "Cur Dir = " + Directory.GetCurrentDirectory() + Environment.NewLine);

            if (args.Length > 0)
            {
                if (args[0] == "//")
                {
                    return;
                }
                AttachConsole(ATTACH_PARENT_PROCESS);
            }

            bool   execute = false;
            string model   = null;

            //SimulationDAL.Globals.simID = 1;
            for (int i = 0; i < args.Length; i++) // Loop through array
            {
                string argument = args[i];
                switch (argument)
                {
                case "-n": //run count
                {
                    tbRunCnt.Text = args[i + 1];
                    ++i;
                    break;
                }

                case "-i": //path to input file
                {
                    string filePath = args[i + 1];
                    if (!File.Exists(filePath))
                    {
                        Console.Write("invalid input file path - " + filePath);
                        return;
                    }
                    else
                    {
                        model = filePath;
                    }
                    ++i;
                    break;
                }


                //case "-c": //code load of project
                //  {
                //    sim = new LookupLists("Test", "Desc");
                //    sim.TestNRCFlooding2();
                //    //sim.TestLoop();
                //    break;
                //  }

                case "-r": //path to output file
                {
                    //tabSimulate_Enter(this, null);
                    tbSavePath.Text = args[i + 1];
                    ++i;
                    break;
                }

                case "-o": //path to paths and timing output file
                {
                    tbSavePath2.Text = args[i + 1];
                    ++i;
                    break;
                }

                case "-t": //max run time
                {
                    tbMaxSimTime.Text = args[i + 1];
                    ++i;
                    break;
                }

                case "-e": //execute
                {
                    execute = true;
                    break;
                }

                case "-m": //monitor
                {
                    try
                    {
                        string arg = args[i + 1];
                        if (arg[0] == '[')
                        {
                            arg = arg.TrimStart('[');
                            while (arg[arg.Length - 1] != ']')
                            {
                                monitor.Add(arg);
                                ++i;
                                arg = args[i + 1];
                            }

                            arg = arg.TrimEnd(']');
                            monitor.Add(arg);
                            ++i;
                        }
                        else
                        {
                            monitor.Add(args[i + 1]);
                            ++i;
                        }
                    }
                    catch
                    {
                        Console.Write("invalid data for monitor parameters, must be a single string or multiple encased in \"[]\", example - [x y z] ");
                    }

                    break;
                }

                case "-c": //coupled XMPP application
                {
                    try
                    {
                        //read the password
                        _XMPP_Password = args[i + 1];
                        ++i;
                        string arg = args[i + 1];
                        if (arg[0] == '[')
                        {
                            arg = arg.TrimStart('[');
                            while (arg[arg.Length - 1] != ']')
                            {
                                string linkName = arg;
                                ++i;
                                string xmppResouce = args[i + 1];
                                ++i;
                                string xmppUser = args[i + 1];
                                ++i;
                                int timeout = int.Parse(args[i + 1].TrimEnd(']')); //verify it is a number

                                _xmppLink.Add(new List <string>()
                                    {
                                        linkName, xmppResouce, xmppUser, timeout.ToString()
                                    });
                            }

                            arg = args[i + 1];
                            ++i;
                        }
                        else
                        {
                            string linkName = arg;
                            ++i;
                            string xmppResouce = args[i + 1];
                            ++i;
                            string xmppUser = args[i + 1];
                            ++i;
                            int timeout = int.Parse(args[i + 1]); //verify it is a number

                            _xmppLink.Add(new List <string>()
                                {
                                    linkName, xmppResouce, xmppUser, timeout.ToString()
                                });
                            ++i;
                        }
                    }
                    catch
                    {
                        Console.Write("invalid data for coupling external simulation, specify the password and the external sim name, XMPP connection resource, XMPP user name, and timeout in seconds. For multiple, encase in \"[]\"" + Environment.NewLine +
                                      "Example: -d xmppServerPassword [LinkedProgram MyApp User1 60] [LinkedProgram2 MyApp2 User2 60]");
                    }

                    break;
                }

                case "-s":
                {
                    if (LoadLib.SetSeed(args[i + 1]))
                    {
                        tbSeed.Text = args[i + 1];
                    }
                    break;
                }

                case "-jsonStats":
                {
                    _statsFile = args[i + 1];
                    break;
                }

                case "-d": //debug the runs
                {
                    string strLev = args[i + 1];

                    switch (strLev)
                    {
                    case "basic":
                    case "Basic":
                        chkLog.Checked      = true;
                        ConfigData.debugLev = LogLevel.Info;
                        break;

                    case "detailed":
                    case "Detailed":
                        chkLog.Checked          = true;
                        rbDebugBasic.Checked    = false;
                        rbDebugDetailed.Checked = true;
                        ConfigData.debugLev     = LogLevel.Debug;
                        break;

                    default:
                        Console.Write("invalid option for debug must be \"basic\" or \"detailed\". ");
                        break;
                    }
                    ++i;

                    string arg = args[i + 1];
                    if (arg[0] == '[')
                    {
                        try
                        {
                            //get the start index
                            arg = arg.TrimStart('[');
                            if (arg.EndsWith(","))
                            {
                                arg = arg.TrimEnd(',');
                            }
                            ConfigData.debugRunStart = int.Parse(arg);
                            tbLogRunStart.Text       = arg;
                            ++i;

                            //get the end index
                            arg = args[i + 1];
                            if (!arg.EndsWith("]"))
                            {
                                Console.Write("invalid option for debug range. Use [startIndex endIndex]");
                                return;
                            }
                            arg = arg.TrimEnd(']');
                            ConfigData.debugRunEnd = int.Parse(arg);
                            tbLogRunEnd.Text       = arg;
                            ++i;
                        }
                        catch
                        {
                            Console.Write("invalid option for debug range. Use [startIndex endIndex]");
                        }

                        ++i;
                    }


                    break;
                }

                case "-help":
                {
                    Console.WriteLine("-n \"run count\"");
                    Console.WriteLine("-i \"input model path\"");
                    Console.WriteLine("-r \"results output file\"");
                    Console.WriteLine("-o \"paths output file\"");
                    Console.WriteLine("-jsonStats \"write path statistics to json output file at specified directory\"");
                    Console.WriteLine("-t \"max run time\"");
                    Console.WriteLine("-e \"execute\"");
                    Console.WriteLine("-c \"coupled external simulation using XMPP, specify the password and the external sim name, XMPP connection resource, XMPP user name and timeout in seconds. If there is more than one put each in brackets\"" + Environment.NewLine +
                                      "    Example: -d xmppServerPassword [LinkedProgram MyApp User1 60] [LinkedProgram2 MyApp2 User2 60]");
                    Console.WriteLine("-m \"parameter to monitor, use []'s to do multiples, example - [x y z] \"");
                    Console.WriteLine("-s \"initial random number seed\"");
                    Console.WriteLine("-d \"debug level \"basic\" or \"detailed\", (optional) range [start end]. " + Environment.NewLine +
                                      "    Basic - state movement only. Detailed - state movement, actions and events. " + Environment.NewLine +
                                      "    Example: -d basic [10 20]");
                    break;
                }


                    //case "-x": //path to Extternal Sims TODO
                    //  {
                    //    if (File.Exists(args[i+1]))
                    //    {
                    //      extSims.Add(args[i + 1]);
                    //    }
                    //    else
                    //    {
                    //      Console.Write("invalid input external sim path - " + args[i + 1]);
                    //      return;
                    //    }

                    //    string model3DPath = args[i + 1];
                    //    //cbNeutrino.Checked = true;
                    //    ++i;
                    //    break;
                    //  }
                }
            }

            if (model != null)
            {
                OpenModel(model);

                tcMain.SelectedTab = tabSimulate;

                //check the monitor values
                for (int idx = 0; idx < lbMonitorVars.Items.Count; idx++)
                {
                    if (monitor.Contains(lbMonitorVars.Items[idx].ToString()))
                    {
                        lbMonitorVars.SetItemChecked(idx, true);
                    }
                }

                //assign the xmpp connections if any
                for (int idx = 0; idx < _xmppLink.Count; idx++)
                {
                    AssignServer(); //make sure it has been assigned
                    var extSimLink = _sim.allExtSims.FindByName(_xmppLink[idx][0], false);
                    if (extSimLink == null)
                    {
                        Console.Write("Bad -c first input. No external link in model named - " + _xmppLink[idx][0]);
                    }
                    else
                    {
                        extSimLink.resourceName = _xmppLink[idx][1] + " - " + _xmppLink[idx][2].ToLower();
                        extSimLink.verified     = false;
                        extSimLink.timeout      = int.Parse(_xmppLink[idx][3]);
                        //check the UI
                        var itemIdx = lbExtSimLinks.FindStringExact(_xmppLink[idx][0]);
                        lbExtSimLinks.SetItemChecked(itemIdx, true);
                    }
                }


                if (execute)
                {
                    btnStartSims_Click(this, null);
                }
            }
        }