Beispiel #1
0
        private static async Task <Dictionary <string, RuntimeValueType> > GetPropertyTypesAsync(IOperationExecutionContext context, IRemoteJobExecuter jobRunner, string resourceName, string moduleName, ILogSink log)
        {
            var job = new ExecutePowerShellJob
            {
                CollectOutput = true,
                ScriptText    = @"$h = @{}
foreach($p in (Get-DscResource -Name $Name -Module $ModuleName).Properties) {
    $h[$p.Name] = $p.PropertyType
}
Write-Output $h",
                Variables     = new Dictionary <string, RuntimeValue>(StringComparer.OrdinalIgnoreCase)
                {
                    ["Name"]       = resourceName,
                    ["ModuleName"] = AH.CoalesceString(moduleName, "PSDesiredStateConfiguration")
                }
            };

            job.MessageLogged += (s, e) => log.Log(e.Level, e.Message);

            var result = (ExecutePowerShellJob.Result) await jobRunner.ExecuteJobAsync(job, context.CancellationToken);

            var properties = result.Output.FirstOrDefault().AsDictionary();

            var types = new Dictionary <string, RuntimeValueType>(StringComparer.OrdinalIgnoreCase);

            if (properties != null)
            {
                foreach (var p in properties)
                {
                    var value = p.Value.AsString();
                    types[p.Key] = (!string.IsNullOrWhiteSpace(value) && IsArrayPropertyRegex.IsMatch(value)) ? RuntimeValueType.Vector : RuntimeValueType.Scalar;
                }
            }

            return(types);
        }