private static void HandleServiceConfiguration(YamlSequenceNode yamlSequenceNode, List <ConfigConfigurationSource> configuration) { foreach (var child in yamlSequenceNode.Children) { var config = new ConfigConfigurationSource(); switch (child) { case YamlMappingNode childMappingNode: HandleServiceConfigurationNameMapping(childMappingNode, config); break; case YamlScalarNode childScalarNode: HandleServiceConfigurationCompact(childScalarNode, config); break; default: throw new TyeYamlException(child.Start, CoreStrings.FormatUnexpectedTypes($"\"{YamlNodeType.Mapping.ToString()}\", \"{YamlNodeType.Scalar.ToString()}\"", child.NodeType.ToString())); } // if no value is given, we take the value from the system/shell environment variables if (config.Value == null) { config.Value = Environment.GetEnvironmentVariable(config.Name) ?? string.Empty; } configuration.Add(config); } }
private static void ParseEnvironment(YamlNode node, ConfigService service) { if (node is YamlSequenceNode sequenceNode) { foreach (var arg in sequenceNode) { var configItem = new ConfigConfigurationSource(); var argString = YamlParser.GetScalarValue(arg); if (argString.Contains('=')) { var parts = argString.Split('='); configItem.Name = parts[0]; configItem.Value = parts[1]; } else { configItem.Name = argString; } service.Configuration.Add(configItem); } } else { var mappingNode = (node as YamlMappingNode) !; foreach (var arg in mappingNode) { var configItem = new ConfigConfigurationSource(); configItem.Name = YamlParser.GetScalarValue(arg.Key); configItem.Value = YamlParser.GetScalarValue(arg.Value); service.Configuration.Add(configItem); } } }
private static void HandleServiceConfiguration(YamlSequenceNode yamlSequenceNode, List <ConfigConfigurationSource> configuration) { foreach (var child in yamlSequenceNode.Children) { YamlParser.ThrowIfNotYamlMapping(child); var config = new ConfigConfigurationSource(); HandleServiceConfigurationNameMapping((YamlMappingNode)child, config); configuration.Add(config); } }
private static void HandleServiceConfigurationNameMapping(YamlMappingNode yamlMappingNode, ConfigConfigurationSource config) { foreach (var child in yamlMappingNode !.Children) { var key = YamlParser.GetScalarValue(child.Key); switch (key) { case "name": config.Name = YamlParser.GetScalarValue(key, child.Value); break; case "value": config.Value = YamlParser.GetScalarValue(key, child.Value); break; default: throw new TyeYamlException(child.Key.Start, CoreStrings.FormatUnrecognizedKey(key)); } } }
private static void HandleServiceConfigurationCompact(YamlScalarNode yamlScalarNode, ConfigConfigurationSource config) { var nodeValue = YamlParser.GetScalarValue(yamlScalarNode); var keyValueSeparator = nodeValue.IndexOf('='); if (keyValueSeparator != -1) { var key = nodeValue.Substring(0, keyValueSeparator).Trim(); var value = nodeValue.Substring(keyValueSeparator + 1)?.Trim(); config.Name = key; config.Value = value?.Trim(new[] { ' ', '"' }) ?? string.Empty; } else { config.Name = nodeValue.Trim(); } }