Represents a single node in the YAML document.
コード例 #1
0
ファイル: YamlParser.cs プロジェクト: vigoo/bari
        /// <summary>
        /// Finds a child node by its name and enumerates its contents
        /// </summary>
        /// <param name="parent">Parent node</param>
        /// <param name="groupName">Name of the group to find</param>
        /// <returns>Returns a sequence of key-node pairs</returns>
        public IEnumerable<KeyValuePair<string, YamlNode>> EnumerateNamedNodesOf(YamlNode parent, string groupName)
        {
            Contract.Requires(parent != null);
            Contract.Requires(!String.IsNullOrWhiteSpace(groupName));
            Contract.Ensures(Contract.Result<IEnumerable<KeyValuePair<string, YamlNode>>>() != null);

            var mapping = parent as YamlMappingNode;
            if (mapping != null)
            {
                var groupNameNode = new YamlScalarNode(groupName);
                if (mapping.Children.ContainsKey(groupNameNode))
                {
                    var groupSeq = mapping.Children[groupNameNode] as YamlSequenceNode;

                    if (groupSeq != null)
                    {
                        foreach (var item in EnumerateNodesOf(groupSeq))
                        {
                            if (item is YamlScalarNode)
                            {
                                yield return new KeyValuePair<string, YamlNode>(((YamlScalarNode)item).Value, null);
                            }
                            else if (item is YamlMappingNode)
                            {
                                var mappingChild = (YamlMappingNode)item;
                                yield return new KeyValuePair<string, YamlNode>(
                                    GetScalarValue(mappingChild, "name"),
                                    mappingChild);
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: YamlDocument.cs プロジェクト: Cyberbanan/Projeny
		/// <summary>
		/// Initializes a new instance of the <see cref="YamlDocument"/> class.
		/// </summary>
		/// <param name="events">The events.</param>
		internal YamlDocument(EventReader events)
		{
			DocumentLoadingState state = new DocumentLoadingState();

			events.Expect<DocumentStart>();

			while (!events.Accept<DocumentEnd>())
			{
				Debug.Assert(RootNode == null);
				RootNode = YamlNode.ParseNode(events, state);

				if (RootNode is YamlAliasNode)
				{
					throw new YamlException();
				}
			}

			state.ResolveAliases();

#if DEBUG
			foreach (var node in AllNodes)
			{
				if (node is YamlAliasNode)
				{
					throw new InvalidOperationException("Error in alias resolution.");
				}
			}
#endif

			events.Expect<DocumentEnd>();
		}
コード例 #3
0
ファイル: YamlParser.cs プロジェクト: zvrana/bari
        /// <summary>
        /// Gets a scalar value identified by its key
        /// </summary>
        /// <param name="parent">Parent node</param>
        /// <param name="key">Key of the value</param>
        /// <param name="errorMessage">Error message if the key does not exists</param>
        /// <returns>Returns the scalar value</returns>
        public string GetScalarValue(YamlNode parent, string key, string errorMessage = null)
        {
            Contract.Requires(parent != null);
            Contract.Requires(key != null);
            Contract.Ensures(Contract.Result<string>() != null);

            try
            {
                var mapping = (YamlMappingNode)parent;
                var pairs = EnumerateNodesOf(mapping);
                var keyNode = new YamlScalarNode(key);

                foreach (var pair in pairs)
                {
                    if (keyNode.Equals(pair.Key))
                    {
                        if (pair.Value is YamlScalarNode)
                        {
                            var v = ((YamlScalarNode) pair.Value).Value;
                            if (v != null)
                                return v;
                        }

                        throw new InvalidSpecificationException(errorMessage ?? String.Format("No value for key {0}", key));
                    }
                }

                throw new InvalidSpecificationException(String.Format("Parent has no child with key {0}", key));
            }
            catch (Exception ex)
            {
                throw new InvalidSpecificationException(errorMessage ?? ex.Message, ex);
            }
        }
コード例 #4
0
ファイル: Rules.cs プロジェクト: k1mst0n/Petrovich.NET
            public bool Match(string name, YamlNode rule, bool matchWholeWord, YamlNode tags)
            {
                var tagRules = from r in (rule as YamlMappingNode).Children
                               where (r.Key as YamlScalarNode).Value.Equals("tags")
                               select r;

                if (!TagsAllow(tags, new YamlMappingNode(tagRules)))
                    return false;

                var gender = (from r in (rule as YamlMappingNode).Children
                              where (r.Key as YamlScalarNode).Value.Equals("gender")
                              select r).FirstOrDefault().Value;

                if (((gender as YamlScalarNode).Value.Equals("male") && this.Female) ||
                    ((gender as YamlScalarNode).Value.Equals("female") && !this.Female))
                    return false;

                var test = (from r in (rule as YamlMappingNode).Children
                            where (r.Key as YamlScalarNode).Value.Equals("test")
                            select r).FirstOrDefault().Value;

                name = name.ToLower();

                foreach (var s in (test as YamlSequenceNode))
                {
                    string value = (s as YamlScalarNode).Value;

                    var x = matchWholeWord ? name : name.Substring((int)Math.Max(name.Length - value.Length, 0));

                    if (x == value)
                        return true;
                }

                return false;
            }
コード例 #5
0
 public static Pattern fromYamlNode(YamlNode node)
 {
     if (node == null)
     {
         return null;
     }
     return new Pattern(regexFromYamlNode(node, DEFAULT_OPTIONS));
 }
コード例 #6
0
ファイル: Swagger.cs プロジェクト: madeso/swagger-compiler
 public void Read(YamlNode rootNode)
 {
     this.root = rootNode;
     if (rootNode.GetRequiredString("swagger") != "2.0")
     {
         throw new YamlError(rootNode, "swagger isn't 2.0");
     }
     ReadPaths(rootNode.FirstChildNamed("paths"));
 }
コード例 #7
0
ファイル: Swagger.cs プロジェクト: madeso/swagger-compiler
 private void ReadOperationsObject(YamlNode yamlNode)
 {
     var p = yamlNode.FirstChildNamedOrNull("parameters");
     if( p != null )
         foreach (var x in p.ArrayItems())
         {
             ReadParametersObject(x);
         }
     ReadResponsesObject(yamlNode.FirstChildNamed("responses"));
 }
コード例 #8
0
ファイル: YamlExtensions.cs プロジェクト: wilsonmar/mulder
		static object GetValue(YamlNode yamlNode)
		{
			if (yamlNode is YamlMappingNode)
				return GetMappingValue((YamlMappingNode)yamlNode);
			
			if (yamlNode is YamlSequenceNode)
				return GetSequenceValue((YamlSequenceNode)yamlNode);
			
			return yamlNode.ToString();
		}
コード例 #9
0
        private static void WriteHtmlForNode(YamlNode item, StringWriter htmlwriter)
        {
            var scalar = item as YamlScalarNode;
            if (scalar != null)
                WriteHtmlForScalarNode(htmlwriter, scalar);

            var mapping = item as YamlMappingNode;
            if (mapping != null)
                WriteHtmlForMappingNode(htmlwriter, mapping);

            var sequence = item as YamlSequenceNode;
            if (sequence != null)
                WriteHtmlForSequenceNode(htmlwriter, sequence);
        }
コード例 #10
0
		/// <summary>
		/// Adds the specified node to the anchor list.
		/// </summary>
		/// <param name="node">The node.</param>
		public void AddAnchor(YamlNode node)
		{
			if (node.Anchor == null)
			{
				throw new ArgumentException("The specified node does not have an anchor");
			}

			if (anchors.ContainsKey(node.Anchor))
			{
				throw new DuplicateAnchorException(node.Start, node.End, string.Format(CultureInfo.InvariantCulture, "The anchor '{0}' already exists", node.Anchor));
			}

			anchors.Add(node.Anchor, node);
		}
コード例 #11
0
        public static Regex regexFromYamlNode(YamlNode node, RegexOptions options)
        {
            string regex;
            string regexOptions = "";
            if (node is YamlScalarNode)
            {
                regex = ((YamlScalarNode)node).Value;
            }
            else if (node is YamlSequenceNode)
            {
                IEnumerator<YamlNode> it = ((YamlSequenceNode)node).Children.GetEnumerator();
                if (!it.MoveNext())
                {
                    throw new InvalidConfigurationException("The pattern needs at least the regex defined!");
                }
                if (!(it.Current is YamlScalarNode))
                {
                    throw new InvalidConfigurationException("The pattern may only contain string value!");
                }
                regex = ((YamlScalarNode)it.Current).Value;

                if (it.MoveNext() && it.Current is YamlScalarNode)
                {
                    regexOptions = ((YamlScalarNode)it.Current).Value;
                }
            }
            else if (node is YamlMappingNode)
            {
                IDictionary<YamlNode, YamlNode> patternConfig = ((YamlMappingNode)node).Children;
                node = (patternConfig.ContainsKey(Node.REGEX) ? patternConfig[Node.REGEX] : null);
                if (!(node is YamlScalarNode))
                {
                    throw new InvalidConfigurationException("Invalid regex value!");
                }
                regex = ((YamlScalarNode)node).Value;

                node = (patternConfig.ContainsKey(Node.OPTIONS) ? patternConfig[Node.OPTIONS] : null);
                if (node is YamlScalarNode)
                {
                    regexOptions = ((YamlScalarNode)node).Value;
                }
            }
            else
            {
                throw new InvalidConfigurationException("No pattern specified!");
            }

            return new Regex(regex, options | regexOptionsFromString(regexOptions));
        }
コード例 #12
0
        /// <summary>
        /// Adds the specified node to the anchor list.
        /// </summary>
        /// <param name="node">The node.</param>
        public void AddAnchor(YamlNode node)
        {
            if (node.Anchor == null)
            {
                throw new ArgumentException("The specified node does not have an anchor");
            }

            if (anchors.ContainsKey(node.Anchor))
            {
                anchors[node.Anchor] = node;
            }
            else
            {
                anchors.Add(node.Anchor, node);
            }
        }
コード例 #13
0
ファイル: ReferenceLoader.cs プロジェクト: zvrana/bari
        public Reference[] LoadReference(YamlNode node)
        {
            var scalar = node as YamlScalarNode;
            if (scalar != null)
            {
                var refUri = new Uri(scalar.Value);

                if (refUri.Scheme == "alias")
                {
                    // Reference aliases are a core functionality and have special support here:                
                    return new[]
                    {
                        new Reference(refUri, ReferenceType.Build),
                        new Reference(refUri, ReferenceType.Runtime)
                    };
                }
                else
                {
                    return new[] {new Reference(refUri, ReferenceType.Build)};
                }
            }

            var mapping = node as YamlMappingNode;
            if (mapping != null)
            {
                var uri = ((YamlScalarNode)mapping.Children[new YamlScalarNode("uri")]).Value;
                var type = ReferenceType.Build;

                if (mapping.Children.ContainsKey(new YamlScalarNode("type")))
                {
                    Enum.TryParse(((YamlScalarNode) mapping.Children[new YamlScalarNode("type")]).Value, out type);
                }                

                return new[] {new Reference(new Uri(uri), type)};
            }

            return new Reference[0];
        }
コード例 #14
0
ファイル: Yaml.cs プロジェクト: ibebbs/Wyam
        private Dictionary<string, object> GetDocumentMetadata(YamlNode node)
        {
            Dictionary<string, object> metadata = new Dictionary<string, object>();

            // Get the dynamic representation
            if (!string.IsNullOrEmpty(_key))
            {
                metadata[_key] = new DynamicYaml(node);
            }

            // Also get the flat metadata if requested
            if (_flatten)
            {
                YamlMappingNode mappingNode = node as YamlMappingNode;
                if (mappingNode == null)
                {
                    throw new InvalidOperationException("Cannot flatten YAML content that doesn't have a mapping node at the root (or within a root sequence).");
                }

                // Map scalar-to-scalar children
                foreach (KeyValuePair<YamlNode, YamlNode> child in 
                    mappingNode.Children.Where(y => y.Key is YamlScalarNode && y.Value is YamlScalarNode))
                {
                    metadata[((YamlScalarNode)child.Key).Value] = ((YamlScalarNode)child.Value).Value;
                }

                // Map simple sequences
                foreach (KeyValuePair<YamlNode, YamlNode> child in
                    mappingNode.Children.Where(y => y.Key is YamlScalarNode && y.Value is YamlSequenceNode && ((YamlSequenceNode)y.Value).All(z => z is YamlScalarNode)))
                {
                    metadata[((YamlScalarNode)child.Key).Value] = ((YamlSequenceNode)child.Value).Select(a => ((YamlScalarNode)a).Value).ToArray();
                }
            }

            return metadata;
        }
コード例 #15
0
        private static void parseFilterNode(FilterCollection filterCollection, Dictionary<string, Filter> filterMap, YamlNode node)
        {
            string name;
            string[] args;
            if (node is YamlScalarNode)
            {
                name = ((YamlScalarNode)node).Value.Trim().ToLower();
                args = new string[0];
            }
            else if (node is YamlSequenceNode)
            {
                IEnumerator<YamlNode> it = ((YamlSequenceNode)node).Children.GetEnumerator();
                if (!it.MoveNext())
                {
                    throw new InvalidConfigurationException("An empty list as a filter is not valid!");
                }
                node = it.Current;
                if (!(node is YamlScalarNode))
                {
                    throw new InvalidConfigurationException("Filter definitions as a list my only contain strings!");
                }
                name = ((YamlScalarNode)node).Value.Trim().ToLower();
                args = readFilterArgs(it);
            }
            else if (node is YamlMappingNode)
            {
                YamlMappingNode filterConfig = (YamlMappingNode)node;
                IDictionary<YamlNode, YamlNode> childNodes = filterConfig.Children;
                node = (childNodes.ContainsKey(Node.NAME) ? childNodes[Node.NAME] : null);
                if (!(node is YamlScalarNode))
                {
                    throw new InvalidConfigurationException("The filter name is missing or invalid!");
                }
                name = ((YamlScalarNode)node).Value.Trim().ToLower();

                node = (childNodes.ContainsKey(Node.ARGS) ? childNodes[Node.ARGS] : null);
                if (node is YamlSequenceNode)
                {
                    args = readFilterArgs(((YamlSequenceNode)node).Children.GetEnumerator());
                }
                else
                {
                    args = new string[0];
                }
            }
            else
            {
                throw new InvalidConfigurationException("Invalid filter configuration");
            }

            if (!filterMap.ContainsKey(name))
            {
                throw new InvalidConfigurationException("Unknown filter " + name);
            }

            filterCollection.Add(filterMap[name], args);
        }
コード例 #16
0
ファイル: DynamicYaml.cs プロジェクト: roji/YamlDotNet
 public DynamicYaml(YamlNode node)
 {
     Reload(node);
 }
コード例 #17
0
ファイル: DynamicYaml.cs プロジェクト: roji/YamlDotNet
 public void Reload(YamlNode node)
 {
     yamlNode = node;
     mappingNode = yamlNode as YamlMappingNode;
     sequenceNode = yamlNode as YamlSequenceNode;
     scalarNode = yamlNode as YamlScalarNode;
     children = null;
 }
コード例 #18
0
 private String ReadString(YamlNode node)
 {
     return ((YamlScalarNode)node).Value;
 }
コード例 #19
0
        public Form1()
        {
            InitializeComponent();

            tbSrcFilename.Text = Program.srcFilename;
            tbSrcFolder.Text   = Program.srcFolder;
            tbTopic.Text       = Program.topic;
            tbSubTopic.Text    = Program.subTopic;
            //tbCategory.Text = Program.category;
            tbStartFilterCSVList.Text = Program.startFilters;
            tbSkipListLines.Text      = Program.skipFilters.Replace(",", "\r\n");
            tbEndFilterCSVList2.Text  = Program.endFilters;

            srcFilePath = Program.srcPath;

            githubioroot = Environment.GetEnvironmentVariable("GITHUBIOROOT");
            string ymlPath = Path.Combine(githubioroot, "_config.yml");

            if (File.Exists(ymlPath))
            {
                using (var reader = new StreamReader(ymlPath))
                {
                    // Load the stream
                    var yaml2 = new YamlStream();
                    yaml2.Load(reader);

                    // Examine the stream
                    YamlMappingNode rootNode =
                        (YamlMappingNode)yaml2.Documents[0].RootNode;
                    YamlDotNet.RepresentationModel.YamlNode sections = rootNode["sections"];


                    for (int i = 0; i < sections.AllNodes.Count(); i++)
                    {
                        try
                        {
                            YamlNode section = sections.AllNodes.ToList()[i];

                            string Name   = (string)section[0];
                            string Abbrev = (string)section[1];
                            Categorys.Add(new Categoryx(Abbrev, Name));
                        }
                        catch (Exception)
                        {
                            //First section item will catch here as its a list of all nodes.
                            //Just ignore. Could iterate from i=1
                            //Why does this feel like deja vu?
                        }
                    }
                }
                var cats = from c in Categorys select c.Name;
                CategoriesComboBox.Items.AddRange(cats.ToArray());
            }
            else
            {
                Categories = Program.categories.Split(new char[] { ',' });

                CategoriesComboBox.Items.AddRange(Categories);
                if (Program.category != "")
                {
                    if (Categories.ToList().Contains(Program.category))
                    {
                        CategoriesComboBox.SelectedItem = Program.category;
                    }
                }
            }
        }
コード例 #20
0
ファイル: Rules.cs プロジェクト: k1mst0n/Petrovich.NET
            protected YamlNode Find(string name, YamlNode rules, bool matchWholeWord, YamlNode tags)
            {
                foreach (var x in (rules as YamlSequenceNode).Children)
                    if (Match(name, x, matchWholeWord, tags))
                        return x as YamlMappingNode;

                return new YamlMappingNode();
            }
コード例 #21
0
ファイル: Rules.cs プロジェクト: k1mst0n/Petrovich.NET
            protected string FindAndApply(string name, CASES gcase, YamlNode rules, bool[] features)
            {
                try
                {
                    YamlNode rule = FindFor(name, rules, features);

                    return Apply(name, gcase, rule);
                }
                catch (UnknownRuleException ex)
                {
                    return name;
                }
            }
コード例 #22
0
        private static void parseFilterNode(ValidationCollection filterCollection, Dictionary<string, Validator> validatorMap, YamlNode node)
        {
            string name;
            string[] args;
            if (node is YamlScalarNode)
            {
                name = ((YamlScalarNode)node).Value.Trim().ToLower();
                args = new string[0];
            }
            else if (node is YamlSequenceNode)
            {
                IEnumerator<YamlNode> it = ((YamlSequenceNode)node).Children.GetEnumerator();
                if (!it.MoveNext())
                {
                    throw new InvalidConfigurationException("An empty list as a filter is not valid!");
                }
                node = it.Current;
                if (!(node is YamlScalarNode))
                {
                    throw new InvalidConfigurationException("Filter definitions as a list my only contain strings!");
                }
                name = ((YamlScalarNode)node).Value.Trim().ToLower();
                args = readFilterArgs(it);
            }
            else if (node is YamlMappingNode)
            {
                YamlMappingNode filterConfig = (YamlMappingNode)node;
                IDictionary<YamlNode, YamlNode> childNodes = filterConfig.Children;
                node = (childNodes.ContainsKey(Node.NAME) ? childNodes[Node.NAME] : null);
                if (!(node is YamlScalarNode))
                {
                    throw new InvalidConfigurationException("The filter name is missing or invalid!");
                }
                name = ((YamlScalarNode)node).Value.Trim().ToLower();

                node = (childNodes.ContainsKey(Node.ARGS) ? childNodes[Node.ARGS] : null);
                if (node is YamlSequenceNode)
                {
                    args = readFilterArgs(((YamlSequenceNode)node).Children.GetEnumerator());
                }
                else
                {
                    args = new string[0];
                }
            }
            else
            {
                throw new InvalidConfigurationException("Invalid validator configuration");
            }

            bool inverted = false;
            int spaceIndex = name.IndexOf(" ", System.StringComparison.Ordinal);
            if (spaceIndex == 3 && name.Substring(0, 3).Equals("not", StringComparison.OrdinalIgnoreCase))
            {
                inverted = true;
                name = name.Substring(4).Trim();
            }

            if (!validatorMap.ContainsKey(name))
            {
                throw new InvalidConfigurationException("Unknown validator " + name);
            }

            filterCollection.Add(validatorMap[name], inverted, args);
        }
コード例 #23
0
 public YamlElement(string s)
 {
     node = new Y.YamlScalarNode(s);
 }
コード例 #24
0
 protected bool Equals(YamlNode other) =>
 SafeEquals(this.Tag, other.Tag);
コード例 #25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="YamlDocument"/> class with a single scalar node.
 /// </summary>
 public YamlDocument(string rootNode)
 {
     RootNode = new YamlScalarNode(rootNode);
 }
コード例 #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="YamlDocument"/> class.
 /// </summary>
 public YamlDocument(YamlNode rootNode)
 {
     RootNode = rootNode;
 }
コード例 #27
0
ファイル: YamlNode.cs プロジェクト: wattsm/YamlDotNet
 /// <summary>
 /// Provides a basic implementation of Object.Equals
 /// </summary>
 protected bool Equals(YamlNode other)
 {
     // Do not use the anchor in the equality comparison because that would prevent anchored nodes from being found in dictionaries.
     return(SafeEquals(Tag, other.Tag));
 }
コード例 #28
0
ファイル: Rules.cs プロジェクト: k1mst0n/Petrovich.NET
            protected string Inflect(string name, CASES gcase, YamlNode rules)
            {
                int i = 0;

                string[] parts = name.Split('-');

                for (int y = 0; y < parts.Length; y++)
                {
                    bool firstWord = (i += 1) == 1 && parts.Length > 1;

                    parts[y] = FindAndApply(parts[y], gcase, rules, new bool[] { firstWord });
                }

                return string.Join("-", parts);
            }
コード例 #29
0
ファイル: Rules.cs プロジェクト: k1mst0n/Petrovich.NET
            protected string Apply(string name, CASES gcase, YamlNode rule)
            {
                foreach (char c in ModificatorFor(gcase, rule))
                {
                    switch (c)
                    {
                        case '.':
                            break;
                        case '-':
                            name = name.Substring(0, name.Length - 1);
                            break;
                        default:
                            name += c;
                            break;
                    }
                }

                return name;
            }
コード例 #30
0
ファイル: Rules.cs プロジェクト: k1mst0n/Petrovich.NET
            protected bool TagsAllow(YamlNode tags, YamlNode ruleTags)
            {
                ruleTags = ruleTags ?? new YamlMappingNode();

                return (ruleTags as YamlMappingNode).Except(tags as YamlMappingNode).ToArray().Length == 0;
            }
コード例 #31
0
ファイル: Rules.cs プロジェクト: k1mst0n/Petrovich.NET
            protected YamlNode FindFor(string name, YamlNode rules, bool[] features)
            {
                YamlNode tags = ExtractTags(features);

                var exceptions = (from r in (rules as YamlMappingNode).Children
                                  where (r.Key as YamlScalarNode).Value.Equals("exceptions")
                                  select r).FirstOrDefault().Value;

                YamlNode p;

                if (exceptions != null)
                {
                    p = Find(name, exceptions, true, tags);

                    if (p != null && (p as YamlMappingNode).Children.Count > 0) return p;
                }

                var suffixes = (from r in (rules as YamlMappingNode).Children
                                where (r.Key as YamlScalarNode).Value.Equals("suffixes")
                                select r).FirstOrDefault().Value;

                if ((p = Find(name, suffixes, false, tags)) != null)
                    return p;
                else
                    throw new UnknownRuleException(string.Format("Cannot find rule for {0}", name));
            }
コード例 #32
0
 public YamlElement(Y.YamlNode n)
 {
     node = n;
 }
コード例 #33
0
ファイル: Rules.cs プロジェクト: k1mst0n/Petrovich.NET
            protected string ModificatorFor(CASES gcase, YamlNode rule)
            {
                var mods = (from r in (rule as YamlMappingNode).Children
                         where (r.Key as YamlScalarNode).Value.Equals("mods")
                         select r).FirstOrDefault().Value;

                switch (gcase)
                {
                    case CASES.NOMINATIVE:
                        return ".";
                    case CASES.GENITIVE:
                        return ((mods as YamlSequenceNode).Children[0] as YamlScalarNode).Value;
                    case CASES.DATIVE:
                        return ((mods as YamlSequenceNode).Children[1] as YamlScalarNode).Value;
                    case CASES.ACCUSATIVE:
                        return ((mods as YamlSequenceNode).Children[2] as YamlScalarNode).Value;
                    case CASES.INSTRUMENTAL:
                        return ((mods as YamlSequenceNode).Children[3] as YamlScalarNode).Value;
                    case CASES.PREPOSITIONAL:
                        return ((mods as YamlSequenceNode).Children[4] as YamlScalarNode).Value;
                    default:
                        throw new UnknownCaseException(string.Format("Unknown grammatic case: {0}", gcase));
                }
            }
コード例 #34
0
 private double ReadScalar(YamlNode node)
 {
     return double.Parse(ReadString(node));
 }
コード例 #35
0
ファイル: YamlNode.cs プロジェクト: aaubry/YamlDotNet
 /// <summary>
 /// Gets the value associated with a key in a <see cref="YamlMappingNode" />.
 /// </summary>
 public YamlNode this[YamlNode key]
 {
     get
     {
         return ((YamlMappingNode)this).Children[key];
     }
 }
コード例 #36
0
 /// <summary>
 /// Adds the specified node to the collection of nodes with unresolved aliases.
 /// </summary>
 /// <param name="node">
 /// The <see cref="YamlNode"/> that has unresolved aliases.
 /// </param>
 public void AddNodeWithUnresolvedAliases(YamlNode node)
 {
     nodesWithUnresolvedAliases.Add(node);
 }
コード例 #37
0
 /// <summary>
 /// Called when this object is visiting a key-value pair.
 /// </summary>
 /// <param name="key">The left (key) <see cref="YamlNode"/> that is being visited.</param>
 /// <param name="value">The right (value) <see cref="YamlNode"/> that is being visited.</param>
 protected virtual void VisitPair(YamlNode key, YamlNode value)
 {
     key.Accept(this);
     value.Accept(this);
 }
コード例 #38
0
ファイル: DynamicYaml.cs プロジェクト: imgen/YamlDotNet
 public DynamicYaml(YamlNode node)
 {
     Reload(node);
 }
コード例 #39
0
ファイル: YamlNode.cs プロジェクト: aaubry/YamlDotNet
 /// <summary>
 /// Provides a basic implementation of Object.Equals 
 /// </summary>
 protected bool Equals(YamlNode other)
 {
     // Do not use the anchor in the equality comparison because that would prevent anchored nodes from being found in dictionaries.
     return SafeEquals(Tag, other.Tag);
 }
コード例 #40
0
ファイル: Program.cs プロジェクト: djaus2/Jekyll-Filter
        public static void LoadYaml()
        {
            tbSeperator_Text = "@@@";

            //tbSrcFilename.Text = Program.srcFilename;
            //tbSrcFolder.Text = Program.srcFolder;
            //tbTopic.Text = Program.topic;
            //tbSubTopic.Text = Program.subTopic;
            ////tbCategory.Text = Program.category;
            //tbStartFilterCSVList.Text = Program.startFilters;
            //tbSkipListLines.Text = Program.skipFilters.Replace(",", "\r\n");
            //tbEndFilterCSVList2.Text = Program.endFilters;

            //srcFilePath = Program.srcPath;

            string blogSiteRoot = Program.BlogSiteRoot;


            if (blogSiteRoot == null)
            {
                return;
            }
            if (CategorisIn_data)
            {
                ymlPath = Path.Combine(blogSiteRoot, "_data");
                ymlPath = Path.Combine(ymlPath, "sections.yml");
            }
            else
            {
                ymlPath = Path.Combine(blogSiteRoot, "_config.yml");
            }

            if (File.Exists(ymlPath))
            {
                using (var reader = new StreamReader(ymlPath))
                {
                    // Load the stream
                    var yaml2 = new YamlStream();
                    yaml2.Load(reader);

                    if (CategorisIn_data)
                    {
                        // Examine the stream
                        YamlSequenceNode rootNode1 =
                            (YamlSequenceNode)yaml2.Documents[0].RootNode;
                        //YamlMappingNode rootNode =
                        //(YamlMappingNode)yaml2.Documents[0].RootNode;
                        //YamlDotNet.RepresentationModel.YamlNode sections = rootNode["sections"];


                        //if (sections.NodeType == YamlNodeType.Sequence)
                        //{
                        //    YamlSequenceNode ysn = (YamlSequenceNode)sections;

                        //        ysn.Children.Clear();
                        //    var sd = new YamlSequenceNode();
                        //    sd.Add("embed");
                        //    sd.Add("Embedded");
                        //    ysn.Add(sd);
                        //}

                        var sectionsList = rootNode1.Children.ToList();
                        //xx.Add(new YamlNode());

                        for (int i = 0; i < sectionsList.Count(); i++)
                        //for (int i = 0; i < sections.AllNodes.Count(); i++)
                        {
                            //if ( (sectionsList[i]).Count() == 2)
                            {
                                try
                                {
                                    YamlNode section = sectionsList[i];
                                    if (section.NodeType == YamlNodeType.Sequence)
                                    {
                                        YamlSequenceNode ysn = (YamlSequenceNode)section;
                                        if (ysn.Children.Count == 2)
                                        {
                                            //ysn.Children.Add
                                            if (section[0].NodeType == YamlNodeType.Scalar)
                                            {
                                                string Name = (string)section[0];
                                                if (!string.IsNullOrEmpty(Name))
                                                {
                                                    if (section[1].NodeType == YamlNodeType.Scalar)
                                                    {
                                                        string Abbrev = (string)section[1];
                                                        if (!string.IsNullOrEmpty(Abbrev))
                                                        {
                                                            Categorys.Add(new Categoryx(Abbrev, Name));
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                catch (Exception)
                                {
                                    //First section item will catch here as its a list of all nodes.
                                    //Just ignore. Could iterate from i=1
                                    //Why does this feel like deja vu?
                                }
                            }
                        }
                    }
                    else
                    {
                        YamlMappingNode rootNode =
                            (YamlMappingNode)yaml2.Documents[0].RootNode;
                        YamlDotNet.RepresentationModel.YamlNode sections = rootNode["sections"];


                        //if (sections.NodeType == YamlNodeType.Sequence)
                        //{
                        //    YamlSequenceNode ysn = (YamlSequenceNode)sections;

                        //        ysn.Children.Clear();
                        //    var sd = new YamlSequenceNode();
                        //    sd.Add("embed");
                        //    sd.Add("Embedded");
                        //    ysn.Add(sd);
                        //}

                        var sectionsList = sections.AllNodes.ToList();
                        //xx.Add(new YamlNode());

                        for (int i = 0; i < sectionsList.Count(); i++)
                        //for (int i = 0; i < sections.AllNodes.Count(); i++)
                        {
                            //if ( (sectionsList[i]).Count() == 2)
                            {
                                try
                                {
                                    YamlNode section = sectionsList[i];
                                    if (section.NodeType == YamlNodeType.Sequence)
                                    {
                                        YamlSequenceNode ysn = (YamlSequenceNode)section;
                                        if (ysn.Children.Count == 2)
                                        {
                                            //ysn.Children.Add
                                            if (section[0].NodeType == YamlNodeType.Scalar)
                                            {
                                                string Name = (string)section[0];
                                                if (!string.IsNullOrEmpty(Name))
                                                {
                                                    if (section[1].NodeType == YamlNodeType.Scalar)
                                                    {
                                                        string Abbrev = (string)section[1];
                                                        if (!string.IsNullOrEmpty(Abbrev))
                                                        {
                                                            Categorys.Add(new Categoryx(Abbrev, Name));
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                catch (Exception)
                                {
                                    //First section item will catch here as its a list of all nodes.
                                    //Just ignore. Could iterate from i=1
                                }
                            }
                        }
                    }
                }
                //var cats = from c in Categorys select c.Name;
                //CategoriesComboBox.Items.AddRange(cats.ToArray());
            }
            else
            {
                Categories = Program.categories.Split(new char[] { ',' });

                //CategoriesComboBox.Items.AddRange(Categories);
                //if (Program.category != "")
                //{
                //    if (Categories.ToList().Contains(Program.category))
                //        CategoriesComboBox.SelectedItem = Program.category;
                //}
            }
            var cats = from c in Categorys select c.Abbrev;

            Categories = cats.ToArray();
        }