Represents an YAML document.
예제 #1
0
        public static string WriteToString(this YamlObjectStore yaml)
        {
            var doc  = new YamlDotNet.RepresentationModel.YamlDocument(yaml.MappingNode);
            var sb   = new System.Text.StringBuilder();
            var strm = new YamlDotNet.RepresentationModel.YamlStream();

            strm.Add(doc);
            strm.Save(new System.IO.StringWriter(sb));
            return(sb.ToString());
        }
예제 #2
0
        /// <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...");

            foreach (var pluginUri in LoadPlugins(yaml.RootNode))
                pluginLoader.Load(pluginUri);

            var goals = LoadGoals(yaml.RootNode);
            var defaultGoal = LoadDefaultGoal(goals, yaml.RootNode) ?? Suite.DebugGoal;
            var suite = suiteFactory.CreateSuite(new HashSet<Goal>(goals.Values), defaultGoal);

            parser.SetActiveGoal(suite.ActiveGoal);

            suite.Name = parser.GetScalarValue(yaml.RootNode, "suite", "Error reading the name of the suite");
            suite.Version = ParseVersion(parser.GetOptionalScalarValue(yaml.RootNode, "version", null));
            suite.Copyright = parser.GetOptionalScalarValue(yaml.RootNode, "copyright", null);

            LoadParameters(suite, suite, yaml.RootNode);

            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);
            }

            LoadSourceSetIgnoreLists(suite.SourceSetIgnoreLists, yaml.RootNode);

            validator.Validate(suite);

            log.Debug("Finished processing YAML document.");
            return suite;
        }
        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;
        }
        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;
        }
예제 #5
0
        /// <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;
        }
예제 #6
0
            public void AssignAnchors(YamlDocument document)
            {
                this.existingAnchors.Clear();
                this.visitedNodes.Clear();
                document.Accept(this);
                Random random = new Random();

                foreach (KeyValuePair <YamlNode, bool> pair in this.visitedNodes)
                {
                    if (pair.Value)
                    {
                        while (true)
                        {
                            string item = random.Next().ToString(CultureInfo.InvariantCulture);
                            if (!this.existingAnchors.Contains(item))
                            {
                                this.existingAnchors.Add(item);
                                pair.Key.Anchor = item;
                                break;
                            }
                        }
                    }
                }
            }
예제 #7
0
            public void AssignAnchors(YamlDocument document)
            {
                existingAnchors.Clear();
                visitedNodes.Clear();

                document.Accept(this);

                Random random = new Random();

                foreach (var visitedNode in visitedNodes)
                {
                    if (visitedNode.Value)
                    {
                        string anchor;
                        do
                        {
                            anchor = random.Next().ToString(CultureInfo.InvariantCulture);
                        } while (existingAnchors.Contains(anchor));
                        existingAnchors.Add(anchor);

                        visitedNode.Key.Anchor = anchor;
                    }
                }
            }
예제 #8
0
 /// <summary>
 /// Called after this object finishes visiting a <see cref="YamlDocument"/>.
 /// </summary>
 /// <param name="document">
 /// The <see cref="YamlDocument"/> that has been visited.
 /// </param>
 protected virtual void Visited(YamlDocument document)
 {
     // Do nothing.
 }
예제 #9
0
 void IYamlVisitor.Visit(YamlDocument document)
 {
     Visit(document);
     Visited(document);
 }
예제 #10
0
 /// <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);
 }
예제 #11
0
		protected override void Visit(YamlDocument document)
		{
			WriteIndent();
			Console.WriteLine("Visit(YamlDocument)");
			indent++;
		}
예제 #12
0
		protected override void Visited(YamlDocument document)
		{
			indent--;
			WriteIndent();
			Console.WriteLine("Visited(YamlDocument)");
		}
예제 #13
0
 protected override void Visit(YamlDocument document)
 {
     myDocument = new XmlDocument();
     current = myDocument;
     PushNode(options.RootElementName);
 }
		public virtual void Visit(YamlDocument document)
		{
			VisitChildren(document);
		}
예제 #15
0
 protected override void Visit(YamlDocument document)
 {
     _mappingIndentation = 0;
     _scalarCount = 0;
 }
예제 #16
0
			public void AssignAnchors(YamlDocument document)
			{
				existingAnchors.Clear();
				visitedNodes.Clear();

				document.Accept(this);

				Random random = new Random();
				foreach (var visitedNode in visitedNodes)
				{
					if (visitedNode.Value)
					{
						string anchor;
						do
						{
							anchor = random.Next().ToString(CultureInfo.InvariantCulture);
						} while (existingAnchors.Contains(anchor));
						existingAnchors.Add(anchor);

						visitedNode.Key.Anchor = anchor;
					}
				}
			}
 /// <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);
 }
예제 #18
0
 /// <summary>
 ///     Creates a new instances an attaches the given <see cref="YamlDocument" /> to the underlying stream.
 /// </summary>
 /// <param name="doc"></param>
 public Provider(YamlDocument doc)
 {
     EnsureActiveYamlStream();
     _yamlStream.Documents.Add(doc);
 }
예제 #19
0
 void IYamlVisitor.Visit(YamlDocument document)
 {
     this.Visit(document);
     this.Visited(document);
 }
예제 #20
0
 protected virtual void Visited(YamlDocument document)
 {
 }
        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);

            }
        }
 /// <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);
     }
 }
예제 #23
0
            public void AssignAnchors(YamlDocument document)
            {
                existingAnchors.Clear();
                visitedNodes.Clear();

                document.Accept(this);

                var random = new Random();
                foreach (var visitedNode in visitedNodes)
                {
                    if (visitedNode.Value)
                    {
                        string anchor;
                        // If the existing anchor is not already used, we can have it
                        if (!string.IsNullOrEmpty(visitedNode.Key.Anchor) && !existingAnchors.Contains(visitedNode.Key.Anchor))
                        {
                            anchor = visitedNode.Key.Anchor;
                        }
                        else
                        {
                            do
                            {
                                anchor = random.Next().ToString(CultureInfo.InvariantCulture);
                            } while (existingAnchors.Contains(anchor));
                        }

                        existingAnchors.Add(anchor);
                        visitedNode.Key.Anchor = anchor;
                    }
                }
            }
 void IYamlVisitor.Visit(YamlDocument document)
 {
     Visit(document);
     Visited(document);
 }
예제 #25
0
 /// <summary>
 /// Converts a <see cref="YamlDocument"/> to <see cref="XmlDocument"/>.
 /// </summary>
 /// <param name="document">The YAML document to convert.</param>
 /// <returns></returns>
 public XmlDocument ToXml(YamlDocument document)
 {
     YamlToXmlDocumentVisitor visitor = new YamlToXmlDocumentVisitor(options);
     document.Accept(visitor);
     return visitor.Document;
 }
 /// <summary>
 /// Called after this object finishes visiting a <see cref="YamlDocument"/>.
 /// </summary>
 /// <param name="document">
 /// The <see cref="YamlDocument"/> that has been visited.
 /// </param>
 protected virtual void Visited(YamlDocument document)
 {
     // Do nothing.
 }
        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);

            }
        }