Exemplo n.º 1
0
        public void ProcessLog(string Data)
        {
            TextReader LogTextReader = new StringReader(Data);
            string     CurLine;
            int        i          = 0;
            DateTime   StartOfDay = DateTime.MinValue;
            DateTime   Timestamp  = DateTime.MinValue;

            while ((CurLine = LogTextReader.ReadLine()) != null)
            {
                if (CurLine.Substring(0, 1) == "#")
                {
                    if (CurLine.Substring(0, 15) == "# Opened (UTC):")
                    {
                        string DayStr = CurLine.Substring(16);
                        StartOfDay = Convert.ToDateTime(DayStr.Substring(0, DayStr.IndexOf(' ')));
                    }
                    // Is a comment
                }
                else
                {
                    string TimeNum = CurLine.Substring(0, CurLine.IndexOf(' '));
                    Timestamp = StartOfDay.AddMilliseconds(Convert.ToDouble(TimeNum));
                    // The will return the number of whole Config.Resolution chunks that have passed since Jan 1 2014.
                    uint TimeframeID = (uint)(((Timestamp - new DateTime(2014, 1, 1)).TotalSeconds) / Config.Resolution);
                    CurLine = CurLine.Substring(TimeNum.Length + 1);
                    if (CurLine.Substring(0, 1) == ":")
                    {
                        CurLine = CurLine.Substring(1);
                        string[] ParameterSplit = CurLine.Split(" ".ToCharArray(), 3, StringSplitOptions.RemoveEmptyEntries);
                        Sender   Sender         = IRCFunctions.ParseSender(ParameterSplit[0]);
                        string   Command        = ParameterSplit[1];
                        string   Parameters     = ParameterSplit[2];
                        Network.Parse(Timestamp, TimeframeID, Sender, Command, Parameters);
                    }
                    else if (CurLine.Substring(0, 4) == "PING")
                    {
                        // Do anything here?
                    }
                    else
                    {
                        AppLog.WriteLine(5, "DEBUG", "Unknown Line Format: " + CurLine);
                    }
                }
                i++;
            }
        }
Exemplo n.º 2
0
        private void RunModel()
        {
            string CurLine;

            string[] Fields;
            int      Frame  = 0;
            string   Delims = " ";

            char[] FieldDelims = Delims.ToCharArray();
            bool   Once        = true;

            btnRun.Enabled       = false;
            btnStop.Enabled      = true;
            udFrameCount.Enabled = false;
            menuModelRun.Enabled = false;

            mRunning         = false;
            sbTextPanel.Text = "Running";
            Log("Starting simulation");
            Log("Current path is: " + Directory.GetCurrentDirectory());

            Log("Module directory: \"" + ModuleDirectory + "\"");
            Log("Input directory: \"" + InputDirectory + "\"");
            Log("Output directory: \"" + OutputDirectory + "\"");
            Log("Model configuration: \"" + DiagramFile + "\"");
            Log("Module parameters: \"" + ParameterFile + "\"");
            Log("Beginning simulation\n");
            while (true)
            {
                CurLine = mExecutionProcess.StandardOutput.ReadLine();
                if ((CurLine != null) && (CurLine.IndexOf("Error") > 0))
                {
                    Log(CurLine);
                }
                else
                {
                    if ((CurLine != null) && (CurLine.StartsWith("  Starting Frame ")))
                    {
                        Fields            = CurLine.Split(FieldDelims);
                        Frame             = Int32.Parse(Fields[Fields.Length - 1]);
                        progressBar.Value = Frame;
                        sbTextPanel.Text  = "Running: Frame " + Frame.ToString() + "/" + mFrameCount.Value.ToString();
                    }
                }
                if (Frame < 2)
                {
                    Log(CurLine);
                }
                else
                {
                    if (Once)
                    {
                        Once = false;
                        Log("Simulation running, please wait");
                    }
                }
                if (mExecutionProcess.HasExited)
                {
                    break;
                }
            }
            progressBar.Value   = progressBar.Maximum;
            progressBar.Visible = false;
            if (mExecutionProcess.ExitCode != 0)
            {
                Log("Simulation completed with errors");
            }
            else
            {
                Log("Simulation complete");
            }
            Log("Ready");

            btnRun.Enabled       = true;
            btnStop.Enabled      = false;
            btnAbort.Enabled     = false;
            udFrameCount.Enabled = true;
            UpdateStatusDisplay();
            udFrameCount.Focus();
            mRunning             = false;
            menuModelRun.Enabled = true;
            if (RunningFromCommandLineInput)
            {
                Application.Exit();
            }
        }