示例#1
0
        private void PrintMsg(string fromName, string message)
        {
            if (InvokeRequired)
            {
                if (IsHandleCreated)
                {
                    BeginInvoke(new MethodInvoker(() => PrintMsg(fromName, message)));
                }
                return;
            }

            DateTime timestamp = DateTime.Now;

            if (message == null)
            {
                message = string.Empty;
            }

            if (true)
            {
                textPrinter.ForeColor = Color.Gray;
                textPrinter.PrintText(timestamp.ToString("[HH:mm] "));
            }

            textPrinter.ForeColor = Color.Black;

            StringBuilder sb = new StringBuilder();

            if (message.StartsWith("/me "))
            {
                sb.Append(fromName);
                sb.Append(message.Substring(3));
            }
            else
            {
                sb.Append(fromName);
                sb.Append(": ");
                sb.Append(message);
            }

            //instance.LogClientMessage(sessionName + ".txt", sb.ToString());
            textPrinter.PrintTextLine(sb.ToString());
            sb = null;
        }
示例#2
0
 private void doOutput(string str, params object[] args)
 {
     if (str == null)
     {
         return;
     }
     if (args == null || args.Length == 0)
     {
         args = new object[] { str };
         str  = "{0}";
     }
     if (args.Length > 0)
     {
         str = DLRConsole.SafeFormat(str, args);
     }
     str = str.Trim();
     if (str == "")
     {
         return;
     }
     if (!writeLock.IsRunning)
     {
         DLRConsole.SYSTEM_ERR_WRITELINE_REAL("early " + str);
     }
     writeLock.Enqueue(str, () => DLRConsole.InvokeControl(rtbChat, new MethodInvoker(() =>
     {
         try
         {
             string s    = rtbChat.Text;
             int sLength = s.Length;
             if (sLength > 20000)
             {
                 rtbChat.Text =
                     s.Substring(sLength - 20000);
             }
             printer.PrintTextLine(str);
         }
         catch (Exception e)
         {
             DLRConsole.SYSTEM_ERR_WRITELINE_REAL("" + e);
             // probably dead anyway ...
         }
     })));
 }