Пример #1
0
        //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);
                }
            }
        }
Пример #2
0
        //In case there is a file with a sequence node in the beginning
        private void LoadChildren(YamlSequenceNode mapping)
        {
            var children = mapping?.Children;

            if (children == null)
            {
                return;
            }

            foreach (var child in children)
            {
                var key = child as YamlScalarNode;

                if (child is YamlMappingNode)
                {
                    nodes.Add(MyNodeFactory.CreateMyYamlMappingNode("", indentAmount, null));
                    MyYamlMappingNode root = (MyYamlMappingNode)nodes[nodes.Count - 1];

                    root.AddChildren(MyNodeFactory.CreateMyYamlSequenceNode("", indentAmount, root));
                    MyYamlSequenceNode first_sequence = (MyYamlSequenceNode)root.nodes[root.nodes.Count - 1];

                    first_sequence.AddChildren(MyNodeFactory.CreateMyYamlMappingNode("", indentAmount, first_sequence));

                    indentAmount += 2;
                    MyYamlMappingNode parent = (MyYamlMappingNode)first_sequence.nodes[first_sequence.nodes.Count - 1];
                    LoadChildren(child as YamlMappingNode, parent);
                    indentAmount -= 2;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Loads all the nodes and files included in configuration
        /// </summary>
        private void LoadChildren(YamlMappingNode mapping)
        {
            var children = mapping?.Children;

            if (children == null)
            {
                return;
            }

            foreach (var child in children)
            {
                var key = child.Key as YamlScalarNode;
                //System.Diagnostics.Trace.Assert(key != null);

                //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("\"", "\\\"");
                    }

                    nodes.Add(MyNodeFactory.CreateMyYamlScalarNode(key.Value, scalar.Tag, scalar.Value, scalar.Style, indentAmount, null, 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 + "'.");
                        }
                    }
                    else 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)
                {
                    nodes.Add(MyNodeFactory.CreateMyYamlSequenceNode(key.Value, indentAmount, null));

                    indentAmount += 2;
                    MyYamlSequenceNode parent = (MyYamlSequenceNode)nodes[nodes.Count - 1];
                    LoadChildren(child.Value as YamlSequenceNode, parent);
                    indentAmount -= 2;
                }
                else if (child.Value is YamlMappingNode)
                {
                    nodes.Add(MyNodeFactory.CreateMyYamlMappingNode(key.Value, indentAmount, null));

                    indentAmount += 2;
                    MyYamlMappingNode parent = (MyYamlMappingNode)nodes[nodes.Count - 1];
                    LoadChildren(child.Value as YamlMappingNode, parent);
                    indentAmount -= 2;
                }
            }
        }