Exemplo n.º 1
0
        public void recordMessage(string message, Exception ex, int type)
        {
            int    i = ex.StackTrace.IndexOf("行号");
            string s = ex.StackTrace.Substring(i + 3);

            i = s.IndexOf(' ');
            if (i != -1)
            {
                s = s.Substring(0, i).Trim();
            }
            if (RTB_Log.Lines.Count() > 500)
            {
                BeginInvoke((MethodInvoker) delegate() { RTB_Log.Clear(); });
            }
            BeginInvoke((MethodInvoker) delegate() { RTB_Log.Text = RTB_Log.Text.Insert(0, DateTime.Now.ToString("yy/MM/dd-HH:mm:ss") + "  :  " + message + Environment.NewLine); });
            if (type == 0)
            {
                Log.InformationLog.Info(message + " 行号:" + s);           //0表示正常数据
            }
            else if (type == 1)
            {
                Log.InformationLog.Error(message + " 行号:" + s);                //1表示错误
            }
            else if (type == 2)
            {
                Log.InformationLog.Fatal(message + " 行号:" + s);                //2表示产生数据
            }
            else if (type == 3)
            {
                Log.InformationLog.Debug(message + " 行号:" + s);                //3表示系统BUG
            }
        }
Exemplo n.º 2
0
 public void recordMessage(string name, string message, int type)
 {
     if (type == 1)
     {
         Log.InformationLog.Error(message);           //1表示错误
     }
     else
     {
         Log.InformationLog.Info(message);
     }
     BeginInvoke((MethodInvoker) delegate()
     {
         if (RTB_Log.Lines.Count() > 500)
         {
             RTB_Log.Clear();
         }
     });
     BeginInvoke((MethodInvoker) delegate() { RTB_Log.Text = RTB_Log.Text.Insert(0, DateTime.Now.ToString("yy/MM/dd-HH:mm:ss") + "  :  " + message + Environment.NewLine); });
 }
Exemplo n.º 3
0
        private void BTN_BatchRun_Click(object sender, EventArgs e)
        {
            if (BTN_BatchRun.Text == "Run Batch")
            {
                batchrunning = true;
                if (LB_Batch.SelectedIndex == 0)
                {
                    LB_Batch_SelectedIndexChanged(this, null);
                }
                else
                {
                    LB_Batch.SelectedIndex = 0;
                }
                BTN_BatchRun.Text = "Stop Batch Run";
                LB_Batch.Enabled  = false;
                foreach (Button b in PAN_Buttons.Controls)
                {
                    if (!(b == BTN_BatchRun || b == BTN_Close))
                    {
                        b.Enabled = false;
                    }
                }
            }
            else
            {
                batchrunning = false;
                parent.listenTimer.Enabled = false;
                parent.listening           = false;
                RTB_Log.AppendText("Aborted.\r\n\r\n");

                BTN_BatchRun.Text = "Run Batch";
                LB_Batch.Enabled  = true;
                foreach (Button b in PAN_Buttons.Controls)
                {
                    b.Enabled = true;
                }
            }
        }
Exemplo n.º 4
0
        public void UpdateLog()
        {
            bool pass  = true;
            bool check = false;

            foreach (DataRow dr in parent.listenList.Rows)
            {
                if (dr["Result"].ToString() != "")
                {
                    string result      = "PASS";
                    Color  resultcolor = Color.LightGreen;
                    if (!dr["Pass"].ToString().Contains("0"))
                    {
                        result      = "\r\nPASS:"******"Pass"].ToString().Contains("1"))
                    {
                        result      = "\r\nFAIL:";
                        resultcolor = Color.LightCoral;
                        pass        = false;
                    }
                    else
                    {
                        result      = "\r\nCHECK:";
                        resultcolor = Color.Yellow;
                        check       = true;
                    }
                    result += "\r\n\tExpected result: (0x" + dr["Key"] + ")" + dr["Name"] + ": " + dr["Value"] + "\r\n";
                    int selstart = RTB_Log.TextLength;
                    RTB_Log.AppendText(result);
                    int selend = RTB_Log.TextLength;

                    RTB_Log.Select(selstart, selend - selstart);
                    RTB_Log.SelectionBackColor = resultcolor;

                    string[] results    = dr["Result"].ToString().Split('\t');
                    string[] passes     = dr["Pass"].ToString().Split(';');
                    string[] timestamps = dr["TimeStamp"].ToString().Split(';');
                    for (int i = 1; i < results.Length; i++)
                    {
                        selstart    = RTB_Log.TextLength;
                        resultcolor = passes[i] == "1" ? Color.LightGreen : Color.LightCoral;
                        RTB_Log.AppendText(timestamps[i] + "\t" + results[i]);
                        selend = RTB_Log.TextLength;
                        RTB_Log.Select(selstart, selend - selstart);
                        RTB_Log.SelectionBackColor = resultcolor;
                    }
                }
                else
                {
                    int selstart = RTB_Log.TextLength;
                    RTB_Log.AppendText("FAIL:\r\n" + DateTime.Now.ToString("MMddyy hh:mm:ss") + "\t(0x" + dr["Key"] + ")" + dr["Name"] + " not received in " + TB_Wait.Text + "ms\r\n");
                    int selend = RTB_Log.TextLength;
                    RTB_Log.Select(selstart, selend - selstart);
                    RTB_Log.SelectionBackColor = dr["Result"].ToString().StartsWith("PASS") ? Color.LightGreen : Color.LightCoral;
                    pass = false;
                }
                RTB_Log.SelectionLength = 0;
            }
            RTB_Log.AppendText("Done.  Overall Result = ");
            int    start       = RTB_Log.TextLength;
            string overalltext = check && pass ? "CHECK" : "PASS";

            overalltext = pass ? overalltext : "FAIL";
            RTB_Log.AppendText(overalltext + "\r\n\r\n");
            int end = RTB_Log.TextLength;

            RTB_Log.Select(start, end - start);
            Color overallcolor = check && pass ? Color.Yellow : Color.LightGreen;

            overallcolor = pass ? overallcolor : Color.LightCoral;
            RTB_Log.SelectionBackColor = overallcolor;
            RTB_Log.SelectionLength    = 0;
            RTB_Log.ScrollToCaret();
            if (batchrunning || BTN_Run.Text == "Stop")
            {
                if (LB_Batch.SelectedIndex < LB_Batch.Items.Count - 1 && BTN_Run.Text != "Stop")
                {
                    LB_Batch.SelectedIndex++;
                }
                else
                {
                    batchrunning               = false;
                    parent.listening           = false;
                    parent.listenTimer.Enabled = false;
                    BTN_BatchRun.Text          = "Run Batch";
                    BTN_Run.Text               = "Run Step";
                    LB_Batch.Enabled           = true;
                    foreach (Button b in PAN_Buttons.Controls)
                    {
                        b.Enabled = true;
                    }
                }
            }
        }
Exemplo n.º 5
0
        private void BTN_Run_Click(object sender, EventArgs e)
        {
            if (BTN_Run.Text == "Run Step")
            {
                string setmsg   = "";
                bool   validcmd = true;
                string sentlist = "";
                foreach (RelationalItem2 r in PAN_Send.Controls)
                {
                    if (r.KVPValue(false) != "")
                    {
                        setmsg   += r.KVPMessage();
                        sentlist += "(0x" + r.KeyValue + ")" + r.KeyName + ": " + r.KVPValue(false) + "\r\n";
                    }
                    else
                    {
                        validcmd = false;
                    }
                }

                /*if (validcmd && setmsg.Length > 0)
                 * {
                 *  parent.SendExternal(setmsg, false, true);
                 * }
                 * else
                 * {
                 *  MessageBox.Show("All command KVPs must have an assigned value.");
                 * }*/
                parent.listenList.Clear();

                foreach (RelationalItem2 r in PAN_Recv.Controls)
                {
                    DataRow dr = parent.listenList.NewRow();
                    dr["Key"]      = r.KeyValue;
                    dr["Name"]     = r.KeyName;
                    dr["Value"]    = r.KVPValue(false);
                    dr["HexValue"] = r.KVPMessage();
                    dr["Result"]   = "";
                    dr["Pass"]     = "";
                    parent.listenList.Rows.Add(dr);
                }

                try
                {
                    //parent.listenUntil = DateTime.Now.AddMilliseconds(int.Parse(TB_Wait.Text));
                    parent.listenTimer.Interval = int.Parse(TB_Wait.Text);
                    if ((validcmd && setmsg.Length > 0) || PAN_Send.Controls.Count == 0)
                    {
                        parent.listening           = true;
                        parent.listenTimer.Enabled = true;
                        bool sent = parent.SendExternal(setmsg, false, true);
                        if (sent)
                        {
                            RTB_Log.AppendText("Running " + TB_Name.Text + "...\r\n\r\n");
                            RTB_Log.AppendText("Sent:\r\n" + sentlist + "\r\n");
                            RTB_Log.AppendText("Waiting " + TB_Wait.Text + "ms for responses...\r\n\r\n");
                            RTB_Log.ScrollToCaret();
                            if (!batchrunning)
                            {
                                BTN_Run.Text     = "Stop";
                                LB_Batch.Enabled = false;
                                foreach (Button b in PAN_Buttons.Controls)
                                {
                                    if (!(b == BTN_Run || b == BTN_Close))
                                    {
                                        b.Enabled = false;
                                    }
                                }
                            }
                        }
                        else
                        {
                            parent.listening           = false;
                            parent.listenTimer.Enabled = false;
                            batchrunning      = false;
                            LB_Batch.Enabled  = true;
                            BTN_Run.Text      = "Run Step";
                            BTN_BatchRun.Text = "Run Batch";
                            foreach (Button b in PAN_Buttons.Controls)
                            {
                                b.Enabled = true;
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("All command KVPs must have an assigned value.");
                    }
                }
                catch
                {
                    MessageBox.Show("Wait time is an invalid value.");
                }
            }
            else
            {
                BTN_Run.Text               = "Run Step";
                parent.listening           = false;
                parent.listenTimer.Enabled = false;
                RTB_Log.AppendText("Aborted.\r\n\r\n");
                LB_Batch.Enabled = true;
                foreach (Button b in PAN_Buttons.Controls)
                {
                    b.Enabled = true;
                }
            }
        }
Exemplo n.º 6
0
 private void RTB_Log_TextChanged(object sender, EventArgs e)
 {
     RTB_Log.SelectionStart = RTB_Log.Text.Length; //Set the current caret position at the end
     RTB_Log.ScrollToCaret();                      //Now scroll it automatically
 }