Chromium Code Reviews| Index: visual_studio/NativeClientVSAddIn/NativeClientVSAddIn/ProcessInfo.cs |
| diff --git a/visual_studio/NativeClientVSAddIn/NativeClientVSAddIn/ProcessInfo.cs b/visual_studio/NativeClientVSAddIn/NativeClientVSAddIn/ProcessInfo.cs |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..795732c3aa3870b7a17e0578b4d1dd97f74b25fa |
| --- /dev/null |
| +++ b/visual_studio/NativeClientVSAddIn/NativeClientVSAddIn/ProcessInfo.cs |
| @@ -0,0 +1,89 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +namespace NativeClientVSAddIn |
| +{ |
| + using System; |
| + using System.Globalization; |
| + using System.Management; |
| + |
| + /// <summary> |
| + /// Holds information about a process for a ProcessSearcher. |
| + /// </summary> |
| + public class ProcessInfo |
| + { |
| + /// <summary> |
| + /// Constructs a process entry. |
| + /// </summary> |
| + /// <param name="id">Process ID.</param> |
| + /// <param name="parentId">Process ID of the parent process.</param> |
| + /// <param name="creationDate"> |
| + /// String date in format 'yyyyMMddHHmmss.ffffff', or if empty then current time used. |
| + /// </param> |
| + /// <param name="commandLine">Command line arguments to the process.</param> |
| + /// <param name="name">Process name.</param> |
| + public ProcessInfo(uint id, uint parentId, string creationDate, string commandLine, string name) |
| + { |
| + // Convert an empty creationDate string into the current timestamp. |
| + if (string.IsNullOrEmpty(creationDate)) |
| + { |
| + int timezoneMinutes = (int)Math.Round((DateTime.Now - DateTime.UtcNow).TotalMinutes); |
| + creationDate = string.Format("{0:yyyyMMddHHmmss.ffffff}{1}", DateTime.Now, timezoneMinutes); |
|
binji
2012/07/20 00:24:53
seems weird to create the date string here just to
tysand
2012/08/07 23:01:54
Done.
|
| + } |
| + |
| + // Example creationDate: "20120622150149.843021-420". |
| + CreationDate = DateTime.ParseExact( |
| + creationDate.Substring(0, 21), |
| + "yyyyMMddHHmmss.ffffff", |
| + CultureInfo.InvariantCulture); |
| + long timeZoneMinutes = long.Parse(creationDate.Substring(21)); |
| + CreationDate = CreationDate.AddMinutes(-timeZoneMinutes); |
| + |
| + ID = id; |
| + ParentID = parentId; |
| + CommandLine = commandLine; |
| + Name = name; |
| + } |
| + |
| + /// <summary> |
| + /// Gets or sets Process ID of the represented process. |
| + /// </summary> |
| + public uint ID { get; set; } |
| + |
| + /// <summary> |
| + /// Gets or sets Process ID of the parent process. |
| + /// </summary> |
| + public uint ParentID { get; set; } |
| + |
| + /// <summary> |
| + /// Gets or sets DateTime of the process creation. |
| + /// </summary> |
| + public DateTime CreationDate { get; set; } |
| + |
| + /// <summary> |
| + /// Gets or sets Command line arguments to the process. |
| + /// </summary> |
| + public string CommandLine { get; set; } |
| + |
| + /// <summary> |
| + /// Gets or sets Name of the process. |
| + /// </summary> |
| + public string Name { get; set; } |
| + |
| + /// <summary> |
| + /// Casts from a management object that is a Win32_Process underlying type to a ProcessInfo. |
| + /// </summary> |
| + /// <param name="from">A management object that is Win32_Process underneath.</param> |
| + /// <returns>A ProcessInfo object.</returns> |
| + public static explicit operator ProcessInfo(ManagementObject from) |
|
binji
2012/07/20 00:24:53
Seems more natural to just have a second construct
tysand
2012/08/07 23:01:54
Done.
|
| + { |
| + return new ProcessInfo( |
| + id: (uint)from["ProcessID"], |
| + parentId: (uint)from["ParentProcessID"], |
| + creationDate: from["CreationDate"] as string, |
| + commandLine: from["CommandLine"] as string, |
| + name: from["Name"] as string); |
| + } |
| + } |
| +} |