当前位置: 首页>>代码示例>>C#>>正文


C# YamlStream.Load方法代码示例

本文整理汇总了C#中YamlStream.Load方法的典型用法代码示例。如果您正苦于以下问题:C# YamlStream.Load方法的具体用法?C# YamlStream.Load怎么用?C# YamlStream.Load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在YamlStream的用法示例。


在下文中一共展示了YamlStream.Load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OLDdScriptCommand

 void OLDdScriptCommand(CommandDetails command)
 {
     string outp = scriptcommand_base(command);
     if (outp == null)
     {
         return;
     }
     Chat(command.Channel.Name, command.Pinger + ColorGeneral + "Scanning " + ColorHighlightMajor + (Utilities.CountChar(outp, '\n') + 1) + ColorGeneral + " lines...");
     try
     {
         YamlStream ys = new YamlStream();
         ys.Load(new StringReader(outp));
         int nodes = 0;
         for (int i = 0; i < ys.Documents.Count; i++)
         {
             nodes += ys.Documents[i].AllNodes.ToArray().Length;
         }
     }
     catch (Exception ex)
     {
         Chat(command.Channel.Name, ColorGeneral + "Error in your YAML: " + ColorHighlightMajor + ex.Message);
     }
     List<string> warnings = dsCheck(outp);
     Chat(command.Channel.Name, ColorGeneral + "Found " + ColorHighlightMajor + warnings.Count + ColorGeneral + " potential issues.");
     for (int i = 0; i < warnings.Count && i < 8; i++)
     {
         Chat(command.Channel.Name, ColorHighlightMinor + "- " + i + ") " + warnings[i]);
     }
 }
开发者ID:DenizenScript,项目名称:DenizenIRCBot,代码行数:29,代码来源:ScriptcheckCommands.cs

示例2: Execute

 public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
 {
     return inputs
         .AsParallel()
         .SelectMany(input =>
         {
             List<Dictionary<string, object>> documentMetadata = new List<Dictionary<string, object>>();
             using (TextReader contentReader = new StringReader(input.Content))
             {
                 YamlStream yamlStream = new YamlStream();
                 yamlStream.Load(contentReader);
                 foreach (YamlDocument document in yamlStream.Documents)
                 {
                     // If this is a sequence, get a document for each item
                     YamlSequenceNode rootSequence = document.RootNode as YamlSequenceNode;
                     if (rootSequence != null)
                     {
                         documentMetadata.AddRange(rootSequence.Children.Select(GetDocumentMetadata));
                     }
                     else
                     {
                         // Otherwise, just get a single set of metadata
                         documentMetadata.Add(GetDocumentMetadata(document.RootNode));
                     }
                 }
             }
             return documentMetadata.Select(metadata => context.GetDocument(input, metadata));
         })
         .Where(x => x != null);
 }
开发者ID:ibebbs,项目名称:Wyam,代码行数:30,代码来源:Yaml.cs

示例3: Parse

        private void Parse(string path)
        {
            var yamlStream = new YamlStream();
            var fileText = File.ReadAllText(path);
            using (var stringReader = new StringReader(fileText))
            {
                yamlStream.Load(stringReader);
            }

            var mapping = (YamlMappingNode)yamlStream.Documents[0].RootNode;

            foreach (var entry in mapping.Children)
            {
                switch (entry.Key.ToString().ToLower())
                {
                    case "source":
                        Source = entry.Value.ToString();
                        break;
                    case "destination":
                        Destination = entry.Value.ToString();
                        break;
                    case "permalink":
                        Permalink = entry.Value.ToString();
                        break;
                    case "exclude":
                        Exclude = ((YamlSequenceNode)entry.Value).Children.Select(n => System.IO.Path.Combine(Source, n.ToString()));
                        break;
                    default:
                        break;
                }
            }
        }
开发者ID:rbwestmoreland,项目名称:Hyde,代码行数:32,代码来源:ConfigurationSettings.cs

示例4: YamlHeader

        public static IDictionary<string, object> YamlHeader(this string text)
        {
            var results = new Dictionary<string, object>();
            var m = r.Matches(text);
            if (m.Count == 0)
                return results;

            var input = new StringReader(m[0].Groups[1].Value);

            var yaml = new YamlStream();
            yaml.Load(input);

            var root = yaml.Documents[0].RootNode;

            var collection = root as YamlMappingNode;
            if (collection != null)
            {
                foreach (var entry in collection.Children)
                {
                    var node = entry.Key as YamlScalarNode;
                    if (node != null)
                    {
                        results.Add(node.Value, entry.Value);
                    }
                }
            }

            return results;
        }
开发者ID:noelitoa,项目名称:pretzel,代码行数:29,代码来源:YamlExtensions.cs

示例5: Execute

        public override string Execute(string input)
        {
            var yamlDocument = new StringReader(input);

            var yaml = new YamlStream();
            yaml.Load(yamlDocument);

            var mapping = (YamlMappingNode)yaml.Documents[0].RootNode;

            foreach (var entry in mapping.Children)
            {
                var name = entry.Key.ToString();

                if (entry.Value is YamlMappingNode)
                {
                    AddRelationsFromLinks(name, entry.Value);
                }
                else if (entry.Value is YamlSequenceNode)
                {
                    AddAttributesWithExplicitActionFromArray(name, entry.Value);
                }
                else if (entry.Value is YamlScalarNode)
                {
                    AddAttributeFromScalarProperty(name, entry.Value);
                }
            }

            return Builder.GetAssetXml();
        }
开发者ID:versionone,项目名称:VersionOne.SDK.Experimental,代码行数:29,代码来源:TranslateHalYamlInputToAssetXml.cs

示例6: LoadFromTextReader

		public static YamlNode LoadFromTextReader(TextReader reader)
		{
			var yaml = new YamlStream();
			yaml.Load(reader);

			return yaml.Documents.First().RootNode;
		}
开发者ID:adbrowne,项目名称:EventStore,代码行数:7,代码来源:YamlDoc.cs

示例7: Read

        public IConfiguration Read(string path)
        {
            var entity = new Configuration();

            try
            {
                var yamlStream = new YamlStream();
                var fileText = File.ReadAllText(path);
                using (var stringReader = new StringReader(fileText))
                {
                    yamlStream.Load(stringReader);
                }
                var mapping = (YamlMappingNode)yamlStream.Documents[0].RootNode;

                if (mapping.Children.ContainsKey(new YamlScalarNode("dateformat")))
                {
                    entity.DateFormat = mapping.Children[new YamlScalarNode("dateformat")].ToString();
                }

                if (mapping.Children.ContainsKey(new YamlScalarNode("title")))
                {
                    entity.Title = mapping.Children[new YamlScalarNode("title")].ToString();
                }

                if (mapping.Children.ContainsKey(new YamlScalarNode("author")))
                {
                    entity.Author = mapping.Children[new YamlScalarNode("author")].ToString();
                }
            }
            catch
            {
            }

            return entity;
        }
开发者ID:typeset,项目名称:typeset,代码行数:35,代码来源:ConfigurationRepository.cs

示例8: DynamicYaml

        /// <summary>
        /// Initializes a new instance of <see cref="DynamicYaml"/> from the specified stream.
        /// </summary>
        /// <param name="stream">A stream that contains a YAML content. The stream will be disposed</param>
        /// <param name="disposeStream">Dispose the stream when reading the YAML content is done. <c>true</c> by default</param>
        public DynamicYaml(Stream stream, bool disposeStream = true)
        {
            if (stream == null) throw new ArgumentNullException(nameof(stream));
            // transform the stream into string.
            string assetAsString;
            try
            {
                using (var assetStreamReader = new StreamReader(stream, Encoding.UTF8))
                {
                    assetAsString = assetStreamReader.ReadToEnd();
                }
            }
            finally
            {
                if (disposeStream)
                {
                    stream.Dispose();
                }
            }

            // Load the asset as a YamlNode object
            var input = new StringReader(assetAsString);
            yamlStream = new YamlStream();
            yamlStream.Load(input);
            
            if (yamlStream.Documents.Count != 1 || !(yamlStream.Documents[0].RootNode is YamlMappingNode))
                throw new YamlException("Unable to load the given stream");
        }
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:33,代码来源:DynamicYaml.cs

示例9: Start

    void Start () {
        var input = new StringReader(Document);

        var yaml = new YamlStream();
        yaml.Load(input);

        // Examine the stream
        var mapping =
            (YamlMappingNode)yaml.Documents[0].RootNode;

        var output = new StringBuilder();
        foreach (var entry in mapping.Children)
        {
            output.AppendLine(((YamlScalarNode)entry.Key).Value);
        }

        var items = (YamlSequenceNode)mapping.Children[new YamlScalarNode("items")];
        foreach (YamlMappingNode item in items)
        {
            output.AppendLine(
                String.Format("{0}\t{1}",
                    item.Children[new YamlScalarNode("part_no")],
                    item.Children[new YamlScalarNode("descrip")]
                )
            );
        }
        Debug.Log(output);
    }
开发者ID:mxoconnell,项目名称:GGJ_2016,代码行数:28,代码来源:Loading_a_YAML_stream.cs

示例10: openRulesetToolStripMenuItem_Click

    private void openRulesetToolStripMenuItem_Click(object sender, EventArgs e)
    {
      if( ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK )
      {
        string rulesetContents;

        rulesetFilename = ofd.FileName;
        this.Text = "M.A.R.S. for OpenXCOM [" + rulesetFilename + "]";

        rulesetContents = System.IO.File.ReadAllText( ofd.FileName );
        rulesetStream = new YamlStream();

        using( System.IO.StringReader docReader = new System.IO.StringReader(rulesetContents) )
        {
          rulesetStream.Load( docReader );
        }

        rulesetRoot = (YamlMappingNode)rulesetStream.Documents[0].RootNode;

        foreach( System.Collections.Generic.KeyValuePair<YamlNode, YamlNode> child in rulesetRoot.Children )
        {
          // child are "<name>:" markers in the yaml
          TreeNode coreNode = null;
          TreeNode objNode = null;

          switch( child.Key.ToString() )
          {
            case "countries":
              coreNode = oxcTree.Nodes.Add( "Countries" );
              coreNode.Tag = child.Value;

              rulesetCountries = new Rulesets.Countries();
              rulesetCountries.Load( (YamlSequenceNode)child.Value );

              foreach( Rulesets.Country c in rulesetCountries.CountryList )
              {
                objNode = coreNode.Nodes.Add( c.CountryString );
                objNode.Tag = c;
              }

              break;

            case "regions":
              coreNode = oxcTree.Nodes.Add( "Regions" );
              coreNode.Tag = child.Value;
              break;
          }

          /*
          if( coreNode == null )
          {
            coreNode = oxcTree.Nodes.Add( child.Key.ToString() );
            coreNode.Tag = child.Value;
          }
          */

        }
        
      }
    }
开发者ID:pmprog,项目名称:OpenXCOM.Tools,代码行数:60,代码来源:Form1.cs

示例11: LoadSimpleDocument

		public void LoadSimpleDocument() {
			var stream = new YamlStream();
			stream.Load(YamlFile("test2.yaml"));
			
			Assert.AreEqual(1, stream.Documents.Count);
			Assert.IsInstanceOf<YamlScalarNode>(stream.Documents[0].RootNode);
			Assert.AreEqual("a scalar", ((YamlScalarNode)stream.Documents[0].RootNode).Value);
		}
开发者ID:modulexcite,项目名称:SharpYaml,代码行数:8,代码来源:YamlStreamTests.cs

示例12: LoadSimpleDocument

		public void LoadSimpleDocument() {
			var stream = new YamlStream();
			stream.Load(Yaml.StreamFrom("02-scalar-in-imp-doc.yaml"));
			
			Assert.Equal(1, stream.Documents.Count);
			Assert.IsType<YamlScalarNode>(stream.Documents[0].RootNode);
			Assert.Equal("a scalar", ((YamlScalarNode)stream.Documents[0].RootNode).Value);
		}
开发者ID:Gwynneth,项目名称:YamlDotNet,代码行数:8,代码来源:YamlStreamTests.cs

示例13: AccessingAllNodesOnInfinitelyRecursiveDocumentThrows

        public void AccessingAllNodesOnInfinitelyRecursiveDocumentThrows()
        {
            var stream = new YamlStream();
            stream.Load(Yaml.ParserForText("&a [*a]"));

            var accessAllNodes = new Action(() => stream.Documents.Single().AllNodes.ToList());

            accessAllNodes.ShouldThrow<MaximumRecursionLevelReachedException>("because the document is infinitely recursive.");
        }
开发者ID:aaubry,项目名称:YamlDotNet,代码行数:9,代码来源:YamlStreamTests.cs

示例14: ReadFromFile

 public static YamlStream ReadFromFile(string path)
 {
     StreamReader sr = new StreamReader(path);
     string content = sr.ReadToEnd();
     var input = new StringReader(content);
     var yaml = new YamlStream();
     yaml.Load(input);
     return yaml;
 }
开发者ID:ismethr,项目名称:gas-geological-map,代码行数:9,代码来源:YamlHelper.cs

示例15: load

        public static IEnumerable<Classification> load(StreamReader input)
        {
            // Load the stream
            var yaml = new YamlStream();
            yaml.Load(input);

            var root = (YamlMappingNode)yaml.Documents[0].RootNode;
            return load(root);
        }
开发者ID:abingham,项目名称:OhSnap,代码行数:9,代码来源:AOLoader.cs


注:本文中的YamlStream.Load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。