public void log(string t, bool response, int level)
        {
            LogLine l;
            bool update = false;
            if (logM105 && t.IndexOf("M105") >= 0) return;
            if (useNextLog != null)
            {
                l = useNextLog;
                l.text = t;
                l.response = response;
                l.level = level;
                update = true;
                useNextLog = null;
            }
            else
                l = new LogLine(t, response, level);
            if (logWriter != null)
            {
                if (!response)
                {
                    lock (logWriter)
                    {
                        logWriter.WriteLine("< " + l.text);
                    }
                }
            }
            lock (logList)
            {
                if (l.text.Length > 0 && l.text[l.text.Length - 1] == 27)
                {
                    //useNextLog = l;
                    l.text = l.text.Substring(0, l.text.Length - 1);
                }
                if (!update) logList.AddLast(l);
            }
            if (logList.Count > maxLogLines)
            {
                LogLine removed = null;
                lock (logList)
                {
                    removed = logList.First.Value;
                    logList.RemoveFirst();
                }
                /* if (eventLogRemoveLast!=null)
                 {
                     try
                     {
                         Main.main.Invoke(eventLogRemoveLast, removed);
                     }
                     catch { } // Closing the app can cause an exception, if event comes after Main handle is destroyed
                 }*/
            }
            if (!update /*&& eventLogAppend!=null*/)
                try
                {
                    lock (newLogs)
                    {
                        newLogs.AddLast(l);
                    }
                    //Main.main.Invoke(eventLogAppend, l);
                }
                catch { } // Closing the app can cause an exception, if event comes after Main handle is destroyed

            if (update && eventLogUpdate != null)
                try
                {
                    Main.main.Invoke(eventLogUpdate, l);
                }
                catch { } // Closing the app can cause an exception, if event comes after Main handle is destroyed
        }
Example #2
0
 public void Add(LogLine l)
 {
     if(!hasFocus)
         while (lines.Count >= maxLines)
         {
             _row--;
             selRow--;
             lines.RemoveAt(0);
         }
     lines.Add(l);
 }
Example #3
0
 private void DrawRow(Graphics g, int line, LogLine logline, float y)
 {
     int p = logline.text.IndexOf(" : ");
     string time = "", text = "";
     if (p < 0)
         text = logline.text;
     else
     {
         time = logline.text.Substring(0, p);
         text = logline.text.Substring(p + 3);
     }
     Brush fontBrush = normalBrush;
     Brush bgBrush = ((line & 1)!=0 ? evenBackBrush : backBrush);
     if (hasFocus && line >= Math.Min(row, selRow) && line <= Math.Max(row, selRow))
     { // mark selection
         bgBrush = selectionBrush;
         fontBrush = selectionTextBrush;
     }
     else
     {
         switch (logline.level)
         {
             case 0:
                 fontBrush = normalBrush;
                 break;
             case 1:
                 fontBrush = warningBrush;
                 break;
             case 2:
                 fontBrush = errorBrush;
                 break;
             case 3:
                 fontBrush = infoBrush;
                 break;
             case 4:
                 fontBrush = normalBrush;
                 break;
         }
     }
     g.FillRectangle(bgBrush, linesWidth, y, log.Width-linesWidth, fontHeight);
     g.DrawString(text, drawFont, fontBrush, linesWidth+4, y);
     g.DrawString(time, drawFont, linesTextColor, linesWidth - 3 - fontWidth * time.Length, y);
 }
Example #4
0
 private void logUpdate(LogLine line)
 {
     logAppend(line);
     listLog.UpdateBox();
 }
Example #5
0
 private void logAppend(LogLine line)
 {
     if (switchACK.On == false && isAck(line.text)) return;
     if (line.level == 0 && line.response==false && switchCommandsSend.On == false) return;
     if (line.level == 1 && switchWarnings.On == false) return;
     if (line.level == 2 && switchErrors.On == false) return;
     if (line.level == 3 && switchInfo.On == false) return;
     listLog.Add(line);
 }
Example #6
0
 private void logAppend(LogLine line)
 {
     if (toolACK.Checked == false && isAck(line.text)) return;
     if (line.level == 0 && line.response==false && toolSend.Checked == false) return;
     if (line.level == 1 && toolWarning.Checked == false) return;
     if (line.level == 2 && toolErrors.Checked == false) return;
     if (line.level == 3 && toolInfo.Checked == false) return;
     listLog.Add(line);
 }
Example #7
0
 private void logAppend(LogLine line)
 {
     if (toolACK.Checked == false && (line.text.StartsWith("ok") || line.text.StartsWith("wait"))) return;
     if (line.level == 0 && line.response==false && toolSend.Checked == false) return;
     if (line.level == 1 && toolWarning.Checked == false) return;
     if (line.level == 2 && toolErrors.Checked == false) return;
     if (line.level == 3 && toolInfo.Checked == false) return;
     ListViewItem item = new ListViewItem(line.text);
     item.Tag = line;
     switch(line.level) {
         case 0:
         case 4:
             item.BackColor = Color.White;
             break;
         case 1:
             item.BackColor = warningColor;
             break;
         case 2:
             item.BackColor = errorColor;
             item.ForeColor = Color.Black;
             break;
         case 3:
             item.BackColor = infoColor;
             break;
     }
     listLog.Items.Add(item);
     if (toolAutoscroll.Checked)
     {
         listLog.EnsureVisible(listLog.Items.Count - 1);
     }
 }
Example #8
0
 private void logUpdate(LogLine line)
 {
     listLog.Items.RemoveAt(listLog.Items.Count - 1);
     logAppend(line);
 }