848 lines · 31.0 KB · C#
RawDownload
                     m_filters = filters;                    LstFilters.Items.Clear();                    LstFilters.Items.AddRange(filters.Cast<object>().ToArray());                    RefreshFilters();                    break;                default:                    throw new NotSupportedException();            }         }         private void btnSaveSelected_Click(object sender, EventArgs e)        {            using (SaveFileDialog dlgSave = new SaveFileDialog())            {                dlgSave.Filter = "Log File (Compressed)|*.logz";                 if (dlgSave.ShowDialog() == DialogResult.OK)                {                    using (var fileWriter = new LogFileWriter(dlgSave.FileName))                    {                        foreach (DataRow row in m_dataTable.Rows)                        {                            LogMessage message = row["Object"] as LogMessage;                            bool shown = (bool)row["_Show"];                             if (shown)                            {                                fileWriter.Write(message, false);                            }                        }                    }                }            }        }         private void FilterFirstChanceExceptions(List<LogMessage> messages)        {            for (int x = 0; x < messages.Count; x++)            {                //Only first chance exceptions can be filtered.                LogMessage firstMessage = messages[x];                if (firstMessage.ExceptionString.Length > 0 && firstMessage.TypeName == "GSF.Diagnostics.Logger" && firstMessage.EventName == "First Chance App Domain Exception")                {                    //don't look ahead for more than 100ms.                    DateTime stopAfter = firstMessage.UtcTime.AddTicks(100 * TimeSpan.TicksPerMillisecond);                     //bool foundMatch = false;                    for (int y = x + 1; y < messages.Count; y++)                    {                        LogMessage futureMessage = messages[y];                        if (futureMessage.UtcTime > stopAfter)                            break;                         if (futureMessage.ManagedThreadID == firstMessage.ManagedThreadID && futureMessage.ExceptionString.Length > 0 &&                            !(futureMessage.TypeName == "GSF.Diagnostics.Logger" && futureMessage.EventName == "First Chance App Domain Exception"))                        {                            if (AreExceptionsEqual(firstMessage, futureMessage))                            {                                messages.RemoveAt(x);                                x--;                                break;                            }                        }                    }                }            }        }         private bool AreExceptionsEqual(LogMessage first, LogMessage future)        {            string firstError = TrimException(first.ExceptionString);            string futureError = TrimException(future.ExceptionString);             if (futureError.StartsWith(firstError))            {                return true;            }             string[] firstWords = firstError.Split(" \r\n:".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);            List<string> foundWords = new List<string>();            List<string> missingWords = new List<string>();            List<string> ignoredWords = new List<string>();             int position = 0;             foreach (var word in firstWords)            {                if (position >= futureError.Length)                {                    missingWords.Add(word);                }                else                {                    int newPosition = futureError.IndexOf(word, position);                    if (newPosition >= 0)                    {                        foundWords.Add(word);                        position = newPosition + word.Length;                    }                    else                    {                        if (word[0] == '(' && word[word.Length - 1] == ')' && word.Contains("0x"))                        {                            ignoredWords.Add(word);                        }                        else                        {                            missingWords.Add(word);                        }                    }                }            }             if (missingWords.Count > 0)            {                return false;            }            return true;        }         private string TrimException(string error)        {            int pos = error.IndexOf("WRN: Assembly binding");            if (pos >= 0)            {                return error.Substring(0, pos).TrimEnd("\r\n ".ToCharArray());            }            return error;        }         private void LogFileViewer_DragEnter(object sender, DragEventArgs e)        {            if (e.Data.GetDataPresent(DataFormats.FileDrop))                e.Effect = DragDropEffects.Copy;        }         private void LogFileViewer_DragDrop(object sender, DragEventArgs e)        {            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);            LoadFiles(files, (e.KeyState & 8) == 8); //CTRL is pushed.        }         private void LstFilters_KeyUp(object sender, KeyEventArgs e)        {            if (e.KeyCode == Keys.Delete)            {                foreach (LogMessageFilter item in LstFilters.SelectedItems.Cast<LogMessageFilter>().ToArray())                {                    m_filters.Remove(item);                    LstFilters.Items.Remove(item);                }                 RefreshFilters();            }        }         private void VisibleCheckedChanged(object sender, EventArgs e)        {            m_visibleFlags = GetVisibleFlags();            RefreshVisible();        }         private void RefreshVisible()        {            var visible = GetVisibleFlags();             m_bindingSource.RaiseListChangedEvents = false;            foreach (DataRow row in m_dataTable.Rows)            {                int level = (int)row["_Level"];                bool show = (bool)row["_Show"];                 if (show ^ visible[level])                {                    row["_show"] = !show;                }            }            m_bindingSource.RaiseListChangedEvents = true;            m_bindingSource.ResetBindings(false);        }         private bool[] GetVisibleFlags()        {            bool[] visible = new bool[7];            visible[0] = RdoLowest.Checked;            visible[1] = visible[0] || RdoLow.Checked;            visible[2] = visible[1] || RdoBelowNormal.Checked;            visible[3] = visible[2] || RdoNormal.Checked;            visible[4] = visible[3] || RdoAboveNormal.Checked;            visible[5] = visible[4] || RdoHigh.Checked;            visible[6] = visible[5] || RdoHighest.Checked;            return visible;        }         private void RefreshFilters()        {            var visible = GetVisibleFlags();            m_bindingSource.RaiseListChangedEvents = false;            foreach (DataRow row in m_dataTable.Rows)            {                LogMessage message = row["Object"] as LogMessage;                int level = (int)row["_Level"];                bool show = (bool)row["_Show"];                int assignedLevel = GetLevel(message);                 if (level != assignedLevel)                {                    row["_Level"] = assignedLevel;                }                if (show ^ visible[assignedLevel])                {                    row["_show"] = !show;                }            }            m_bindingSource.RaiseListChangedEvents = true;            m_bindingSource.ResetBindings(false);        }         private int GetLevel(LogMessage message)        {            //Match is in reverse order.            for (int x = m_filters.Count - 1; x >= 0; x--)            {                var filter = m_filters[x];                if (filter.IsMatch(message))                {                    return (int)filter.FilterLevel;                }            }            return (int)(FilterLevel.Normal);        }         private bool IsShown(LogMessage message)        {            return m_visibleFlags[GetLevel(message)];        }         private void dgvResults_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)        {            if (e.RowIndex != -1)            {                DataGridViewRow row = dgvResults.Rows[e.RowIndex];                string fileName = (string)dgvResults["File Name", e.RowIndex].Value;                if (m_filesToBold.Contains(fileName))                {                    row.DefaultCellStyle = m_highlightStyle;                }                else                {                    row.DefaultCellStyle = dgvResults.DefaultCellStyle;                }            }        }         private void dgvResults_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)        {            if (e.ColumnIndex >= 0 && e.RowIndex != -1 && (e.State & DataGridViewElementStates.Selected) != DataGridViewElementStates.Selected)            {                int value = (int)dgvResults["_Level", e.RowIndex].Value;                Color color;                switch (value)                {                    case 0:                        color = Color.Silver;                        break;                    case 1:                        color = Color.FromArgb(255, 128, 128);                        break;                    case 2:                        color = Color.FromArgb(255, 128, 255);                        break;                    case 4:                        color = Color.FromArgb(255, 255, 128);                        break;                    case 5:                        color = Color.FromArgb(128, 255, 128);                        break;                    case 6:                        color = Color.FromArgb(128, 255, 255);                        break;                    default:                        return;                }                  //fill gradient background                using (SolidBrush gradientBrush = new SolidBrush(color))                {                    e.Graphics.FillRectangle(gradientBrush, e.CellBounds);                }                 // paint rest of cell                e.Paint(e.CellBounds, DataGridViewPaintParts.Border | DataGridViewPaintParts.ContentForeground);                e.Handled = true;            }        }         private void BtnAddFilter_Click(object sender, EventArgs e)        {            DataGridViewCell cell = dgvResults.SelectedCells.Cast<DataGridViewCell>().FirstOrDefault();            if (cell == null)            {                MessageBox.Show("Select a message to base the filter on");                return;            }            LogMessage message = dgvResults["Object", cell.RowIndex].Value as LogMessage;             using (var win = new FilterEditorDialog(message, new LogMessageFilter()))            {                if (win.ShowDialog() == DialogResult.OK)                {                    LstFilters.Items.Add(win.FilterResult);                    m_filters.Add(win.FilterResult);                    RefreshFilters();                }            }        }         private void LstFilters_MouseDoubleClick(object sender, MouseEventArgs e)        {            if (LstFilters.SelectedItem != null)            {                DataGridViewCell cell = dgvResults.SelectedCells.Cast<DataGridViewCell>().FirstOrDefault();                if (cell == null)                {                    MessageBox.Show("Select a message to base the edits on");                    return;                }                LogMessage message = dgvResults["Object", cell.RowIndex].Value as LogMessage;                 using (var win = new FilterEditorDialog(message, (LogMessageFilter)LstFilters.SelectedItem))                {                    if (win.ShowDialog() == DialogResult.OK)                    {                        m_filters[LstFilters.SelectedIndex] = win.FilterResult;                        LstFilters.Items[LstFilters.SelectedIndex] = win.FilterResult;                        RefreshFilters();                    }                }             }        }      }}

Lines 501–848 of 848. Previous lines

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t