in src/InstrumentationEngine.Attach/CommandHandler/AttachCommandHandler.cs [345:444]
private static bool TryParseInstrumentationMethodConfiguration(
List<ConfigurationSourceInfo> sourceInfos,
ChipType targetChip,
out InstrumentationMethodsTypeAddInstrumentationMethod[]? methods)
{
methods = null;
var methodsSection = new List<InstrumentationMethodsTypeAddInstrumentationMethod>();
// Parse methods section
if (sourceInfos == null || sourceInfos.Count == 0)
{
// Short-cirtcuit here, we don't have sources to parse.
WriteError("Missing configuration sources.");
return false;
}
foreach (var sourceInfo in sourceInfos)
{
if (sourceInfo.Sources == null ||
sourceInfo.ConfigSourceDirectory == null)
{
continue;
}
if (sourceInfo.Sources.InstrumentationConfigurationSource != null)
{
foreach (var source in sourceInfo.Sources.InstrumentationConfigurationSource)
{
if (source.Platforms != null)
{
foreach (var platform in source.Platforms)
{
if (platform.Chip.Equals(targetChip))
{
string configFullPath = Path.GetFullPath(Path.Combine(sourceInfo.ConfigSourceDirectory, platform.Path));
var methodSettings = new List<SettingsTypeSetting>();
var methodSection = new InstrumentationMethodsTypeAddInstrumentationMethod();
if (File.Exists(configFullPath))
{
methodSection.ConfigPath = configFullPath;
}
else
{
WriteError($"Instrumentation Method Config file was not found at {configFullPath}.");
return false;
}
// Allow methods without any settings.
if (source.Settings != null)
{
foreach (var setting in source.Settings)
{
string settingValue;
if (setting.IsPathSpecified &&
setting.IsPath)
{
// Assumes path is relative, however Path.Combine will ignore all arguments left of one that is absolute.
settingValue = Path.Combine(sourceInfo.ConfigSourceDirectory, setting.Value);
}
else
{
settingValue = setting.Value;
}
methodSettings.Add(new SettingsTypeSetting()
{
Name = setting.Name,
Value = settingValue
});
}
methodSection.Settings = methodSettings.ToArray();
}
methodsSection.Add(methodSection);
}
else
{
// Mismatch of platform, skipping.
continue;
}
}
}
else
{
WriteError($"No platforms found for ConfigurationSource '{sourceInfo.ConfigSourceFilePath}'.");
return false;
}
}
}
else
{
WriteError($"No ConfigurationSources provided for '{sourceInfo.ConfigSourceFilePath}'.");
return false;
}
}
methods = methodsSection.ToArray();
return true;
}