Exemple #1
0
        private void FindRichTextBoxAndSendTheMessage(string logMessage, RichTextBoxRowColoringRule rule)
        {
            Form form        = null;
            bool createdForm = false;

            if (Form.ActiveForm != null && Form.ActiveForm.Name == FormName)
            {
                form = Form.ActiveForm;
            }

#if DOTNET_2_0
            if (form == null && Application.OpenForms[FormName] != null)
            {
                form = Application.OpenForms[FormName];
            }
#endif
            if (form == null)
            {
                form        = FormHelper.CreateForm(FormName, 0, 0, true);
                createdForm = true;
            }

            RichTextBox rtbx = (RichTextBox)FormHelper.FindControl(ControlName, form, typeof(RichTextBox));

            if (rtbx == null && createdForm)
            {
                rtbx = FormHelper.CreateRichTextBox(ControlName, form);
            }
            else if (rtbx == null && !createdForm)
            {
                return;
            }

            rtbx.Invoke(new DelSendTheMessageToRichTextBox(SendTheMessageToRichTextBox), new object[] { rtbx, logMessage, rule });
        }
Exemple #2
0
        /// <summary>
        /// Log message to RichTextBox.
        /// </summary>
        /// <param name="logEvent">The logging event.</param>
        protected override void Write(LogEventInfo logEvent)
        {
            RichTextBoxRowColoringRule matchingRule = null;

            foreach (RichTextBoxRowColoringRule rr in this.RowColoringRules)
            {
                if (rr.CheckCondition(logEvent))
                {
                    matchingRule = rr;
                    break;
                }
            }

            if (this.UseDefaultRowColoringRules && matchingRule == null)
            {
                foreach (RichTextBoxRowColoringRule rr in DefaultRowColoringRules)
                {
                    if (rr.CheckCondition(logEvent))
                    {
                        matchingRule = rr;
                        break;
                    }
                }
            }

            if (matchingRule == null)
            {
                matchingRule = RichTextBoxRowColoringRule.Default;
            }

            string logMessage = this.Layout.Render(logEvent);

            this.TargetRichTextBox.BeginInvoke(new DelSendTheMessageToRichTextBox(this.SendTheMessageToRichTextBox), new object[] { logMessage, matchingRule });
        }
 /// <summary>
 /// Adds the elements of an array to the end of this RichTextBoxRowColoringRuleCollection.
 /// </summary>
 /// <param name="items">
 /// The array whose elements are to be added to the end of this RichTextBoxRowColoringRuleCollection.
 /// </param>
 public virtual void AddRange(RichTextBoxRowColoringRule[] items)
 {
     foreach (RichTextBoxRowColoringRule item in items)
     {
         this.List.Add(item);
     }
 }
Exemple #4
0
        /// <summary>
        /// Log message to RichTextBox
        /// </summary>
        /// <param name="logEvent">The logging event.</param>
        protected internal override void Write(LogEventInfo logEvent)
        {
            RichTextBoxRowColoringRule matchingRule = null;

            foreach (RichTextBoxRowColoringRule rr in RowColoringRules)
            {
                if (rr.CheckCondition(logEvent))
                {
                    matchingRule = rr;
                    break;
                }
            }

            if (UseDefaultRowColoringRules && matchingRule == null)
            {
                foreach (RichTextBoxRowColoringRule rr in _defaultRichTextBoxRowColoringRules)
                {
                    if (rr.CheckCondition(logEvent))
                    {
                        matchingRule = rr;
                        break;
                    }
                }
            }

            if (matchingRule == null)
            {
                matchingRule = RichTextBoxRowColoringRule.Default;
            }

            string logMessage = CompiledLayout.GetFormattedMessage(logEvent);

            FindRichTextBoxAndSendTheMessage(logMessage, matchingRule);
        }
Exemple #5
0
        private void SendTheMessageToRichTextBox(string logMessage, RichTextBoxRowColoringRule rule)
        {
            RichTextBox rtbx = this.TargetRichTextBox;

            int startIndex = rtbx.Text.Length;

            rtbx.SelectionStart     = startIndex;
            rtbx.SelectionBackColor = GetColorFromString(rule.BackgroundColor, rtbx.BackColor);
            rtbx.SelectionColor     = GetColorFromString(rule.FontColor, rtbx.ForeColor);
            rtbx.SelectionFont      = new Font(rtbx.SelectionFont, rtbx.SelectionFont.Style ^ rule.Style);
            rtbx.AppendText(logMessage + "\n");
            rtbx.SelectionLength = rtbx.Text.Length - rtbx.SelectionStart;

            // find word to color
            foreach (RichTextBoxWordColoringRule wordRule in this.WordColoringRules)
            {
                MatchCollection mc = wordRule.CompiledRegex.Matches(rtbx.Text, startIndex);
                foreach (Match m in mc)
                {
                    rtbx.SelectionStart     = m.Index;
                    rtbx.SelectionLength    = m.Length;
                    rtbx.SelectionBackColor = GetColorFromString(wordRule.BackgroundColor, rtbx.BackColor);
                    rtbx.SelectionColor     = GetColorFromString(wordRule.FontColor, rtbx.ForeColor);
                    rtbx.SelectionFont      = new Font(rtbx.SelectionFont, rtbx.SelectionFont.Style ^ wordRule.Style);
                }
            }

            if (this.MaxLines > 0)
            {
                this.lineCount++;
                if (this.lineCount > this.MaxLines)
                {
                    int pos = rtbx.GetFirstCharIndexFromLine(1);
                    rtbx.Select(0, pos);
                    rtbx.SelectedText = string.Empty;
                    this.lineCount--;
                }
            }

            if (this.AutoScroll)
            {
                rtbx.Select(rtbx.TextLength, 0);
                rtbx.ScrollToCaret();
            }
        }
Exemple #6
0
        /// <summary>
        /// Log message to RichTextBox.
        /// </summary>
        /// <param name="logEvent">The logging event.</param>
        protected override void Write(LogEventInfo logEvent)
        {
            RichTextBoxRowColoringRule matchingRule = null;

            foreach (RichTextBoxRowColoringRule rr in this.RowColoringRules)
            {
                if (rr.CheckCondition(logEvent))
                {
                    matchingRule = rr;
                    break;
                }
            }

            if (this.UseDefaultRowColoringRules && matchingRule == null)
            {
                foreach (RichTextBoxRowColoringRule rr in DefaultRowColoringRules)
                {
                    if (rr.CheckCondition(logEvent))
                    {
                        matchingRule = rr;
                        break;
                    }
                }
            }

            if (matchingRule == null)
            {
                matchingRule = RichTextBoxRowColoringRule.Default;
            }

            string logMessage = this.Layout.Render(logEvent);

            this.TargetRichTextBox.Invoke(new DelSendTheMessageToRichTextBox(this.SendTheMessageToRichTextBox), new object[] { logMessage, matchingRule });
            //System.Windows.Application.Current.MainWindow.Dispatcher.Invoke(new Action(() =>
            //    {
            //        SendTheMessageToRichTextBox(logMessage, matchingRule);
            //    }));
        }
 /// <summary>
 /// Initializes static members of the RichTextBoxRowColoringRule class.
 /// </summary>
 static RichTextBoxRowColoringRule()
 {
     Default = new RichTextBoxRowColoringRule();
 }
 /// <summary>
 /// Initializes static members of the RichTextBoxRowColoringRule class.
 /// </summary>
 static RichTextBoxRowColoringRule()
 {
     Default = new RichTextBoxRowColoringRule(null, "Empty", "Empty");
 }
 /// <summary>
 /// Initializes a new instance of the RichTextBoxRowColoringRuleCollection class, containing elements
 /// copied from an array.
 /// </summary>
 /// <param name="items">
 /// The array whose elements are to be added to the new RichTextBoxRowColoringRuleCollection.
 /// </param>
 public RichTextBoxRowColoringRuleCollection(RichTextBoxRowColoringRule[] items)
 {
     this.AddRange(items);
 }
 /// <summary>
 /// Removes the first occurrence of a specific RichTextBoxRowColoringRule from this RichTextBoxRowColoringRuleCollection.
 /// </summary>
 /// <param name="value">
 /// The RichTextBoxRowColoringRule value to remove from this RichTextBoxRowColoringRuleCollection.
 /// </param>
 public virtual void Remove(RichTextBoxRowColoringRule value)
 {
     this.List.Remove(value);
 }
 /// <summary>
 /// Inserts an element into the RichTextBoxRowColoringRuleCollection at the specified index
 /// </summary>
 /// <param name="index">
 /// The index at which the RichTextBoxRowColoringRule is to be inserted.
 /// </param>
 /// <param name="value">
 /// The RichTextBoxRowColoringRule to insert.
 /// </param>
 public virtual void Insert(int index, RichTextBoxRowColoringRule value)
 {
     this.List.Insert(index, value);
 }
 /// <summary>
 /// Return the zero-based index of the first occurrence of a specific value
 /// in this RichTextBoxRowColoringRuleCollection
 /// </summary>
 /// <param name="value">
 /// The RichTextBoxRowColoringRule value to locate in the RichTextBoxRowColoringRuleCollection.
 /// </param>
 /// <returns>
 /// The zero-based index of the first occurrence of the _ELEMENT value if found;
 /// -1 otherwise.
 /// </returns>
 public virtual int IndexOf(RichTextBoxRowColoringRule value)
 {
     return this.List.IndexOf(value);
 }
 /// <summary>
 /// Determines whether a specfic RichTextBoxRowColoringRule value is in this RichTextBoxRowColoringRuleCollection.
 /// </summary>
 /// <param name="value">
 /// The RichTextBoxRowColoringRule value to locate in this RichTextBoxRowColoringRuleCollection.
 /// </param>
 /// <returns>
 /// true if value is found in this RichTextBoxRowColoringRuleCollection;
 /// false otherwise.
 /// </returns>
 public virtual bool Contains(RichTextBoxRowColoringRule value)
 {
     return this.List.Contains(value);
 }
 /// <summary>
 /// Adds an instance of type RichTextBoxWordColoringRule to the end of this RichTextBoxRowColoringRuleCollection.
 /// </summary>
 /// <param name="value">
 /// The RichTextBoxRowColoringRule to be added to the end of this RichTextBoxRowColoringRuleCollection.
 /// </param>
 public virtual void Add(RichTextBoxRowColoringRule value)
 {
     this.List.Add(value);
 }
		private void SendTheMessageToRichTextBox(RichTextBox rtbx, string logMessage, RichTextBoxRowColoringRule rule) {
			int startIndex = rtbx.TextLength;
			rtbx.SelectionStart = startIndex;
			rtbx.SelectionBackColor = GetColorFromString(rule.BackgroundColor, rtbx.BackColor);
			rtbx.SelectionColor = GetColorFromString(rule.FontColor, rtbx.ForeColor);
			rtbx.SelectionFont = new Font(rtbx.SelectionFont, rtbx.SelectionFont.Style ^ rule.Style);
			rtbx.AppendText(logMessage + "\n");
			int newLength = rtbx.TextLength;

			if (newLength > _maxLength) {
				rtbx.ReadOnly = false;
				rtbx.Select(0, newLength - (int)(_maxLength * 0.8));
				rtbx.SelectedText = "";
				rtbx.ReadOnly = true;
			}

			// find word to color
			//foreach (RichTextBoxWordColoringRule wordRule in WordColoringRules)
			//{
			//    MatchCollection mc = wordRule.CompiledRegex.Matches(rtbx.Text, startIndex);
			//    foreach (Match m in mc)
			//    {
			//        rtbx.SelectionStart = m.Index;
			//        rtbx.SelectionLength = m.Length;
			//        rtbx.SelectionBackColor = GetColorFromString(wordRule.BackgroundColor, rtbx.BackColor);
			//        rtbx.SelectionColor = GetColorFromString(wordRule.FontColor, rtbx.ForeColor);
			//        rtbx.SelectionFont = new Font(rtbx.SelectionFont, rtbx.SelectionFont.Style ^ wordRule.Style);
			//    }
			//}

			ScrollTextBoxEnd(rtbx);
		}
Exemple #16
0
        private void FindRichTextBoxAndSendTheMessage(string logMessage, RichTextBoxRowColoringRule rule)
        {
            Form form = null;
            bool createdForm = false;

            if (Form.ActiveForm != null && Form.ActiveForm.Name == this.FormName)
            {
                form = Form.ActiveForm;
            }

            if (form == null && Application.OpenForms[this.FormName] != null)
            {
                form = Application.OpenForms[this.FormName];
            }

            if (form == null)
            {
                form = FormHelper.CreateForm(this.FormName, 0, 0, true);
                createdForm = true;
            }

            RichTextBox rtbx = (RichTextBox)FormHelper.FindControl(this.ControlName, form, typeof(RichTextBox));

            if (rtbx == null && createdForm)
            {
                rtbx = FormHelper.CreateRichTextBox(this.ControlName, form);
            }
            else if (rtbx == null && !createdForm)
            {
                return;
            }

            rtbx.Invoke(new DelSendTheMessageToRichTextBox(this.SendTheMessageToRichTextBox), new object[] { rtbx, logMessage, rule });
        }
Exemple #17
0
 /// <summary>
 /// Initializes static members of the RichTextBoxRowColoringRule class.
 /// </summary>
 static RichTextBoxRowColoringRule()
 {
     Default = new RichTextBoxRowColoringRule();
 }
Exemple #18
0
        private void SendTheMessageToRichTextBox(RichTextBox rtbx, string logMessage, RichTextBoxRowColoringRule rule)
        {
            int startIndex = rtbx.Text.Length;
            rtbx.SelectionStart = startIndex;
            rtbx.SelectionBackColor = this.GetColorFromString(rule.BackgroundColor, rtbx.BackColor);
            rtbx.SelectionColor = this.GetColorFromString(rule.FontColor, rtbx.ForeColor);
            rtbx.SelectionFont = new Font(rtbx.SelectionFont, rtbx.SelectionFont.Style ^ rule.Style);
            rtbx.AppendText(logMessage + "\n");
            rtbx.SelectionLength = rtbx.Text.Length - rtbx.SelectionStart;

            // find word to color
            foreach (RichTextBoxWordColoringRule wordRule in this.WordColoringRules)
            {
                MatchCollection mc = wordRule.CompiledRegex.Matches(rtbx.Text, startIndex);
                foreach (Match m in mc)
                {
                    rtbx.SelectionStart = m.Index;
                    rtbx.SelectionLength = m.Length;
                    rtbx.SelectionBackColor = this.GetColorFromString(wordRule.BackgroundColor, rtbx.BackColor);
                    rtbx.SelectionColor = this.GetColorFromString(wordRule.FontColor, rtbx.ForeColor);
                    rtbx.SelectionFont = new Font(rtbx.SelectionFont, rtbx.SelectionFont.Style ^ wordRule.Style);
                }
            }
        }
        private void SendTheMessageToRichTextBox(string logMessage, RichTextBoxRowColoringRule rule)
        {
            RichTextBox rtbx = this.TargetRichTextBox;

            int startIndex = rtbx.Text.Length;
            rtbx.SelectionStart = startIndex;
            rtbx.SelectionBackColor = GetColorFromString(rule.BackgroundColor, rtbx.BackColor);
            rtbx.SelectionColor = GetColorFromString(rule.FontColor, rtbx.ForeColor);
            rtbx.SelectionFont = new Font(rtbx.SelectionFont, rtbx.SelectionFont.Style ^ rule.Style);
            rtbx.AppendText(logMessage + "\n");
            rtbx.SelectionLength = rtbx.Text.Length - rtbx.SelectionStart;

            // find word to color
            foreach (RichTextBoxWordColoringRule wordRule in this.WordColoringRules)
            {
                MatchCollection mc = wordRule.CompiledRegex.Matches(rtbx.Text, startIndex);
                foreach (Match m in mc)
                {
                    rtbx.SelectionStart = m.Index;
                    rtbx.SelectionLength = m.Length;
                    rtbx.SelectionBackColor = GetColorFromString(wordRule.BackgroundColor, rtbx.BackColor);
                    rtbx.SelectionColor = GetColorFromString(wordRule.FontColor, rtbx.ForeColor);
                    rtbx.SelectionFont = new Font(rtbx.SelectionFont, rtbx.SelectionFont.Style ^ wordRule.Style);
                }
            }

            if (this.MaxLines > 0)
            {
                this.lineCount++;
                if (this.lineCount > this.MaxLines)
                {
                    int pos = rtbx.GetFirstCharIndexFromLine(1);
                    rtbx.Select(0, pos);
                    rtbx.SelectedText = string.Empty;
                    this.lineCount--;
                }
            }

            if (this.AutoScroll)
            {
                rtbx.Select(rtbx.TextLength, 0);
                rtbx.ScrollToCaret();
            }
        }
Exemple #20
0
        private void SendTheMessageToRichTextBox(RichTextBox rtbx, string logMessage, RichTextBoxRowColoringRule rule)
        {
            int startIndex = rtbx.Text.Length;

            rtbx.SelectionStart = startIndex;
#if DOTNET_2_0
            rtbx.SelectionBackColor = GetColorFromString(rule.BackgroundColor, rtbx.BackColor);
#endif
            rtbx.SelectionColor = GetColorFromString(rule.FontColor, rtbx.ForeColor);
            rtbx.SelectionFont  = new Font(rtbx.SelectionFont, rtbx.SelectionFont.Style ^ rule.Style);
            rtbx.AppendText(logMessage + "\n");
            rtbx.SelectionLength = rtbx.Text.Length - rtbx.SelectionStart;

            // find word to color
            foreach (RichTextBoxWordColoringRule wordRule in WordColoringRules)
            {
                MatchCollection mc = wordRule.CompiledRegex.Matches(rtbx.Text, startIndex);
                foreach (Match m in mc)
                {
                    rtbx.SelectionStart  = m.Index;
                    rtbx.SelectionLength = m.Length;
#if DOTNET_2_0
                    rtbx.SelectionBackColor = GetColorFromString(wordRule.BackgroundColor, rtbx.BackColor);
#endif
                    rtbx.SelectionColor = GetColorFromString(wordRule.FontColor, rtbx.ForeColor);
                    rtbx.SelectionFont  = new Font(rtbx.SelectionFont, rtbx.SelectionFont.Style ^ wordRule.Style);
                }
            }
        }
		private void FindRichTextBoxAndSendTheMessage(string logMessage, RichTextBoxRowColoringRule rule) {
			if (_control != null)
				_control.Invoke(new DelSendTheMessageToRichTextBox(SendTheMessageToRichTextBox), new object[] { _control, logMessage, rule });
		}