<commit_before>﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Threading;
using System.Threading;
using System.Media;
using System.Diagnostics;
using System.Windows.Media;
using Controls;
using System.IO;
using System.Text.RegularExpressions;
using System.ComponentModel;
using System.Windows.Input;
using Utilities;
using Microsoft.Diagnostics.Utilities;
using System.Threading.Tasks;

namespace PerfView
{
    /// <summary>
    /// Interaction logic for StatusBar.xaml
    /// </summary>
    public partial class StatusBar : UserControl, INotifyPropertyChanged
    {
        public StatusBar()
        {
            m_blinkColor = new SolidColorBrush(Color.FromRgb(0x42, 0x69, 0xEB));
            m_timer = new DispatcherTimer();
            m_workMessage = "";
            m_timer.Interval = new TimeSpan(0, 0, 0, 0, 600);
            m_timer.Tick += OnTick;

            InitializeComponent();

            m_StatusMessage.PreviewMouseDoubleClick += delegate(object sender, MouseButtonEventArgs e)
            {
                e.Handled = StatusBar.ExpandSelectionByANumber(m_StatusMessage);
                return;
            };
        }

        /// <summary>
        /// Report messages are short messages that are not persisted in the history, these are meant for
        /// messages that are not in direct response to a user command (and thus might be 'noise')
        /// </summary>
        public string Status { get { return m_StatusMessage.Text; } set { m_StatusMessage.Text = value; m_loggedStatus = true; LoggedError = false; } }
        public TimeSpan Duration { get { return DateTime.Now - m_startTime; } }
        /// <summary>
        /// Logging a message on the other hand, is persisted, and can be viewed later.  These should be
        /// used for any messages that are in direct response to an obvious user command (Effectively 
        /// logging what the user did.  
        /// 
        /// This can called by the worker thread, and Log() will insure that it posts the message on the GUI thread
        /// </summary>
        public void Log(string message)
        {
            LogWriter.WriteLine(message);
            System.Threading.Thread.Sleep(0);       // Allow Abort
        }
        /// <summary>
        /// Logs an error message (logs and then beeps).  
        /// </summary>
        /// <param name="errorMessage"></param>
        public void LogError(string errorMessage)
        {
            Log(errorMessage);
            SystemSounds.Beep.Play();
            if (errorMessage.IndexOf('\n') < 0)     // Is it a one line error message?
            {
                if (Dispatcher.CheckAccess())
                    Status = errorMessage;
                else
                    Dispatcher.BeginInvoke((Action)delegate()
                    {
                        Status = errorMessage;
                    });
            }
            LoggedError = true;

            m_StatusMessage.RaiseEvent(new RoutedEventArgs(StatusBar.HighlightMessageEvent, this));
        }

        public static readonly RoutedEvent HighlightMessageEvent = EventManager.RegisterRoutedEvent("HighlightMessage", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(StatusBar));

        public event RoutedEventHandler HighlightMessage
        {
            add { AddHandler(HighlightMessageEvent, value); }
            remove { RemoveHandler(HighlightMessageEvent, value); }
        }

        /// <summary>
        /// Have we just logged an error (last message in status bar is an error message)
        /// </summary>
        public bool LoggedError { get; private set; }
        /// <summary>
        /// returns a TextWriter for the status log.  
        /// </summary>
        public TextWriter LogWriter
        {<commit_msg>Fix error when writing error to status bar<commit_after>﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Threading;
using System.Threading;
using System.Media;
using System.Diagnostics;
using System.Windows.Media;
using Controls;
using System.IO;
using System.Text.RegularExpressions;
using System.ComponentModel;
using System.Windows.Input;
using Utilities;
using Microsoft.Diagnostics.Utilities;
using System.Threading.Tasks;

namespace PerfView
{
    /// <summary>
    /// Interaction logic for StatusBar.xaml
    /// </summary>
    public partial class StatusBar : UserControl, INotifyPropertyChanged
    {
        public StatusBar()
        {
            m_blinkColor = new SolidColorBrush(Color.FromRgb(0x42, 0x69, 0xEB));
            m_timer = new DispatcherTimer();
            m_workMessage = "";
            m_timer.Interval = new TimeSpan(0, 0, 0, 0, 600);
            m_timer.Tick += OnTick;

            InitializeComponent();

            m_StatusMessage.PreviewMouseDoubleClick += delegate(object sender, MouseButtonEventArgs e)
            {
                e.Handled = StatusBar.ExpandSelectionByANumber(m_StatusMessage);
                return;
            };
        }

        /// <summary>
        /// Report messages are short messages that are not persisted in the history, these are meant for
        /// messages that are not in direct response to a user command (and thus might be 'noise')
        /// </summary>
        public string Status { get { return m_StatusMessage.Text; } set { m_StatusMessage.Text = value; m_loggedStatus = true; LoggedError = false; } }
        public TimeSpan Duration { get { return DateTime.Now - m_startTime; } }
        /// <summary>
        /// Logging a message on the other hand, is persisted, and can be viewed later.  These should be
        /// used for any messages that are in direct response to an obvious user command (Effectively 
        /// logging what the user did.  
        /// 
        /// This can called by the worker thread, and Log() will insure that it posts the message on the GUI thread
        /// </summary>
        public void Log(string message)
        {
            LogWriter.WriteLine(message);
            System.Threading.Thread.Sleep(0);       // Allow Abort
        }
        /// <summary>
        /// Logs an error message (logs and then beeps).  
        /// </summary>
        /// <param name="errorMessage"></param>
        public void LogError(string errorMessage)
        {
            Log(errorMessage);
            SystemSounds.Beep.Play();
            if (errorMessage.IndexOf('\n') < 0)     // Is it a one line error message?
            {
                if (Dispatcher.CheckAccess())
                {

                    Status = errorMessage;
                    m_StatusMessage.RaiseEvent(new RoutedEventArgs(StatusBar.HighlightMessageEvent, this));
                }
                else
                    Dispatcher.BeginInvoke((Action)delegate ()
                    {
                        Status = errorMessage;
                        m_StatusMessage.RaiseEvent(new RoutedEventArgs(StatusBar.HighlightMessageEvent, this));
                    });
            }
            LoggedError = true;

        }

        public static readonly RoutedEvent HighlightMessageEvent = EventManager.RegisterRoutedEvent("HighlightMessage", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(StatusBar));

        public event RoutedEventHandler HighlightMessage
        {
            add { AddHandler(HighlightMessageEvent, value); }
            remove { RemoveHandler(HighlightMessageEvent, value); }
        }

        /// <summary>
        /// Have we just logged an error (last message in status bar is an error message)
        /// </summary>
        public bool LoggedError { get; private set; }
        /// <summary>
        /// returns a TextWriter for the status log.  
        /// </summary>
        public TextWriter LogWriter
        {
{'fraction_non_alphanumeric': 0.09172913225765468, 'fraction_numerical': 0.004065557108372506, 'mean_word_length': 2.0057273768613975, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7316321', 'n_tokens_mistral': 2012, 'n_tokens_neox': 1918, 'n_words': 596}