예제 #1
0
        /// <summary>
        /// Writes a message to the panel that this PanelHandler keeps a reference to
        /// </summary>
        /// <param name="message">The message string we want to write.</param>
        public void WriteDelayedMessage(string message)
        {
            if (!String.IsNullOrEmpty(message))
            {
                //If the PanelHandler is printing progress text, then remove the last line of this progress text so we can update it with new progress count text:
                if (new Regex(@"[a-z]{8}\:\s{1}\d{1,3}\%", RegexOptions.IgnoreCase).Match(message).Success)
                {
                    RemoveLastLine(@"[a-z]{8}\:\s{1}\d{1,3}\%");
                }
                //If the PanelHandler is printing progress text, then remove the last line of this progress text so we can update it with new progress count text:
                if (new Regex(@"\d{1,3}\s{1}\%\s{1}[a-z]{8}", RegexOptions.IgnoreCase).Match(message).Success)
                {
                    RemoveLastLine(@"\d{1,3}\s{1}\%\s{1}[a-z]{8}");
                }
                if (StatusUpdateList != null)
                {
                    string statusMessage = StatusUpdateList.Where(m => message.Trim().ToLower().Contains(m.Trim().ToLower())).FirstOrDefault();
                    if (!String.IsNullOrEmpty(statusMessage) && StatusHandler != null)
                    {
                        string successComparer = !String.IsNullOrEmpty(StatusSuccessString) ? StatusSuccessString.ToLower() : String.Empty;
                        StatusHandler.PrintStatus(statusMessage, statusMessage.ToLower() == successComparer ? Status.Success : Status.InProgress);
                        StatusStepEvent(StatusUpdateList.FindIndex(m => m.ToLower().Trim() == statusMessage.ToLower()));
                    }
                }

                int    msgLength = message.TrimEnd().Length;
                string outText;
                if (message == "PS>" || message == "\nPS>" || msgLength == 0)
                {
                    outText = message;
                }
                else
                {
                    outText = message.Substring(0, msgLength);
                    if (outText[outText.Length - 1] != '\n')
                    {
                        outText += "\n";
                    }
                }
                foreach (char c in outText)
                {
                    if (TheTextBox.InvokeRequired)
                    {
                        // It's on a different thread, so use Invoke.
                        lock (m_LockObject) {
                            PrintTextCallback ourDelegate = new PrintTextCallback(printText);
                            TheTextBox.Invoke(ourDelegate, new object[] { c, TheTextBox, TextColor });
                        }
                    }
                    else
                    {
                        lock (m_LockObject) {
                            // It's on the same thread, no need for Invoke
                            TheTextBox.AppendText(c.ToString(), TextColor);
                        }
                    }
                    Thread.Sleep(PrintDelay);
                }
            }
        }
 public void AddMsg(string msg)
 {
     if (TheTextBox.InvokeRequired == false)
     {
         TheTextBox.AppendText(msg);
     }
     else
     {
         var addMsg = new AddMsgDelegate(AddMsg);
         try
         {
             Invoke(addMsg, msg);
         }
         catch
         {
             Thread.Sleep(1000);
             Invoke(addMsg, msg);
         }
     }
 }