Exemplo n.º 1
0
        /// <summary>
        /// This method will process the data receieved from YAML file
        /// </summary>
        /// <param name="filePath"></param>
        private static void ProcessYamlFile(string filePath)
        {
            TextReader reader = File.OpenText(filePath);

            YamlStream yaml = new YamlStream();

            yaml.Load(reader);

            List <YamlProducts> yamlProducts = new List <YamlProducts>();



            var pTry = (YamlSequenceNode)yaml.Documents[0].RootNode;

            var count = pTry.Children.Count;

            for (int i = 0; i < count; i++)
            {
                YamlProducts product = new YamlProducts();

                var mappingYamlContents = (YamlMappingNode)((YamlSequenceNode)yaml.Documents[0].RootNode)[i];

                foreach (var entry in mappingYamlContents.Children)
                {
                    if (((YamlScalarNode)entry.Key).Value.ToString() == "tags")
                    {
                        product.tag = ((YamlScalarNode)entry.Value).ToString();
                    }

                    if (((YamlScalarNode)entry.Key).Value.ToString() == "name")
                    {
                        product.name = ((YamlScalarNode)entry.Value).ToString();
                    }

                    if (((YamlScalarNode)entry.Key).Value.ToString() == "twitter")
                    {
                        product.twitter = ((YamlScalarNode)entry.Value).ToString();
                    }
                }
                yamlProducts.Add(product);
            }

            foreach (var sectionItems in yamlProducts)
            {
                PrintYamlContent(sectionItems);
                //Save To Database
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// This method is priting the YAML content that is been extracted from the application
 /// </summary>
 /// <param name="sectionItems"></param>
 private static void PrintYamlContent(YamlProducts sectionItems)
 {
     Console.WriteLine(@"Importing: Tags: {0} , Name: {1} , Twitter : {2}", sectionItems.tag, sectionItems.name, sectionItems.twitter);
 }