public IEnumerable <KeyValuePair <string, object> > ProvideValues(ManagementObject managementObject, Process process, bool updateProcess) { if (!updateProcess) { //these values cannot change if (process != null) { yield return(new KeyValuePair <string, object>("Name", process.ProcessName)); } if (managementObject.TryGetDateTime("CreationDate", out var creationDate)) { yield return(new KeyValuePair <string, object>("CreationDate", creationDate)); } if (managementObject.TryGetProperty("ExecutablePath", out string executablePath)) { yield return(new KeyValuePair <string, object>("ExecutablePath", executablePath)); } if (managementObject.TryGetProperty("CommandLine", out string commandLine)) { yield return(new KeyValuePair <string, object>("CommandLine", commandLine)); } } if (managementObject.TryGetProperty("ParentProcessId", out uint parentProcessId)) { yield return(new KeyValuePair <string, object>("ParentProcessId", parentProcessId)); } }
public static void TryAddDateTime(this IList <SystemInfoDto> dtos, string category, ManagementObject managementObject, string name) { if (managementObject.TryGetDateTime(name, out DateTimeOffset value)) { var dto = new SystemInfoDto { Name = $"@{category}.{name}", Category = category, Value = new DateTimeValueDto(value) }; dtos.Add(dto); } }