Beispiel #1
0
 static void RemoveChildren(this ProcessEntry root, IList <ProcessEntry> processEntries)
 {
     foreach (var entry in root.Children)
     {
         processEntries.Remove(entry);
     }
 }
Beispiel #2
0
        public static void ForEach(this ProcessEntry processEntries, Action <ProcessEntry, int> action, int indentLevel = 0)
        {
            action(processEntries, indentLevel);

            foreach (var entry in processEntries.Children)
            {
                entry.ForEach(action, indentLevel + 1);
            }
        }
Beispiel #3
0
        public static ProcessEntry FindProcessByName(this ProcessEntry root, Regex nameRegex)
        {
            if (root.ImageName != null && nameRegex.IsMatch(root.ImageName))
            {
                return(root);
            }

            foreach (var proc in root.Children)
            {
                var child = proc.FindProcessByName(nameRegex);
                if (child != null)
                {
                    return(child);
                }
            }

            return(null);
        }
Beispiel #4
0
        public static ProcessEntry BuildTree(this ProcessEntry root, IList <ProcessEntry> processList)
        {
            if (processList.Count == 0)
            {
                return(root);
            }

            var children = processList.Where(p => p.ParentId == root.Id || !p.ValidParent).ToList();

            root.Children.AddRange(children);
            root.RemoveChildren(processList);

            for (var i = 0; i < children.Count; i++)
            {
                children[i] = children[i].BuildTree(processList);

                if (processList.Count == 0)
                {
                    break;
                }
            }

            return(root);
        }
Beispiel #5
0
 public static ulong TotalWorkingSet(this ProcessEntry process)
 {
     return(process.WorkingSet
            + process.Children
            .Aggregate(0UL, (current, child) => current + child.TotalWorkingSet()));
 }
Beispiel #6
0
        public static ProcessEntry FindProcessByName(this ProcessEntry root, string name)
        {
            var regex = new Regex($"{name}(?:\\..*)?", RegexOptions.IgnoreCase);

            return(root.FindProcessByName(regex));
        }