public static string ToYaml(ByamlExt.Byaml.BymlFileData data) { /*var settings = new SerializerSettings() * { * EmitTags = false, * EmitAlias = false, * DefaultStyle = SharpYaml.YamlStyle.Flow, * SortKeyForMapping = false, * EmitShortTypeName = true, * EmitCapacityForList = false, * LimitPrimitiveFlowSequence = 4, * }; * * settings.RegisterTagMapping("!u", typeof(uint)); * settings.RegisterTagMapping("!l", typeof(int)); * settings.RegisterTagMapping("!d", typeof(double)); * settings.RegisterTagMapping("!ul", typeof(ulong)); * settings.RegisterTagMapping("!ll", typeof(long)); * * var serializer = new Serializer(settings); * return serializer.Serialize(data);*/ NodePaths.Clear(); refNodeId = 0; YamlNode root = SaveNode("root", data.RootNode); YamlMappingNode mapping = new YamlMappingNode(); mapping.Add("Version", data.Version.ToString()); mapping.Add("IsBigEndian", (data.byteOrder == ByteOrder.BigEndian).ToString()); mapping.Add("SupportPaths", data.SupportPaths.ToString()); mapping.Add("HasReferenceNodes", (refNodeId != 0).ToString()); mapping.Add("root", root); NodePaths.Clear(); refNodeId = 0; var doc = new YamlDocument(mapping); YamlStream stream = new YamlStream(doc); var buffer = new StringBuilder(); using (var writer = new StringWriter(buffer)) { stream.Save(writer, true); return(writer.ToString()); } }
public static void FileWriter2(MappingNode n, string filename) //para auto-save { n.IsRoot = true; YamlMappingNode rootNode = new YamlMappingNode(); CreateNodeVisitor visitor = new CreateNodeVisitor(); //SaveTree.saveChildrenMapping(n, rootNode); n.Accept(visitor, rootNode); YamlDocument doc = new YamlDocument(rootNode); var yaml = new YamlStream(doc); using (TextWriter writer = File.CreateText(@"..\\Config_Files\\bin\\" + filename)) yaml.Save(writer, false); }
public static Metadata Build(YamlDocument document) { if (document == null) { return(null); } var rootMapping = (YamlMappingNode)document.RootNode; var root = rootMapping.Children.Select(child => child.Key).FirstOrDefault(); var canonicalName = root?.ToString(); var modifiers = (YamlMappingNode)rootMapping.Children[new YamlScalarNode(canonicalName)]; var metadata = new Metadata(canonicalName); foreach (var(key, value) in modifiers) { switch (key.ToString()) { case KEY_PROPERTIES: { var properties = BuildProperties((YamlMappingNode)value, false); metadata.SetProperties(properties.Select(property => (MetadataProperty)property).ToList()); break; } case KEY_ACCESS_TYPE: Enum.TryParse(value.ToString(), true, out FieldAccessType fieldAccessType); metadata.SetAccessType(fieldAccessType); break; case KEY_VIRTUAL_PROPERTIES: { var properties = BuildProperties((YamlMappingNode)value, true); metadata.SetVirtualProperties(properties.Select(property => (MetadataVirtualProperty)property) .ToList()); break; } } } return(metadata); }
/// <summary> /// Reads a <see cref="UnityPrefabInstance"/> from the specified Yaml node. /// </summary> public UnityPrefabInstance(string documentId, YamlDocument yaml, UnityObjectKey key) : base(documentId, key) { YamlMappingNode rootNode = (YamlMappingNode)yaml.RootNode; YamlMappingNode objectNode = (YamlMappingNode)rootNode.Children.First().Value; // read parent prefab YamlNode prefabNode; if (objectNode.Children.TryGetValue("m_ParentPrefab", out prefabNode)) { YamlMappingNode prefabMappingNode = (YamlMappingNode)prefabNode; UnityObjectKey reference = ParseReference(prefabMappingNode, key); AddRelationship(reference, "is-instance-of-prefab", "has-prefab-instance"); } // read instance modifications YamlMappingNode modificationNode = (YamlMappingNode)objectNode.Children["m_Modification"]; YamlSequenceNode modifications = ((YamlSequenceNode)modificationNode.Children["m_Modifications"]); foreach (YamlMappingNode listNode in modifications.Children) { UnityObjectKey reference; YamlScalarNode propertyPathNode = (YamlScalarNode)listNode.Children["propertyPath"]; YamlScalarNode valueNode = (YamlScalarNode)listNode.Children["value"]; // save overridden GameObject name if (propertyPathNode.Value == "m_Name") { Name = valueNode.Value; } YamlMappingNode targetNode = (YamlMappingNode)listNode.Children["target"]; reference = ParseReference(targetNode, key); AddRelationship(reference, "modifies-member", "modified-by-instance"); YamlMappingNode objectReferenceNode = (YamlMappingNode)listNode.Children["objectReference"]; reference = ParseReference(objectReferenceNode, key); if (!reference.IsEmpty) { AddRelationship(reference, "has-reference-to", "is-referenced-by"); } } }
protected Pnyx parseDocument(YamlDocument document, ArgsInputOutput argsIo) { Pnyx p = new Pnyx(); p.setSettings(stdIoDefault: true); // forces STD-IN/OUT as defaults p.setNumberedInputOutput(argsIo); if (document.RootNode.NodeType != YamlNodeType.Sequence) { throw new InvalidArgumentException("Expected a YAML sequence as the document root, but found: {0}", document.RootNode.NodeType.ToString()); } YamlSequenceNode topLevel = (YamlSequenceNode)document.RootNode; parseBlock(p, topLevel); return(p); }
public void SaveToFile(string path) { YamlNode root = ConvertToYaml(); YamlDocument doc = new YamlDocument(root); YamlStream ys = new YamlStream(doc); try { using (StreamWriter sw = new StreamWriter(path)) { ys.Save(sw); } } catch (Exception) { Console.Error.WriteLine("Error saving config file: " + path); } }
private static void UpdateYamlFile(Options options, FilePusher.Models.Config config) { YamlStream yamlStream = new(); using (StreamReader streamReader = new(config.SourcePath)) { yamlStream.Load(streamReader); } if (yamlStream.Documents.Count > 1) { throw new NotSupportedException("Multi-document YAML files are not supported."); } YamlDocument doc = yamlStream.Documents[0]; YamlNode currentNode = doc.RootNode; string[] queryParts = options.NodeQueryPath.Split('/'); for (int i = 0; i < queryParts.Length; i++) { currentNode = currentNode[queryParts[i]]; } if (currentNode is YamlScalarNode scalarNode) { scalarNode.Value = options.NewValue; } else { throw new NotSupportedException("Last node in the path must be a scalar value."); } StringBuilder stringBuilder = new(); using StringWriter writer = new(stringBuilder); yamlStream.Save(new CustomEmitter(writer), assignAnchors: false); string newContent = stringBuilder.ToString(); Console.WriteLine( $"Writing the following content to file '{config.SourcePath}':{Environment.NewLine}{newContent}"); File.WriteAllText(config.SourcePath, stringBuilder.ToString()); }
public YamlStream GetYamlStream() { var stream = new YamlStream(); var root = new YamlMappingNode(); var doc = new YamlDocument(root); stream.Add(doc); // file info root.Add(FileInformation.Name, FileInformation.ToYaml()); // Logging root.Add(Logging.Name, Logging.ToYaml()); // Plugins root.Add(Plugins.Name, Plugins.ToYaml()); return(stream); }
// ------------------------------------------------------------------- // Public // ------------------------------------------------------------------- public YamlFluentDeserializer SetDocument(int index) { if (this.stream.Documents.Count < index) { throw new SerializationException("Stream does not have a document at index " + index); } this.activeDocument = this.stream.Documents[index]; this.activeDocumentIndex = index; if (this.activeDocument.RootNode == null) { throw new SerializationException("Document has no root node"); } this.ClearParentStack(); this.PushParent(this.activeDocument.RootNode); return(this); }
public static void WriteDefaultConfig(string filePath) { var stream = new YamlStream(); var root = new YamlMappingNode(); var doc = new YamlDocument(root); stream.Add(doc); // Logging root.Add("logging", CreateDefaultLoggingConfig()); // Plugins root.Add("plugins", CreateDefaultPluginConfig()); using (var writer = new StreamWriter(filePath)) { stream.Save(writer, assignAnchors: false); } }
/// <summary> /// Reads a <see cref="UnityGameObject"/> from the specified Yaml node. /// </summary> public UnityObject(string documentId, YamlDocument yaml, UnityObjectKey key) : base(key) { // add to document DocumentId = documentId.ToString(); AddRelationship(DocumentId, "is-in-document", "document-contains-object"); if (yaml != null) { try { Parse(yaml, key); } catch (Exception e) { ParseError = e; } } }
// ---- public void Save(string fileName) { // Update entities node EntitiesNode.Children.Clear(); foreach (var kvp in Entities) { EntitiesNode.Add(kvp.Value); } using var writer = new StreamWriter(fileName); var document = new YamlDocument(Root); var stream = new YamlStream(document); var emitter = new Emitter(writer); var fixer = new TypeTagPreserver(emitter); stream.Save(fixer, false); writer.Flush(); }
/// <summary> /// Reads a <see cref="UnityGameObject"/> from the specified Yaml node. /// </summary> public UnityGameObject(string documentId, YamlDocument yaml, UnityObjectKey key) : base(documentId, yaml, key) { YamlMappingNode rootNode = (YamlMappingNode)yaml.RootNode; YamlMappingNode objectNode = (YamlMappingNode)rootNode.Children.First().Value; // read object name Name = ((YamlScalarNode)objectNode.Children["m_Name"]).Value; // read object component links YamlSequenceNode components = ((YamlSequenceNode)objectNode.Children["m_Component"]); foreach (YamlMappingNode listNode in components.Children) { YamlMappingNode component = listNode.Children["component"] as YamlMappingNode; UnityObjectKey reference = ParseReference(component, key); AddRelationship(reference, "has-component", ""); } }
private YamlDocument Preprocess(YamlDocument inputDocument) { // replace choice branches with their respective choices var outputDocument = new YamlDocument { Start = inputDocument.Start, Values = ResolveChoices(inputDocument.Values), End = inputDocument.End }; // read variables, if any var variables = new Dictionary <string, string>(); if (outputDocument.Values.FirstOrDefault() is YamlMap rootMap) { // find optional `Variables` section var variablesEntry = rootMap.Entries.FirstOrDefault(entry => entry.Key.Scalar.Value == "Variables"); if (variablesEntry.Value != null) { // remove `Variables` from root map rootMap.Entries = rootMap.Entries.Where(entry => entry.Key.Scalar.Value != "Variables").ToList(); // parse `Variables` into a dictionary AtLocation("Variables", () => { if (variablesEntry.Value is YamlMap variablesMap) { variables = variablesMap.Entries.Select(entry => new KeyValuePair <string, string>( entry.Key.Scalar.Value, AtLocation(entry.Key.Scalar.Value, () => { if (entry.Value is YamlScalar scalar) { return(scalar.Scalar.Value); } AddError("must be a string value"); return(null); }, null) )).Where(entry => entry.Value != null) .ToDictionary(entry => entry.Key, entry => entry.Value); } else { AddError("'Variables' section expected be a map"); } });
private void QuoteValues(YamlDocument doc) { foreach (var node in doc.AllNodes.OfType <YamlScalarNode>()) { if (node.Style == ScalarStyle.DoubleQuoted || node.Style == ScalarStyle.SingleQuoted || node.Value == null) { continue; } // Don't quote numbers if (double.TryParse(node.Value, out _)) { continue; } node.Style = ScalarStyle.DoubleQuoted; } }
public static string ToYaml(FFNT header) { YamlMappingNode mapping = new YamlMappingNode(); mapping.Add("Platform", header.Platform.ToString()); mapping.Add("Version", header.Version.ToString("X")); mapping.Add("FontInfo", SaveFontInfo(header.FontSection)); mapping.Add("KerningTable", SaveKerningTable(header.KerningTable)); var doc = new YamlDocument(mapping); YamlStream stream = new YamlStream(doc); var buffer = new StringBuilder(); using (var writer = new StringWriter(buffer)) { stream.Save(writer, true); return(writer.ToString()); } }
/// <summary> /// Writes the full representation of this UDT to a text stream. /// </summary> /// <param name="text">The text stream to output to</param> internal override void WriteToFile(TextWriter text) { var rootNode = new YamlMappingNode(); rootNode.AddStringMapping(Utils.UidKey, this.uid); rootNode.AddStringMapping(Utils.NameKey, this.name); rootNode.AddStringMapping(Utils.TypeKey, this.itemType); rootNode.AddStringMapping(Utils.NamespaceKey, this.namespaceName.AsObsoleteUid()); if (!string.IsNullOrEmpty(this.comments.Documentation)) { rootNode.AddStringMapping(Utils.SummaryKey, this.comments.Documentation); } // UDTs get fancy treatment of examples if (!string.IsNullOrEmpty(this.comments.Remarks) || !string.IsNullOrEmpty(this.comments.Example)) { var rems = this.comments.Remarks; if (!string.IsNullOrEmpty(this.comments.Example)) { // \r instead of \n because the YAML.Net serialization doubles \n. // In the file the newline is correct; YAML.Net serializes \r as \n. rems += "\r\r### Examples\r" + this.comments.Example; } rootNode.AddStringMapping(Utils.RemarksKey, rems); } rootNode.Add(Utils.SyntaxKey, this.syntax); if (!string.IsNullOrEmpty(this.comments.References)) { rootNode.AddStringMapping(Utils.ReferencesKey, this.comments.References); } if (this.comments.SeeAlso.Count > 0) { rootNode.Add(Utils.SeeAlsoKey, Utils.BuildSequenceNode(this.comments.SeeAlso)); } var doc = new YamlDocument(rootNode); var stream = new YamlStream(doc); text.WriteLine("### " + Utils.QsYamlMime + Utils.AutogenerationWarning); stream.Save(text, false); }
public void TestRAML1() { EAMetaModel meta = new EAMetaModel(); meta.setupAPIPackage(); EAFactory api = APIModel.createAPI1(meta); YamlMappingNode map = new YamlMappingNode(); RAMLManager.REIFY_VERSION = APIAddinClass.RAML_1_0; //Test RAMLManager.reifyAPI(EARepository.Repository, api.clientElement, map); YamlDocument d = new YamlDocument(map); YamlStream stream = new YamlStream(); stream.Documents.Add(d); StringWriter writer = new StringWriter(); stream.Save(writer, false); string yaml = writer.ToString(); Assert.IsTrue(yaml.Contains("is: [notcacheable]")); Assert.IsTrue(yaml.Contains("dev-environment")); Assert.IsTrue(yaml.Contains("prod-environment")); Assert.IsTrue(yaml.Contains("someuriparameter")); Assert.IsTrue(yaml.Contains("data_item_description")); FileManager fileManager = new FileManager(null); fileManager.setBasePath("."); fileManager.initializeAPI(EARepository.currentPackage.Name); fileManager.setup(APIAddinClass.RAML_0_8); fileManager.exportAPI(EARepository.currentPackage.Name, APIAddinClass.RAML_0_8, yaml.ToString(), ""); }
/// <summary> /// Process an already loaded <c>YamlDocument</c> and returns the loaded suite model. /// </summary> /// <param name="yaml">The yaml document to process.</param> /// <returns>Returns a loaded model if succeeds. On error it throws an exception, never /// returns <c>null</c>.</returns> protected Suite LoadYaml(YamlDocument yaml) { Contract.Requires(yaml != null); Contract.Requires(yaml.RootNode != null); Contract.Ensures(Contract.Result <Suite>() != null); log.Debug("Processing YAML document..."); var goals = new HashSet <Goal>(LoadGoals(yaml.RootNode)); var suite = suiteFactory.CreateSuite(goals); parser.SetActiveGoal(suite.ActiveGoal); suite.Name = parser.GetScalarValue(yaml.RootNode, "suite", "Error reading the name of the suite"); suite.Version = parser.GetOptionalScalarValue(yaml.RootNode, "version", null); suite.Copyright = parser.GetOptionalScalarValue(yaml.RootNode, "copyright", null); foreach (KeyValuePair <string, YamlNode> item in parser.EnumerateNamedNodesOf(yaml.RootNode, "modules")) { var module = suite.GetModule(item.Key); if (item.Value != null) { LoadModule(module, item.Value); } } foreach (KeyValuePair <string, YamlNode> item in parser.EnumerateNamedNodesOf(yaml.RootNode, "products")) { var product = suite.GetProduct(item.Key); if (item.Value != null) { LoadProduct(suite, product, item.Value); } } LoadParameters(suite, suite, yaml.RootNode); log.Debug("Finished processing YAML document."); return(suite); }
//yaml parser for items ID private void yamlPriceReader() { YamlStream stream = new YamlStream(); using (var reader = new StreamReader(@"Resources/typeIDs.yaml")) { stream.Load(reader); } YamlDocument yaDoc = stream.Documents[0]; YamlMappingNode yamm = (YamlMappingNode)(yaDoc.RootNode); DGVPrices.DataSource = null; MainPricesDT.Clear(); MainPricesDT = CreatePriceTable(); foreach (KeyValuePair <YamlNode, YamlNode> KVP in yamm.Children) { int id = Convert.ToInt32(((YamlScalarNode)KVP.Key).Value); string name = ""; try { name = ((YamlScalarNode)((YamlMappingNode)((YamlMappingNode)KVP.Value).Children["name"]).Children[langselector.Text]).Value; } catch (Exception ex) { try { name = ((YamlScalarNode)((YamlMappingNode)((YamlMappingNode)KVP.Value).Children["name"]).Children["en"]).Value; } catch (Exception ex1) { name = id.ToString(); // MessageBox.Show(id.ToString(), ex.Message); } } //MessageBox.Show(name); DataRow ndr = MainPricesDT.NewRow(); ndr["id"] = id; ndr["Name"] = name; MainPricesDT.Rows.Add(ndr); } ShowPriceDGV(); }
public static YamlNode XPath(this YamlDocument doc, string path) { if (!(doc.RootNode is YamlMappingNode mappingNode)) // Cannot search non mapping nodes { return(null); } var sections = new Queue <string>(path.Split('/', StringSplitOptions.RemoveEmptyEntries)); while (sections.Count > 1) { string nextSection = sections.Dequeue(); var key = new YamlScalarNode(nextSection); if (mappingNode == null || !mappingNode.Children.ContainsKey(key)) { return(null); // Path does not exist } mappingNode = mappingNode[key] as YamlMappingNode; } return(mappingNode?[new YamlScalarNode(sections.Dequeue())]); }
/// <summary> /// Creates a folder from this package with the correct structure /// </summary> public void GenerateFolder(string to = "") { foreach (var file in this) { var outPath = Path.Combine(to, file.Value.PackPath); var metaPath = outPath + ".meta"; Directory.CreateDirectory(Path.GetDirectoryName(outPath)); File.Copy(file.Value.GetDiskPath(), outPath); using (var writer = new StreamWriter(metaPath)) // the meta file { var doc = new YamlDocument(file.Value.GetMeta()); var ys = new YamlStream(doc); ys.Save(writer); } var fi = new FileInfo(metaPath); using (var fs = fi.Open(FileMode.Open)) { fs.SetLength(fi.Length - 3 - Environment.NewLine.Length); } } }
/// <summary> /// Creates a yml file for the namespace containing the /// item(s) of the source document. /// If source document contains MyNameSpace.Utilities.MyClass, /// created file will contain namespace MyNameSpace.Utilities /// </summary> /// <param name="sourceDoc"></param> /// <returns></returns> private YamlDocument createTargetDoc(YamlDocument sourceDoc) { var root = new YamlMappingNode(); root.Tag = "### YamlMime:ManagedReference"; var items = new YamlSequenceNode(); root.Add("items", items); var references = new YamlSequenceNode(); root.Add("references", references); string name = getUidOfFirstItem(sourceDoc, true); var namespaceInfo = createItem(name, "Namespace"); items?.Add(namespaceInfo); return(new YamlDocument(root)); }
/// <summary> /// Reads a <see cref="UnityGameObject"/> from the specified Yaml node. /// </summary> public UnityObject(string documentId, YamlDocument yaml, UnityObjectKey key) : base(key) { // add to document DocumentId = documentId.ToString(); AddRelationship(DocumentId, "is-in-document", "document-contains-object"); if (yaml != null) { YamlMappingNode rootNode = (YamlMappingNode)yaml.RootNode; // create prefab link YamlNode prefabNode; if (rootNode.Children.TryGetValue("m_PrefabParentObject", out prefabNode)) { YamlMappingNode prefabMappingNode = (YamlMappingNode)prefabNode; UnityObjectKey reference = ParseReference(prefabMappingNode, key); AddRelationship(reference, "is-instance-of-prefab", "has-instance"); } } }
/// <summary> /// Initiates the parsing process of a fragment. Not thread safe and should only be called once on a parsing context /// </summary> /// <param name="yamlDocument"></param> /// <param name="version">OpenAPI version of the fragment</param> /// <param name="diagnostic">Diagnostic object which will return diagnostic results of the operation.</param> /// <returns>An OpenApiDocument populated based on the passed yamlDocument </returns> internal T ParseFragment <T>(YamlDocument yamlDocument, OpenApiSpecVersion version, OpenApiDiagnostic diagnostic) where T : IOpenApiElement { var node = ParseNode.Create(this, diagnostic, yamlDocument.RootNode); T element = default(T); switch (version) { case OpenApiSpecVersion.OpenApi2_0: VersionService = new OpenApiV2VersionService(); element = this.VersionService.LoadElement <T>(node); break; case OpenApiSpecVersion.OpenApi3_0: this.VersionService = new OpenApiV3VersionService(); element = this.VersionService.LoadElement <T>(node); break; } return(element); }
private void LoadPubspecFile() { // YAML parser _pubspecStream = new YamlStream(); using (StreamReader reader = _pubspecFile.OpenText()) { _pubspecStream.Load(reader); } /* * name: flutter_xamarin_protocol * description: A new Flutter package project. * version: 0.0.1 * author: * homepage: * * environment: * sdk: ">=2.1.0 <3.0.0" * * dependencies: * flutter: * sdk: flutter # Your other regular dependencies here # json_annotation: ^2.0.0 # # dev_dependencies: # flutter_test: # sdk: flutter # Your other dev_dependencies here # build_runner: ^1.0.0 # json_serializable: ^2.0.0 */ if (_pubspecStream.Documents.Count != 1) { throw new ArgumentException($"The specified directory contains an invalid '{PubspecFilename}' file."); } _pubspecDocument = _pubspecStream.Documents[0]; }
/// <summary> /// Adds information from source doc to target doc. /// After calling this, the target doc contains all necessary references to the source item /// and also updates its information to contain source items information, such as the 'langs' section. /// </summary> private bool addSourceInfo(YamlDocument sourceDoc, YamlDocument targetDoc) { var sourceRoot = sourceDoc?.RootNode as YamlMappingNode; var targetItem = getItem(targetDoc, 0); YamlSequenceNode sourceItems = sourceRoot?.Children?[new YamlScalarNode("items")] as YamlSequenceNode; if (sourceItems?.Children == null) { return(false); } if (sourceItems.Children.Count > 1) { string name = getUidOfFirstItem(sourceDoc, false); Debug.WriteLine($"Found several items in document with ithem {name}"); } bool changes = false; foreach (var item in sourceItems.Children) { var sourceItem = item as YamlMappingNode; if (sourceItem == null) { continue; } bool isNamespace = (sourceItem?.Children?[new YamlScalarNode("type")] as YamlScalarNode).Value == "Namespace"; if (!isNamespace) { continue; } changes |= addSourceToChildren(sourceItem, targetItem); changes |= copySequence(sourceItem, targetItem, "langs"); changes |= addReference(targetDoc, sourceItem); } return(changes); }
public void Transform() { // Arrange var document = new YamlDocument(@"a: x: 1 b: 2 c: 3"); // Act document.ReplaceKey(new[] { "A", "y" }, "2"); document.ReplaceKey(new[] { "a", "z", "t", "w" }, "3"); document.ReplaceKey(new[] { "b" }, "5"); document.ReplaceKey(new[] { "c", "a" }, "1"); document.ReplaceKey(new[] { "c", "b" }, "2"); document.ReplaceKey(new[] { "c", "b", "t" }, "3"); document.ReplaceKey(new[] { "D" }, "4"); var result = document.ToString(); // Assert Assert.Equal(@"a: x: 1 y: 2 z: t: w: 3 b: 5 c: a: 1 b: t: 3 d: 4 ", result, ignoreCase: true, ignoreLineEndingDifferences: true, ignoreWhiteSpaceDifferences: true); }
private static void AddAsset(string tempPath, string fromFile, string toPath) { YamlDocument meta = GetMeta(fromFile) ?? GenerateMeta(fromFile, toPath); string guid = GetGuid(meta); Directory.CreateDirectory(Path.Combine(tempPath, guid)); if (File.Exists(fromFile)) { string assetPath = Path.Combine(tempPath, guid, "asset"); File.Copy(fromFile, assetPath); } string pathnamePath = Path.Combine(tempPath, guid, "pathname"); File.WriteAllText(pathnamePath, toPath); string metaPath = Path.Combine(tempPath, guid, "asset.meta"); SaveMeta(metaPath, meta); }
/// <summary> /// Serializes any extra values that are in the ExtraValues collection /// and creates YAML from them that can be appended to the serialized /// Yaml data of the schema bound fields. /// </summary> /// <param name="extraValues"></param> /// <returns></returns> public string ExtraValuesToYaml(IDictionary <string, object> extraValues) { // serialize extra fields that aren't part of the scheme explicitly var root = new YamlMappingNode(); var doc = new YamlDocument(root); foreach (var extra in extraValues) { root.Add(extra.Key.ToString(), extra.Value?.ToString().Trim()); } var yamlStream = new YamlStream(doc); var buffer = new StringBuilder(); string yamlText; using (var writer = new StringWriter(buffer)) { yamlStream.Save(writer); yamlText = writer.ToString(); } return(yamlText.TrimEnd('\r', '\n', '.') + mmApp.NewLine); }
public static string Dump(YamlDocument doc) { return Dump(new List<YamlDocument> { doc }); }
void IYamlVisitor.Visit(YamlDocument document) { Visit(document); VisitChildren(document); Visited(document); }
/// <summary> /// Called when this object is visiting a <see cref="YamlDocument"/>. /// </summary> /// <param name="document"> /// The <see cref="YamlDocument"/> that is being visited. /// </param> protected virtual void Visit(YamlDocument document) { // Do nothing. }
/// <summary> /// Called when this object is visiting a <see cref="YamlDocument"/>. /// </summary> /// <param name="document"> /// The <see cref="YamlDocument"/> that is being visited. /// </param> public virtual void Visit(YamlDocument document) { VisitChildren(document); }
/// <summary> /// Visits every child of a <see cref="YamlDocument"/>. /// </summary> /// <param name="document"> /// The <see cref="YamlDocument"/> that is being visited. /// </param> protected virtual void VisitChildren(YamlDocument document) { if (document.RootNode != null) { document.RootNode.Accept(this); } }
/// <summary> /// Called when this object is visiting a <see cref="YamlDocument"/>. /// </summary> /// <param name="document"> /// The <see cref="YamlDocument"/> that is being visited. /// </param> protected virtual void Visit(YamlDocument document) { VisitChildren(document); }