-
Notifications
You must be signed in to change notification settings - Fork 56
Closed
Labels
Milestone
Description
Summary of the new feature / enhancement
The current output of this argument set places a higher burden on higher level tools. A simple array of resources would be more useful and easier to parse.
Proposed technical implementation details (optional)
Consider this is what I have to do today:
// Execute the external command and capture output
var dscCommand = "c:\\bin\\dsc\\dsc.exe";
var dscArgs = $"resource get --all --resource Microsoft.GuestConfiguration/users";
var processInfo = new ProcessStartInfo(dscCommand, dscArgs)
{
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};
var process = Process.Start(processInfo);
var output = new List<string>();
while (!process.StandardOutput.EndOfStream)
{
output.Add(process.StandardOutput.ReadLine());
}
process.WaitForExit();
// Deserialize the JSON output and extract the resources
var resources = new List<Resource>();
foreach (var line in output)
{
var resource = JsonSerializer.Deserialize<DscResourceResult>(line);
resources.Add(resource.ActualState);
}
public class Resource
{
[JsonPropertyName("id")]
public string Id { get; set; } = string.Empty;
[JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;
[JsonPropertyName("type")]
public string Type { get; set; } = string.Empty;
[JsonPropertyName("properties")]
public object Properties { get; set; } = new object();
}
public class DscResourceResult
{
[JsonPropertyName("actualState")]
public ArmResource ActualState { get; set; }
}
It would be much easier to do this instead:
// Execute the external command and capture output
var dscCommand = "c:\\bin\\dsc\\dsc.exe";
var dscArgs = $"resource get --all --resource Microsoft.GuestConfiguration/users";
var processInfo = new ProcessStartInfo(dscCommand, dscArgs)
{
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};
var process = Process.Start(processInfo);
var output = new StringBuilder();
while (!process.StandardOutput.EndOfStream)
{
output.AppendLine(process.StandardOutput.ReadLine());
}
process.WaitForExit();
// Deserialize the JSON output and extract the resources
var resources = JsonSerializer.Deserialize<List<Resource>>(output);
public class Resource
{
[JsonPropertyName("id")]
public string Id { get; set; } = string.Empty;
[JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;
[JsonPropertyName("type")]
public string Type { get; set; } = string.Empty;
[JsonPropertyName("properties")]
public object Properties { get; set; } = new object();
}