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


C# YamlStream.Save方法代码示例

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


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

示例1: Build

        public static string Build(Asset source)
        {
            var nodes = GetNodes(source);

            var doc = new YamlDocument(nodes);
            var stream = new YamlStream(doc);

            String output = string.Empty;
            var sb = new StringBuilder();

            using (var writer = new StringWriter(sb))
            {
                stream.Save(writer, false);
                output = sb.ToString();
            }

            return output;
        }
开发者ID:JogoShugh,项目名称:VersionOneRestSharpClient,代码行数:18,代码来源:QueryYamlPayloadBuilder.cs

示例2: Encrypt

        public string Encrypt(string config)
        {
            var stream = new YamlStream();
            using (var reader = new StringReader(config))
            {
                stream.Load(reader);
            }

            var mapping = (YamlMappingNode)stream.Documents[0].RootNode;
            mapping.FindNodes("Password").ForEach(x => EncryptTaggedValue(_valueHandler, x));
            mapping.FindNodesToEncrypt().ForEach(x => EncryptTaggedValue(_valueHandler, x));

            var stringBuilder = new StringBuilder();
            using (var textWriter = new StringWriter(stringBuilder))
            {
                stream.Save(textWriter);
                return stringBuilder.ToString();
            }
        }
开发者ID:condep,项目名称:condep-execution,代码行数:19,代码来源:YamlConfigCrypto.cs

示例3: Decrypt

        public string Decrypt(string config)
        {
            using (var reader = new StringReader(config))
            {
                var stream = new YamlStream();
                stream.Load(reader);
                var mapping = (YamlMappingNode)stream.Documents[0].RootNode;

                mapping.FindEncryptedNodes()
                    .ForEach(x => DecryptYamlValue(_valueHandler, x));

                var stringBuilder = new StringBuilder();
                using (var writer = new StringWriter(stringBuilder))
                {
                    stream.Save(writer);

                }
                return stringBuilder.ToString();
            }
        }
开发者ID:condep,项目名称:condep-execution,代码行数:20,代码来源:YamlConfigCrypto.cs

示例4: RoundtripTest

		private void RoundtripTest(string yamlFileName)
		{
			var original = new YamlStream();
			original.Load(YamlFile(yamlFileName));

			var buffer = new StringBuilder();
			original.Save(new StringWriter(buffer));

			Dump.WriteLine(buffer);

			var final = new YamlStream();
			final.Load(new StringReader(buffer.ToString()));

			var originalBuilder = new YamlDocumentStructureBuilder();
			original.Accept(originalBuilder);

			var finalBuilder = new YamlDocumentStructureBuilder();
			final.Accept(finalBuilder);

			Dump.WriteLine("The original document produced {0} events.", originalBuilder.Events.Count);
			Dump.WriteLine("The final document produced {0} events.", finalBuilder.Events.Count);
			Assert.AreEqual(originalBuilder.Events.Count, finalBuilder.Events.Count);

			for (var i = 0; i < originalBuilder.Events.Count; ++i)
			{
				var originalEvent = originalBuilder.Events[i];
				var finalEvent = finalBuilder.Events[i];

				Assert.AreEqual(originalEvent.Type, finalEvent.Type);
				Assert.AreEqual(originalEvent.Value, finalEvent.Value);
			}
		}
开发者ID:modulexcite,项目名称:SharpYaml,代码行数:32,代码来源:YamlStreamTests.cs

示例5: MigrateAssetIfNeeded


//.........这里部分代码省略.........

                var yamlSerializerSettings = YamlSerializer.GetSerializerSettings();
                var tagTypeRegistry = yamlSerializerSettings.TagTypeRegistry;
                bool typeAliased;
                assetType = tagTypeRegistry.TypeFromTag(mappingStart.Tag, out typeAliased);

                expectedVersion = AssetRegistry.GetCurrentFormatVersion(assetType);

                Scalar assetKey;
                while ((assetKey = yamlEventReader.Allow<Scalar>()) != null)
                {
                    // Only allow Id before SerializedVersion
                    if (assetKey.Value == "Id")
                    {
                        yamlEventReader.Skip();
                        continue;
                    }
                    if (assetKey.Value == "SerializedVersion")
                    {
                        serializedVersion = Convert.ToInt32(yamlEventReader.Expect<Scalar>().Value, CultureInfo.InvariantCulture);
                        break;
                    }
                }
            }

            if (serializedVersion > expectedVersion)
            {
                // Try to open an asset newer than what we support (probably generated by a newer Paradox)
                throw new InvalidOperationException(string.Format("Asset of type {0} has been serialized with newer version {1}, but only version {2} is supported. Was this asset created with a newer version of Paradox?", assetType, serializedVersion, expectedVersion));
            }

            if (serializedVersion < expectedVersion)
            {
                // Perform asset upgrade
                context.Log.Verbose("{0} needs update, from version {1} to version {2}", Path.GetFullPath(assetFullPath), serializedVersion, expectedVersion);

                // transform the stream into string.
                string assetAsString;
                using (var assetStream = loadAsset.OpenStream())
                using (var assetStreamReader = new StreamReader(assetStream, Encoding.UTF8))
                {
                    assetAsString = assetStreamReader.ReadToEnd();
                }

                // Load the asset as a YamlNode object
                var input = new StringReader(assetAsString);
                var yamlStream = new YamlStream();
                yamlStream.Load(input);
                var yamlRootNode = (YamlMappingNode)yamlStream.Documents[0].RootNode;

                // Check if there is any asset updater
                var assetUpgraders = AssetRegistry.GetAssetUpgraders(assetType);
                if (assetUpgraders == null)
                {
                    throw new InvalidOperationException(string.Format("Asset of type {0} should be updated from version {1} to {2}, but no asset migration path was found", assetType, serializedVersion, expectedVersion));
                }

                // Instantiate asset updaters
                var currentVersion = serializedVersion;
                while (currentVersion != expectedVersion)
                {
                    int targetVersion;
                    // This will throw an exception if no upgrader is available for the given version, exiting the loop in case of error.
                    var upgrader = assetUpgraders.GetUpgrader(currentVersion, out targetVersion);
                    upgrader.Upgrade(context, currentVersion, targetVersion, yamlRootNode, loadAsset);
                    currentVersion = targetVersion;
                }

                // Make sure asset is updated to latest version
                YamlNode serializedVersionNode;
                var newSerializedVersion = 0;
                if (yamlRootNode.Children.TryGetValue(new YamlScalarNode("SerializedVersion"), out serializedVersionNode))
                {
                    newSerializedVersion = Convert.ToInt32(((YamlScalarNode)serializedVersionNode).Value);
                }

                if (newSerializedVersion != expectedVersion)
                {
                    throw new InvalidOperationException(string.Format("Asset of type {0} was migrated, but still its new version {1} doesn't match expected version {2}.", assetType, newSerializedVersion, expectedVersion));
                }

                context.Log.Info("{0} updated from version {1} to version {2}", Path.GetFullPath(assetFullPath), serializedVersion, expectedVersion);

                var preferredIndent = YamlSerializer.GetSerializerSettings().PreferredIndent;

                // Save asset back to disk
                using (var memoryStream = new MemoryStream())
                {
                    using (var streamWriter = new StreamWriter(memoryStream))
                    {
                        yamlStream.Save(streamWriter, true, preferredIndent);
                    }
                    loadAsset.AssetContent = memoryStream.ToArray();
                }

                return true;
            }

            return false;
        }
开发者ID:releed,项目名称:paradox,代码行数:101,代码来源:AssetMigration.cs

示例6: ToString

        public override string ToString()
        {
            var nodes = Build();

            var doc = new YamlDocument(nodes);
            var stream = new YamlStream(doc);

            String output = string.Empty;
            var sb = new StringBuilder();

            using (var writer = new StringWriter(sb))
            {
                stream.Save(writer, false);
                output = sb.ToString();
            }

            return output;
        }
开发者ID:JogoShugh,项目名称:VersionOneRestSharpClient,代码行数:18,代码来源:QueryApiQueryBuilder.cs

示例7: ConfigureCassandra

        protected virtual void ConfigureCassandra()
        {
            string configRoot = Path.Combine(_CassandraRoot, "conf");
            if (!Directory.Exists(configRoot))
            {
                Directory.CreateDirectory(configRoot);
            }

            string configFile = Path.Combine(configRoot,CASSANDRA_CONFIG_FILE);

            using (var input = new StreamReader(_TemplateConfigFile))
            using (var output = new StreamWriter(configFile, false))
            {
                Trace.WriteLine("Loading Default Config");

                // Load the stream
                var yamlInput = new YamlStream();
                yamlInput.Load(input);

                var rootOutputNode = new YamlMappingNode();
                var outputDoc = new YamlDocument(rootOutputNode);
                var yamlOutput = new YamlStream(outputDoc);

                if (yamlInput.Documents.Count > 0)
                {
                    var mapping = (YamlMappingNode)yamlInput.Documents[0].RootNode;
                    var reservedConfigs = new string[] { "data_file_directories" };
                    foreach (var entry in mapping.Children.Where(m => !reservedConfigs.Contains(m.Key.ToString())))
                    {
                        rootOutputNode.Add(entry.Key, entry.Value);
                    }
                }

                Trace.WriteLine("Writing Critical Config values");
                //write important config values reglardless of what was provided in package

                rootOutputNode.Add(new YamlScalarNode("data_file_directories"), new YamlSequenceNode(new YamlScalarNode(_DataPath)));

                //Write seeds
                //rootOutputNode.Add(new YamlScalarNode("cloud.azureruntime.bridge"), new YamlScalarNode(_BridgePipeName));

                yamlOutput.Save(output,false);

                //Not sure why this is happening but let us clean out chas in end of file.

                Trace.TraceInformation("Saved cassandra config file {0}", configFile);

            }
        }
开发者ID:garvincasimir,项目名称:Cassandra-Azure-PAAS,代码行数:49,代码来源:CassandraManager.cs

示例8: YamlDotNetYamlRead

    void YamlDotNetYamlRead()
    {
        //textAsset
        string fileName=AssetDatabase.GetAssetPath(textAsset);
        // open
        var input = new StreamReader(fileName, Encoding.UTF8);
        var yaml = new YamlStream();
        yaml.Load(input);
        //var mapping = (YamlMappingNode)yaml.Documents[0].RootNode;
        Debug.Log("yaml.Documents.Count="+ yaml.Documents.Count);
        //foreach (YamlMappingNode item in (YamlMappingNode)yaml.Documents) {
        for(int i = 0; i < yaml.Documents.Count; i++){

            string str="";
            //str="(YamlMappingNode)yaml.Documents["+i+"].RootNode= ";
            str=str+(YamlMappingNode)yaml.Documents[i].RootNode+"\n";//Macの場合 optionキーを押しながら¥を押す
            Debug.Log(str);
            //for(int j = 0; j < yaml.Documents[i].AllNodes.Count(); j++){
                //string str1="";
                //str="(YamlMappingNode)yaml.Documents["+i+"].RootNode= ";
            //	str1=str1+(YamlDotNet.RepresentationModel.YamlNode)yaml.Documents[i].AllNodes[j]+"\n";//Macの場合 optionキーを押しながら¥を押す
            //}
            foreach (YamlDotNet.RepresentationModel.YamlNode yamlNode in yaml.Documents[i].AllNodes) {
                Debug.Log(yamlNode.ToString());
            }
            //foreach (var child in item) {
            //	Debug.Log(((YamlScalarNode)child.Key).Value + "\t" +
            //		((YamlScalarNode)child.Value).Value);
            //}

        }
        TextWriter textWriter = new StreamWriter(Application.dataPath + "/YamlDotNetForUnityYAML/Editor/YamlDotNetYamlReadAndSave_yaml.yaml");
        textWriter.WriteLine("%YAML 1.1");//無視される。
        textWriter.WriteLine("%TAG !u! tag:unity3d.com,2011:");//無視される。
        yaml.Save(textWriter);

        textWriter.Close();
        AssetDatabase.Refresh();
        //var Year = (YamlScalarNode)mapping.Children[new YamlScalarNode("Year")];
        //Debug.Log("Year "+ Year.Value);
        //var Description = (YamlScalarNode)mapping.Children[new YamlScalarNode("Description")];
        //Debug.Log("Desciption "+ Description.Value);
        //Debug.Log("Contents:");

        //var items = (YamlSequenceNode)mapping.Children[new YamlScalarNode("Contents")];
        //foreach (YamlMappingNode item in items) {
        //	foreach (var child in item) {
        //		Debug.Log(((YamlScalarNode)child.Key).Value + "\t" +
        //			((YamlScalarNode)child.Value).Value);
        //	}
        //}
    }
开发者ID:whaison,项目名称:YamlDotNetForUnityYAML,代码行数:52,代码来源:YamlDotNetYamlReadAndSave.cs

示例9: RoundtripTest

        private void RoundtripTest(string yamlFileName)
        {
            YamlStream original = new YamlStream();
            original.Load(YamlFile(yamlFileName));

            StringBuilder buffer = new StringBuilder();
            original.Save(new StringWriter(buffer));

            Console.WriteLine(buffer.ToString());

            YamlStream final = new YamlStream();
            final.Load(new StringReader(buffer.ToString()));

            YamlDocumentStructureBuilder originalBuilder = new YamlDocumentStructureBuilder();
            original.Accept(originalBuilder);

            YamlDocumentStructureBuilder finalBuilder = new YamlDocumentStructureBuilder();
            final.Accept(finalBuilder);

            Console.WriteLine("The original document produced {0} events.", originalBuilder.Events.Count);
            Console.WriteLine("The final document produced {0} events.", finalBuilder.Events.Count);
            Assert.Equal(originalBuilder.Events.Count, finalBuilder.Events.Count);

            for (int i = 0; i < originalBuilder.Events.Count; ++i)
            {
                YamlNodeEvent originalEvent = originalBuilder.Events[i];
                YamlNodeEvent finalEvent = finalBuilder.Events[i];

                Assert.Equal(originalEvent.Type, finalEvent.Type);
                //Assert.Equal(originalEvent.Tag, finalEvent.Tag);
                //Assert.Equal(originalEvent.Anchor, finalEvent.Anchor);
                Assert.Equal(originalEvent.Value, finalEvent.Value);
            }
        }
开发者ID:imgen,项目名称:YamlDotNet,代码行数:34,代码来源:YamlStreamTests.cs

示例10: ConfigureElasticsearch

        protected virtual void ConfigureElasticsearch()
        {
            string configRoot = Path.Combine(_ElasticRoot, "Config");
            if (!Directory.Exists(configRoot))
            {
                Directory.CreateDirectory(configRoot);
            }
            string configFile = Path.Combine(configRoot,ELASTICSEARCH_CONFIG_FILE);

            using (var input = new StreamReader(_TemplateConfigFile))
            using (var output = new StreamWriter(configFile, false))
            {
                Trace.WriteLine("Loading Default Config");
                var config = new Dictionary<string, string>();
                // Load the stream
                var yamlInput = new YamlStream();
                yamlInput.Load(input);

                var rootOutputNode = new YamlMappingNode();
                var outputDoc = new YamlDocument(rootOutputNode);
                var yamlOutput = new YamlStream(outputDoc);

                if (yamlInput.Documents.Count > 0)
                {
                    var mapping = (YamlMappingNode)yamlInput.Documents[0].RootNode;
                    var reservedConfigs = new string[] { "path.data", "path.work", "path.logs", "path.plugins" };
                    foreach (var entry in mapping.Children.Where(m => !reservedConfigs.Contains(m.Key.ToString())))
                    {
                        rootOutputNode.Add(entry.Key, entry.Value);
                    }
                }

                Trace.WriteLine("Writing Critical Config values");
                //write important config values reglardless of what was provided in package

                rootOutputNode.Add(new YamlScalarNode("path.data"), new YamlScalarNode(_DataPath));
                rootOutputNode.Add(new YamlScalarNode("path.work"), new YamlScalarNode(_Settings.TempDirectory));
                rootOutputNode.Add(new YamlScalarNode("path.logs"), new YamlScalarNode(_Settings.LogDirectory));
                rootOutputNode.Add(new YamlScalarNode("path.plugin"), new YamlScalarNode(_PluginRoot));
                rootOutputNode.Add(new YamlScalarNode("node.name"), new YamlScalarNode(_Settings.NodeName));
                rootOutputNode.Add(new YamlScalarNode("cloud.azureruntime.bridge"), new YamlScalarNode(_BridgePipeName));

                yamlOutput.Save(output);
                Trace.TraceInformation("Saved elasticsearch config file {0}", configFile);

            }
        }
开发者ID:kunlqt,项目名称:Elasticsearch-Azure-PAAS,代码行数:47,代码来源:ElasticsearchManager.cs


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