Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: visual_studio/NativeClientVSAddIn/NativeClientVSAddIn/ProcessSearcher.cs

Issue 10758009: Native Client Visual Studio Add-in (Closed) Base URL: https://nativeclient-sdk.googlecode.com/svn/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 namespace NativeClientVSAddIn
6 {
7 using System;
8 using System.Collections.Generic;
9 using System.Linq;
10 using System.Management;
11
12 /// <summary>
13 /// Queries the system for the list of running processes.
14 /// </summary>
15 public class ProcessSearcher
16 {
17 /// <summary>
18 /// Returns results of a process search subject to given constraints.
19 /// </summary>
20 /// <param name="constraints">
21 /// A function taking a ProcessInfo object and returning true if the
22 /// ProcessInfo object satisfies the constraints.
23 /// </param>
24 /// <returns>List of matching processes.</returns>
25 public List<ProcessInfo> GetResults(Func<ProcessInfo, bool> constraints)
26 {
27 return GetSystemProcesses().Where(constraints).ToList();
28 }
29
30 /// <summary>
31 /// Searches the system for all processes of a given name.
32 /// </summary>
33 /// <param name="name">Name to search for.</param>
34 /// <returns>List of matching processes.</returns>
35 public List<ProcessInfo> GetResultsByName(string name)
36 {
37 return GetResults(p => name.Equals(p.Name, StringComparison.OrdinalIgnoreC ase));
38 }
39
40 /// <summary>
41 /// Searches the system for all processes of a given process ID.
42 /// </summary>
43 /// <param name="procID">ID to search for.</param>
44 /// <returns>List of matching processes.</returns>
45 public List<ProcessInfo> GetResultsByID(uint procID)
46 {
47 return GetResults(p => procID == p.ID);
48 }
49
50 /// <summary>
51 /// Queries the system for the full list of processes.
52 /// </summary>
53 /// <returns>List of processes on the system.</returns>
54 protected virtual List<ProcessInfo> GetSystemProcesses()
55 {
56 var processList = new List<ProcessInfo>();
57 string query = "select * from Win32_Process";
58 using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(qu ery))
59 {
60 using (ManagementObjectCollection results = searcher.Get())
61 {
62 foreach (ManagementObject process in results)
63 {
64 processList.Add((ProcessInfo)process);
65 }
66 }
67 }
68
69 return processList;
70 }
71 }
72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698