Beispiel #1
0
        /// <summary>
        /// Rebuilds the filtered items array based on given citerias.
        /// </summary>
        public void ApplyFilter(StringHelper.IStringFilter filter)
        {
            if (filter == null || filter.IsAlwaysMatch)
            {
                filteredItems = storedItems;
            }
            else
            {
                IList <ListViewItem> tmp = new List <ListViewItem>();

                lock (syncItems)
                {
                    foreach (ListViewItem i in storedItems)
                    {
                        DebugViewData d = i.Tag as DebugViewData;
                        if (d != null && filter.Match(d.Message))
                        {
                            tmp.Add(i);
                        }
                    }
                }

                filteredItems = tmp;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Imports entries from the text file.
        /// </summary>
        public int ImportTextFile(string fileName, int filterPID, StringHelper.IStringFilter filter)
        {
            StreamReader          input = null;
            IList <DebugViewData> items = new List <DebugViewData>();
            string   line;
            DateTime creation    = DateTime.Now;
            string   processName = "-- disk --";
            int      pid         = -2;

            try
            {
                input = File.OpenText(fileName);

                // read each entry:
                while ((line = input.ReadLine()) != null)
                {
                    line = line.Trim();

                    // interpret as DebugViewData item:
                    if (!string.IsNullOrEmpty(line))
                    {
                        items.Add(new DebugViewData((uint)pid, processName, null, creation, line));
                    }
                }

                // add all items to the internal collections:
                Add(items, filterPID, filter);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
            finally
            {
                if (input != null)
                {
                    input.Close();
                }
            }

            return(items.Count);
        }
Beispiel #3
0
        private void PopulateVars(string filterText)
        {
            // update the filter:
            if (string.IsNullOrEmpty(filterText))
            {
                _activeFilter = null;
            }
            else
            {
                _activeFilter = new StringHelper.RegexFilter(filterText, RegexOptions.IgnoreCase);
            }

            if (filterText != null && !toolStripFilter.Items.Contains(filterText))
            {
                toolStripFilter.Items.Add(filterText);
            }

            // refresh the view:
            PopulateVars();
        }
Beispiel #4
0
        public DebugViewTool()
        {
            InitializeComponent();
            RefreshProcessCombo();

            list.RetrieveVirtualItem         += RetrieveVirtualItem;
            DebugViewMonitor.ReceivedMessage += ReceivedMessage;
            ServiceEnabled = true;

            toolStripCustomColumns.SelectedIndex = 2;

            toolStripSaveAs.Enabled        = false;
            toolStripClear.Enabled         = false;
            clearToolStripMenuItem.Enabled = false;
            filter = StringHelper.CreateStarFilter(null);

            SetItemSelected(-1, null, false);
            FilterMessages = null;

            // store the reference of the created tool:
            CustomAddInManager.LastCreatedPackageTool = this;
        }
Beispiel #5
0
        /// <summary>
        /// Stores new items and updates the filtered list as well.
        /// </summary>
        public void Add(IList <DebugViewData> items, int filterPID, StringHelper.IStringFilter filter)
        {
            lock (syncItems)
            {
                ListViewItem x;
                if (filterPID == -1)
                {
                    if (filter == null || filter.IsAlwaysMatch)
                    {
                        foreach (DebugViewData i in items)
                        {
                            x = ToListViewItem(i);
                            storedItems.Add(x);

                            // using special filter, may set the filteredItems
                            // to the same collection as storedItems, to avoid
                            // adding the same element twice, check if different:
                            if (storedItems != filteredItems)
                            {
                                filteredItems.Add(x);
                            }
                        }
                    }
                    else
                    {
                        foreach (DebugViewData i in items)
                        {
                            x = ToListViewItem(i);
                            storedItems.Add(x);

                            // using special filter, may set the filteredItems
                            // to the same collection as storedItems, to avoid
                            // adding the same element twice, check if different:
                            if (storedItems != filteredItems && filter.Match(i.Message))
                            {
                                filteredItems.Add(x);
                            }
                        }
                    }
                }
                else
                {
                    if (filter == null || filter.IsAlwaysMatch)
                    {
                        foreach (DebugViewData i in items)
                        {
                            if ((int)i.PID == filterPID)
                            {
                                x = ToListViewItem(i);
                                storedItems.Add(x);

                                // using special filter, may set the filteredItems
                                // to the same collection as storedItems, to avoid
                                // adding the same element twice, check if different:
                                if (storedItems != filteredItems)
                                {
                                    filteredItems.Add(x);
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (DebugViewData i in items)
                        {
                            if ((int)i.PID == filterPID)
                            {
                                x = ToListViewItem(i);
                                storedItems.Add(x);

                                // using special filter, may set the filteredItems
                                // to the same collection as storedItems, to avoid
                                // adding the same element twice, check if different:
                                if (storedItems != filteredItems && filter.Match(i.Message))
                                {
                                    filteredItems.Add(x);
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #6
0
        private void Search(TreeNode startNode, int listIndex, StringHelper.IStringFilter filter, bool keys, bool values, bool content)
        {
            treeView.BeginUpdate();

            if (keys)
            {
                do
                {
                    // search by key name:
                    startNode.Expand();

                    // search by value:
                    if (values)
                    {
                        bool        close;
                        RegistryKey key       = GetKey(startNode, false, out close);
                        string[]    keyValues = (key != null ? key.GetValueNames() : null);
                        string      foundName = null;

                        if (listIndex >= 0 && keyValues != null && keyValues.Length > 0)
                        {
                            if (listIndex >= keyValues.Length)
                            {
                                keyValues = null;
                            }
                            else
                            {
                                // remove given number of first elements:
                                Array.Sort(keyValues);
                                string[] newValues = new string[keyValues.Length - listIndex - 1];
                                for (int i = 0, j = listIndex + 1; i < newValues.Length; i++, j++)
                                {
                                    newValues[i] = keyValues[j];
                                }
                                listIndex = -1;
                                keyValues = newValues;
                            }
                        }

                        if (keyValues != null && keyValues.Length > 0)
                        {
                            foreach (string v in keyValues)
                            {
                                if (filter.Match(v))
                                {
                                    // found active item:
                                    foundName = GetSafeValueName(v);
                                    break;
                                }
                            }

                            // check if parse also content:
                            if (content && foundName == null)
                            {
                                foreach (string v in keyValues)
                                {
                                    RegistryValueKind kind = key.GetValueKind(v);

                                    if (filter.Match(GetValueString(key, v, kind)))
                                    {
                                        // found active item:
                                        foundName = GetSafeValueName(v);
                                        break;
                                    }
                                }
                            }

                            if (foundName != null)
                            {
                                treeView.SelectedNode = startNode;
                                treeView.EndUpdate();
                                startNode.EnsureVisible();
                                ActiveControl = listView;

                                foreach (ListViewItem i in listView.Items)
                                {
                                    if (i.SubItems[0].Text == foundName)
                                    {
                                        i.Selected = true;
                                        i.EnsureVisible();
                                    }
                                }
                                return;
                            }
                        }

                        if (close && key != null)
                        {
                            key.Close();
                        }
                    }

                    startNode = startNode.NextVisibleNode;

                    if (startNode != null && filter.Match(startNode.Text))
                    {
                        treeView.SelectedNode = startNode;
                        startNode.EnsureVisible();
                        ActiveControl = treeView;
                        break;
                    }
                } while (startNode != null);
            }
            else
            {
                // search only among current items in list view:
                if (listIndex < 0)
                {
                    listIndex = 0;
                }
                for (int i = listIndex; i < listView.Items.Count; i++)
                {
                    ListViewItem item = listView.Items[i];
                    ListViewItem.ListViewSubItemCollection subItems = item.SubItems;

                    if ((values && filter.Match(subItems[0].Text)) ||
                        (content && filter.Match(subItems[2].Text)))
                    {
                        item.Selected = true;
                        item.EnsureVisible();
                        ActiveControl = listView;
                        break;
                    }
                }
            }

            treeView.EndUpdate();
        }