//OVERLOADING private void LoadChildren(YamlSequenceNode sequence, MyYamlNode parent) { foreach (var child in sequence.Children) { if (child is YamlScalarNode) { var scalar = child as YamlScalarNode; parent.AddChildren(MyNodeFactory.CreateMyYamlScalarNode("", scalar.Tag, scalar.Value, scalar.Style, indentAmount, parent, scalar.Start.Line, scalar.Start.Column)); } else if (child is YamlSequenceNode) { parent.AddChildren(MyNodeFactory.CreateMyYamlSequenceNode("", indentAmount, parent)); MyYamlSequenceNode new_parent = (MyYamlSequenceNode)parent.nodes[parent.nodes.Count - 1]; LoadChildren(child as YamlSequenceNode, new_parent); } else if (child is YamlMappingNode) { parent.AddChildren(MyNodeFactory.CreateMyYamlMappingNode("", indentAmount, parent)); MyYamlMappingNode new_parent = (MyYamlMappingNode)parent.nodes[parent.nodes.Count - 1]; LoadChildren(child as YamlMappingNode, new_parent); } } }
//OVERLOADING private void LoadChildren(YamlMappingNode mapping, MyYamlNode parent) { var children = mapping?.Children; if (children == null) { return; } foreach (var child in children) { var key = child.Key as YamlScalarNode; //alias/anchor error on yamlStream fix: if (key.Value[0] == '*' || key.Value[key.Value.Length - 1] == '*') { key.Value = "\"" + key.Value + "\""; } if (child.Value is YamlScalarNode) { var scalar = child.Value as YamlScalarNode; //Fix yamlStream syntax error //removes unnecessary '/' after folder name in includes if (!(string.IsNullOrEmpty(scalar.Value)) && (scalar.Value[scalar.Value.Length - 1] == '\\' || scalar.Value[scalar.Value.Length - 1] == '/')) { scalar.Value = scalar.Value.Remove(scalar.Value.Length - 1); } //if the value is single quoted and contains a "'" we need to replace it with "''" if (scalar.Value.Contains("'") && scalar.Style == YamlDotNet.Core.ScalarStyle.SingleQuoted) { scalar.Value = scalar.Value.Replace("'", "''"); } //if the value is double quoted and contains a '"' we need to replace it with '"' if (scalar.Value.Contains("\"") && scalar.Style == YamlDotNet.Core.ScalarStyle.DoubleQuoted) { scalar.Value = scalar.Value.Replace("\"", "\\\""); } parent.AddChildren(MyNodeFactory.CreateMyYamlScalarNode(key.Value, scalar.Tag, scalar.Value, scalar.Style, indentAmount, parent, key.Start.Line, key.Start.Column)); if (scalar.Tag == "!include") { if (File.Exists(directory + scalar.Value)) { MyYamlFileFactory.CreateMyYamlFile(directory + scalar.Value); } else { Logger.Instance.WriteLine("Could not find file '" + directory + scalar.Value + "'."); } } if (scalar.Tag == "!include_dir_named" || scalar.Tag == "!include_dir_merge_named" || scalar.Tag == "!include_dir_merge_list") { CreateDirectoryIfDoesntExist(directory, scalar.Value); string[] files = System.IO.Directory.GetFiles(directory + scalar.Value + "\\", "*.yaml"); foreach (var value in files) { var file_to_import = Path.GetFileName(value); if (File.Exists(directory + scalar.Value + "\\" + file_to_import)) { MyYamlFileFactory.CreateMyYamlFile(directory + scalar.Value + "\\" + file_to_import); } else { Logger.Instance.WriteLine("Could not find file '" + directory + scalar.Value + "\\" + file_to_import + "'."); } } } } else if (child.Value is YamlSequenceNode) { parent.AddChildren(MyNodeFactory.CreateMyYamlSequenceNode(key.Value, indentAmount, parent)); indentAmount += 2; MyYamlSequenceNode new_parent = (MyYamlSequenceNode)parent.nodes[parent.nodes.Count - 1]; LoadChildren(child.Value as YamlSequenceNode, new_parent); indentAmount -= 2; } else if (child.Value is YamlMappingNode) { parent.AddChildren(MyNodeFactory.CreateMyYamlMappingNode(key.Value, indentAmount, parent)); indentAmount += 2; MyYamlMappingNode new_parent = (MyYamlMappingNode)parent.nodes[parent.nodes.Count - 1]; LoadChildren(child.Value as YamlMappingNode, new_parent); indentAmount -= 2; } } }