本文整理汇总了C#中YamlStream类的典型用法代码示例。如果您正苦于以下问题:C# YamlStream类的具体用法?C# YamlStream怎么用?C# YamlStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
YamlStream类属于命名空间,在下文中一共展示了YamlStream类的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]);
}
}
示例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);
}
示例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);
}
示例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;
}
示例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();
}
示例6: LoadFromTextReader
public static YamlNode LoadFromTextReader(TextReader reader)
{
var yaml = new YamlStream();
yaml.Load(reader);
return yaml.Documents.First().RootNode;
}
示例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");
}
示例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;
}
示例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;
}
}
}
示例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;
}
*/
}
}
}
示例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);
}
示例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);
}
示例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;
}
示例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.");
}
示例15: Parse
public IEnumerable<YamlDocument> Parse(string yaml)
{
using (var stream = new StringReader(yaml))
{
var yamlStream = new YamlStream();
yamlStream.Load (stream);
return yamlStream.Documents;
}
}