• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# YamlStream类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



YamlStream类属于命名空间,在下文中一共展示了YamlStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: 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


示例3: 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


示例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: 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


示例8: 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


示例9: 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


示例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: GetPackageVersion

        public static Version GetPackageVersion(string fullPath)
        {
            try
            {
                foreach (var packageFullPath in EnumeratePackageFullPaths(fullPath))
                {
                    // Load the package as a Yaml dynamic node, so that we can check Xenko version from dependencies
                    var input = new StringReader(File.ReadAllText(packageFullPath));
                    var yamlStream = new YamlStream();
                    yamlStream.Load(input);
                    dynamic yamlRootNode = new DynamicYamlMapping((YamlMappingNode)yamlStream.Documents[0].RootNode);

                    SemanticVersion dependencyVersion = null;

                    foreach (var dependency in yamlRootNode.Meta.Dependencies)
                    {
                        // Support paradox legacy projects
                        if ((string)dependency.Name == "Xenko" || (string)dependency.Name == "Paradox")
                        {
                            dependencyVersion = new SemanticVersion((string)dependency.Version);

                            // Paradox 1.1 was having incorrect version set (1.0), read it from .props file
                            if (dependencyVersion.Version.Major == 1 && dependencyVersion.Version.Minor == 0)
                            {
                                var propsFilePath = Path.Combine(Path.GetDirectoryName(packageFullPath) ?? "", Path.GetFileNameWithoutExtension(packageFullPath) + ".props");
                                if (File.Exists(propsFilePath))
                                {
                                    using (XmlReader propsReader = XmlReader.Create(propsFilePath))
                                    {
                                        propsReader.MoveToContent();
                                        if (propsReader.ReadToDescendant("SiliconStudioPackageParadoxVersion"))
                                        {
                                            if (propsReader.Read())
                                            {
                                                dependencyVersion = new SemanticVersion(propsReader.Value);
                                            }
                                        }
                                    }
                                }
                            }
                            break;
                        }
                    }

                    // Stop after first version
                    if (dependencyVersion != null)
                    {
                        return new Version(dependencyVersion.Version.Major, dependencyVersion.Version.Minor);
                    }
                }
            }
            catch (Exception)
            {
            }

            return null;
        }
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:57,代码来源:PackageSessionHelper.Solution.cs


示例14: 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


示例15: Parse

 public IEnumerable<YamlDocument> Parse(string yaml)
 {
     using (var stream = new StringReader(yaml))
     {
         var yamlStream = new YamlStream();
         yamlStream.Load (stream);
         return yamlStream.Documents;
     }
 }
开发者ID:TomasEkeli,项目名称:Forseti,代码行数:9,代码来源:YamlParser.cs


示例16: 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


示例17: TransformText

        /// <summary>
        /// Create the template output
        /// </summary>
        public virtual string TransformText()
        {
            this.Write("\r\n");
            
            #line 10 "C:\Users\dean\projs\iRacingReplayOverlay.net\iRacingSDK.Net\GenerateDataModels\SessionInfoTemplate.tt"
 
	var data = iRacing.GetDataFeed().First();

	var yaml = new YamlStream();
	yaml.Load(new StringReader(data.SessionData.Raw));

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

            
            #line default
            #line hidden
            this.Write(@"
// This file is part of iRacingSDK.
//
// Copyright 2014 Dean Netherton
// https://github.com/vipoo/iRacingSDK.Net
//
// iRacingSDK is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// iRacingSDK is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with iRacingSDK.  If not, see <http://www.gnu.org/licenses/>.



using System;
using System.Collections.Generic;
using System.Linq;

namespace iRacingSDK
{
    public partial class SessionData
    {
        ");
            
            #line 47 "C:\Users\dean\projs\iRacingReplayOverlay.net\iRacingSDK.Net\GenerateDataModels\SessionInfoTemplate.tt"
 foreach(var kv in mapping)
            Process(kv.Key.ToString(), kv.Value);
        
            
            #line default
            #line hidden
            this.Write("    }\r\n}\r\n\r\n");
            return this.GenerationEnvironment.ToString();
        }
开发者ID:jrc60752,项目名称:iRacingSDK.Net,代码行数:60,代码来源:SessionInfoTemplate.cs


示例18: 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


示例19: FromFile

        public static IEnumerable<OptionSource> FromFile(string fileName, string sectionName = null)
        {
            var options = new List<OptionSource>();
            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException(fileName);
            }
            var yamlStream = new YamlStream();
            var reader = new StringReader(File.ReadAllText(fileName));
            try
            {
                yamlStream.Load(reader);
            }
            catch (Exception ex)
            {
                throw new OptionException(String.Format("An invalid configuration file has been specified. {0}{1}", Environment.NewLine, ex.Message), "config");
            }

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

            if (!String.IsNullOrEmpty(sectionName))
            {
                Func<KeyValuePair<YamlNode, YamlNode>, bool> predicate = x =>
                    x.Key.ToString() == sectionName && x.Value.GetType() == typeof(YamlMappingNode);

                var nodeExists = yamlNode.Children.Any(predicate);
                if (nodeExists)
                {
                    yamlNode = (YamlMappingNode)yamlNode.Children.First(predicate).Value;
                }
            }
            foreach (var yamlElement in yamlNode.Children)
            {
                var yamlScalarNode = yamlElement.Value as YamlScalarNode;
                var yamlSequenceNode = yamlElement.Value as YamlSequenceNode;
                if (yamlSequenceNode != null)
                {
                    var values = yamlSequenceNode.Children.Select(x => ((YamlScalarNode)x).Value);
                    try
                    {
                        //TODO GFY DO WE PREFER STRINGS OR TYPES HERE?
                        options.Add(OptionSource.String("Config File", yamlElement.Key.ToString(), values.ToArray()));
                    }
                    catch (InvalidCastException)
                    {
                        var message = String.Format("Please ensure that {0} is a valid YAML array.{1}", yamlElement.Key, Environment.NewLine);
                        throw new OptionException(message, yamlElement.Key.ToString());
                    }
                }
                else if (yamlScalarNode != null)
                {
                    options.Add(OptionSource.String("Config File", yamlElement.Key.ToString(), yamlElement.Value.ToString()));
                }
            }
            return options;
        }
开发者ID:danieldeb,项目名称:EventStore,代码行数:56,代码来源:Yaml.cs


示例20: ParseModel

 private static NamedModel ParseModel(string input)
 {
     if (input == null) throw new ArgumentNullException("input");
     using (var yamlSource = File.OpenText(input))
     {
         var stream = new YamlStream();
         stream.Load(yamlSource);
         var visitor = new ComposeNamedModelVisitor();
         stream.Accept(visitor);
         return visitor.Model;
     }
 }
开发者ID:yreynhout,项目名称:MessTalk,代码行数:12,代码来源:Program.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# YellowstonePathology类代码示例发布时间:2022-05-24
下一篇:
C# YamlSequenceNode类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap