Ejemplo n.º 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));

                    //CANT HAVE INCLUDE IN SEQUENCE CHILDREN???

                    /* if (scalar.Tag == "!include")
                     * {
                     *  LoadFile(node, scalar.Value);
                     * } */
                }
                else if (child is YamlSequenceNode)
                {
                    parent.AddChildren(MyNodeFactory.CreateMyYamlSequenceNode("", indentAmount));

                    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));

                    MyYamlMappingNode new_parent = (MyYamlMappingNode)parent.nodes[parent.nodes.Count - 1];
                    LoadChildren(child as YamlMappingNode, new_parent);
                }
            }
        }
Ejemplo n.º 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;
                //System.Diagnostics.Trace.Assert(key != null);

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

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

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

                    indentAmount += 2;
                    MyYamlMappingNode parent = (MyYamlMappingNode)first_sequence.nodes[first_sequence.nodes.Count - 1];
                    LoadChildren(child as YamlMappingNode, parent);
                    indentAmount -= 2;
                }
            }
        }
Ejemplo n.º 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);

                if (child.Value is YamlScalarNode)
                {
                    var scalar = child.Value as YamlScalarNode;
                    nodes.Add(MyNodeFactory.CreateMyYamlScalarNode(key.Value, scalar.Tag, scalar.Value, scalar.Style, indentAmount));

                    if (scalar.Tag == "!include")
                    {
                        if (File.Exists(directory + scalar.Value))
                        {
                            new MyYamlFile(directory + scalar.Value);
                        }
                        else
                        {
                            Logger.Instance.WriteLine("Could not find file '" + directory + scalar.Value + "'.");
                        }
                    }
                    if (scalar.Tag == "!include_dir_named")
                    {
                        System.IO.Directory.CreateDirectory(directory + scalar.Value);//Create directory if doesnt exists
                        string[] files = System.IO.Directory.GetFiles(directory + scalar.Value + "/", "*.yaml");
                        foreach (var value in files)
                        {
                            var value_split    = value.Split("/");
                            var file_to_import = value_split[value_split.Length - 1];
                            if (File.Exists(directory + scalar.Value + "/" + file_to_import))
                            {
                                new MyYamlFile(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));

                    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));

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