コード例 #1
0
        public void SimpleCategoryWithMultipleSimpleKeys()
        {
            string formula    = "[Category]";// \n Key = Value \n Key1 = Value1 \n Key2 = Value2 \n Key3 = Value3";
            int    Keys_Count = 4;

            for (int i = 0; i < Keys_Count; i++)
            {
                formula = string.Concat(formula, $" \n Key{i} = Value{i}");
            }
            var parser = new ContentParser();

            var categories = new List <Category>();

            parser.CategoryDiscovered += (sender, category) => categories.Add(category);
            parser.Parse(formula);

            var firstCategory = categories.First();

            Assert.IsTrue(firstCategory.Name == "Category");
            Assert.IsTrue(firstCategory.Keys.Count == 4);

            for (var i = 0; i < Keys_Count; i++)
            {
                Assert.IsTrue(firstCategory.Keys[i].Id == $"Key{i}");
                Assert.IsTrue(firstCategory.Keys[i].KeyValues.First().Value == $"Value{i}");
            }
        }
コード例 #2
0
        public void MultipleCategoryParsing()
        {
            int CATEGORIES_COUNT = new Random().Next(1, 10);
            var testCategories   = new List <string>();

            for (int i = 1; i <= CATEGORIES_COUNT; i++)
            {
                testCategories.Add($"[CATEGORY{i}]");
            }

            string test = string.Join(" \n ", testCategories);

            var categories = new List <Category>();
            var parser     = new ContentParser();

            parser.CategoryDiscovered += (sender, category) => categories.Add(category);

            parser.Parse(test);

            Assert.IsTrue(categories.Count == CATEGORIES_COUNT);

            for (var i = 1; i <= CATEGORIES_COUNT; i++)
            {
                Assert.IsTrue(categories.Any(x => x.Name == $"CATEGORY{i}"));
            }
        }
コード例 #3
0
        public void RealLifeFileTestDeep()
        {
            var content    = File.ReadAllText(Path.Combine(testFolder, "oem100.inf"));
            var parser     = new ContentParser();
            var categories = new List <Category>();

            parser.CategoryDiscovered += (sender, category) => categories.Add(category);
            parser.Parse(content);

            //Check categories names
            Assert.AreEqual(categories[0].Name, "Version");
            Assert.AreEqual(categories[1].Name, "DestinationDirs");
            Assert.AreEqual(categories[2].Name, "Manufacturer");
            Assert.AreEqual(categories[3].Name, "Standard");
            Assert.AreEqual(categories[4].Name, "Standard.NTAMD64");
            Assert.AreEqual(categories[5].Name, "Razer.NTx86");
            Assert.AreEqual(categories[6].Name, "Razer.NTAMD64");
            Assert.AreEqual(categories[7].Name, "Razer.NTAMD64.HW");
            Assert.AreEqual(categories[8].Name, "Razer.NTAMD64.Services");
            Assert.AreEqual(categories[9].Name, "SourceDisksNames");
            Assert.AreEqual(categories[10].Name, "SourceDisksFiles");
            Assert.AreEqual(categories[11].Name, "Razer.NTAMD64.CoInstallers");
            Assert.AreEqual(categories[12].Name, "Razer_CoInstaller_AddReg");
            Assert.AreEqual(categories[13].Name, "Razer_CoInstaller_CopyFiles");
            Assert.AreEqual(categories[14].Name, "Razer_Installer_CopyFiles");
            Assert.AreEqual(categories[15].Name, "Razer_Installer_CopyFilesWOW64");
            Assert.AreEqual(categories[16].Name, "Strings");
        }
コード例 #4
0
        public InfData Parse(string data)
        {
            var infData = new InfData();
            var parser  = new ContentParser();

            parser.CategoryDiscovered += (sender, category) => infData.Categories.Add(category);
            parser.Parse(data);
            return(infData);
        }
コード例 #5
0
        public BlogIndex Parse(DirectoryPath path)
        {
            var directory = _fileSystem.GetDirectory(path);

            if (!directory.Exists)
            {
                return(new BlogIndex(Enumerable.Empty <BlogPost>()));
            }

            var posts = new List <BlogPost>();
            var files = directory.GetFiles("*", SearchScope.Current);

            foreach (var file in files)
            {
                var filename = BlogFilename.Parse(file.Path);
                if (filename != null)
                {
                    // Read the file.
                    var content = _parser.Parse(file.Path);
                    if (!content.FrontMatter.ContainsKey("content-type"))
                    {
                        content.FrontMatter.Add("content-type", "markdown");
                    }

                    // Process the content.
                    var body = _processor.PreProcess(content.Body);
                    body = _converter.ConvertToHtml(content, body);
                    body = _processor.PostProcess(body) ?? body;

                    // Get the excerpts.
                    var excerpts = _converter.ConvertToHtml(content, content.Excerpt);

                    // Rewrite the feed body.
                    // This is kind of a hack, but we need to make sure that all links are absolute.
                    var feedBody = RewriteRelativeLinks(body);

                    var author = content.GetFrontMatter("author");

                    // Add the blog post.
                    posts.Add(new BlogPost(filename.Slug,
                                           content.GetFrontMatter("title"), body, feedBody, excerpts, filename.PostedAt,
                                           GetCategories(content), author == null ? "Cake Team" : author));
                }
            }

            // Hack. Don't judge me... :)
            var maxDate  = posts.Max(x => x.PostedAt);
            var lastPost = posts.FirstOrDefault(x => x.PostedAt == maxDate);

            if (lastPost != null)
            {
                lastPost.IsLatest = true;
            }

            return(new BlogIndex(posts));
        }
コード例 #6
0
        public void CategoryParsing()
        {
            string test       = "[CATEGORY]";
            var    categories = new List <Category>();
            var    parser     = new ContentParser();

            parser.CategoryDiscovered += (sender, category) => categories.Add(category);

            parser.Parse(test);

            Assert.IsTrue(categories.Count == 1 && categories.First().Name == "CATEGORY");
        }
コード例 #7
0
        private void loadDataButton_Click(object sender, EventArgs e)
        {
            dataGridView.Enabled = true;

            if (dataGridView.Rows.Count > 1)
            {
                dataGridView.DataSource = null;
                dataGridView.Refresh();
            }

            FileReader reader = new FileReader();

            string [] results = reader.GetContent();

            if (results.Length > 1)
            {
                MessageBox.Show("Załadowano dane");
            }
            else
            {
                MessageBox.Show("Nie zaladowano danych. Spróbuj ponownie");
                dataGridView.DataSource = null;
                dataGridView.Refresh();
            }
            ContentParser contentParser = new ContentParser(results);

            content = contentParser.Parse();

            foreach (Measurement measurement in content)
            {
                table.Rows.Add(measurement.GetNumber(), measurement.GetValue());
            }
            dataGridView.DataSource = table;

            AVG      = calculations.AVG(content);
            Variance = calculations.Variance(content);
            Period   = ((1.0f / content.Count) * 10);

            avgBox.Text      = AVG.ToString();
            varianceBox.Text = Variance.ToString();
            periodBox.Text   = $"{Period.ToString()}";

            if (content.Count > 1)
            {
                graphButton.Enabled = true;
                saveButton.Enabled  = true;
            }
        }
コード例 #8
0
ファイル: TopicReader.cs プロジェクト: reicheltp/website
        private Topic ReadTopic(XmlReader reader, DirectoryPath root)
        {
            var file = reader.GetAttribute("file");

            if (string.IsNullOrWhiteSpace(file))
            {
                return(null);
            }

            var id     = reader.GetAttribute("id");
            var title  = reader.GetAttribute("title");
            var body   = string.Empty;
            var hidden = string.Equals("true", reader.GetAttribute("hidden"), StringComparison.OrdinalIgnoreCase);

            if (string.IsNullOrWhiteSpace(id))
            {
                if (!string.IsNullOrWhiteSpace(file))
                {
                    id = Path.GetFileNameWithoutExtension(file);
                }
                else if (!string.IsNullOrWhiteSpace(title))
                {
                    id = title.ToSlug();
                }
                else
                {
                    throw new InvalidOperationException("Could not generate ID from topic.");
                }
            }

            var path = root.CombineWithFilePath(file);

            if (_fileSystem.Exist(path))
            {
                // Read the file and separate front matter from content.
                var content = _contentParser.Parse(path);
                if (content != null)
                {
                    body = _contentProcessor.PreProcess(content.Body);
                    body = _contentConverter.ConvertToHtml(content, body);
                }

                // Process the content.
                body = _contentProcessor.PostProcess(body) ?? body;
            }

            return(new Topic(id, title, body, hidden, file));
        }
コード例 #9
0
        public T SerializeInto <T>(string data, out InfData outputData) where T : new()
        {
            var o       = new T();
            var t       = o.GetType();
            var infData = new InfData();
            var parser  = new ContentParser();

            var dict = new Dictionary <Key, PropertyInfo>();

            parser.CategoryDiscovered += (sender, category) =>
            {
                infData.Categories.Add(category);
                foreach (var property in t.GetProperties())
                {
                    if (Attribute.IsDefined(property, typeof(InfKeyValue)))
                    {
                        var attribute = (InfKeyValue)Attribute.GetCustomAttribute(property, typeof(InfKeyValue));
                        if (category.IsNamed(attribute.CategoryId))
                        {
                            var key = category[attribute.KeyId];
                            if (key != null)
                            {
                                property.SetValue(o, key.PrimitiveValue);

                                //save dynamic values for further dereferencing
                                if (attribute.DeferenceDynamicValueKeys && key.KeyValues.Any() &&
                                    key.KeyValues.Any(x => x.IsDynamic))
                                {
                                    // save for later des.
                                    dict.Add(key, property);
                                }
                            }
                        }
                    }
                }
            };
            parser.Parse(data);
            outputData = infData;

            //dereference keys - if some left after category dereferencing
            if (dict.Any())
            {
                DerefereneDynamicKeys(o, infData, dict);
            }

            return(o);
        }
コード例 #10
0
        public void SimpleCategoryWithSimpleKey()
        {
            string formula = "[Category] \n Key = Value";
            var    parser  = new ContentParser();

            var categories = new List <Category>();

            parser.CategoryDiscovered += (sender, category) => categories.Add(category);
            parser.Parse(formula);

            Assert.IsTrue(categories.First().Name == "Category");
            var key = categories.First().Keys.First();

            Assert.IsTrue(string.Equals(key.Id, "Key", StringComparison.Ordinal));
            Assert.IsTrue(key.KeyValues.Count == 1);
            Assert.IsTrue(string.Equals(key.KeyValues[0].Value, "Value", StringComparison.Ordinal));
        }
コード例 #11
0
        public void RealLifeFileTest()
        {
            var sw     = new Stopwatch();
            var files  = Directory.GetFiles(testFolder);
            var parser = new ContentParser();

            foreach (var file in files)
            {
                sw.Reset();
                Trace.WriteLine("Loading file content: " + file);
                var content = File.ReadAllText(file);
                Trace.WriteLine("Parsing file: " + file);
                sw.Start();
                parser.Parse(content);
                sw.Stop();
                Trace.WriteLine($"Completed. Elapsed time: {sw.Elapsed}");
            }
        }
コード例 #12
0
        public void SimpleCategoryWithMultipleMultiValueKeys()
        {
            string formula =
                "[Intel.NTAMD64.6.2]\r\n%IntcAudDeviceDesc% = IntcAudModel, HDAUDIO\\FUNC_01&VEN_8086&DEV_2809&SUBSYS_80860101, HDAUDIO\\FUNC_01&VEN_8086&DEV_2809\r\n%IntcAudDeviceDesc% = IntcAudModel, INTELAUDIO\\FUNC_01&VEN_8086&DEV_2809&SUBSYS_80860101, INTELAUDIO\\FUNC_01&VEN_8086&DEV_2809\r\n%IntcAudDeviceDesc% = IntcAudModel, HDAUDIO\\FUNC_01&VEN_8086&DEV_280A&SUBSYS_80860101, HDAUDIO\\FUNC_01&VEN_8086&DEV_280A";

            var parser = new ContentParser();

            var categories = new List <Category>();

            parser.CategoryDiscovered += (sender, category) => categories.Add(category);
            parser.Parse(formula);

            var firstCategory = categories.First();

            Assert.AreEqual(firstCategory.Name, "Intel.NTAMD64.6.2");
            Assert.IsTrue(firstCategory.Keys.Count == 3);

            //first key
            var key = firstCategory.Keys[0];

            Assert.AreEqual(key.Id, "%IntcAudDeviceDesc%");
            Assert.AreEqual(key.KeyValues[0].Value, "IntcAudModel");
            Assert.AreEqual(key.KeyValues[1].Value, "HDAUDIO\\FUNC_01&VEN_8086&DEV_2809&SUBSYS_80860101");
            Assert.AreEqual(key.KeyValues[2].Value, "HDAUDIO\\FUNC_01&VEN_8086&DEV_2809");

            //second key
            key = firstCategory.Keys[1];
            Assert.AreEqual(key.Id, "%IntcAudDeviceDesc%");
            Assert.AreEqual(key.KeyValues[0].Value, "IntcAudModel");
            Assert.AreEqual(key.KeyValues[1].Value, "INTELAUDIO\\FUNC_01&VEN_8086&DEV_2809&SUBSYS_80860101");
            Assert.AreEqual(key.KeyValues[2].Value, "INTELAUDIO\\FUNC_01&VEN_8086&DEV_2809");

            //third key
            key = firstCategory.Keys[2];
            Assert.AreEqual(key.Id, "%IntcAudDeviceDesc%");
            Assert.AreEqual(key.KeyValues[0].Value, "IntcAudModel");
            Assert.AreEqual(key.KeyValues[1].Value, "HDAUDIO\\FUNC_01&VEN_8086&DEV_280A&SUBSYS_80860101");
            Assert.AreEqual(key.KeyValues[2].Value, "HDAUDIO\\FUNC_01&VEN_8086&DEV_280A");
        }
コード例 #13
0
        public void SimpleCategoryWithMultipleSimpleKeysReal()
        {
            string formula =
                "[Install_MPCIEX_GENM2_D_REV_59_7265_BGN_2x2_HMC_WINT_64_BGN15.Services]\r\nInclude         = netvwifibus.inf\r\nNeeds           = VWiFiBus.Services";

            var parser = new ContentParser();

            var categories = new List <Category>();

            parser.CategoryDiscovered += (sender, category) => categories.Add(category);
            parser.Parse(formula);

            var firstCategory = categories.First();

            Assert.IsTrue(firstCategory.Name == "Install_MPCIEX_GENM2_D_REV_59_7265_BGN_2x2_HMC_WINT_64_BGN15.Services");

            Assert.AreEqual(firstCategory.Keys[0].Id, "Include");
            Assert.AreEqual(firstCategory.Keys[1].Id, "Needs");

            Assert.AreEqual(firstCategory.Keys[0].KeyValues.First().Value, "netvwifibus.inf");
            Assert.AreEqual(firstCategory.Keys[1].KeyValues.First().Value, "VWiFiBus.Services");
        }
コード例 #14
0
        public void SimpleCategoryWithOneMultiValueKey()
        {
            string formula =
                "[Install_MPCIEX_GENM2_D_REV_61_7265_BGN_2x2_HMC_WINT_64_BGN15.Services] \r\n AddService     = Netwtw04, 2, NIC_Service_WINT_64, Common_EventLog_WINT_64";

            var parser = new ContentParser();

            var categories = new List <Category>();

            parser.CategoryDiscovered += (sender, category) => categories.Add(category);
            parser.Parse(formula);

            var firstCategory = categories.First();

            Assert.AreEqual(firstCategory.Name, "Install_MPCIEX_GENM2_D_REV_61_7265_BGN_2x2_HMC_WINT_64_BGN15.Services");
            Assert.AreEqual(firstCategory.Keys[0].Id, "AddService");
            var values = firstCategory.Keys.First().KeyValues;

            Assert.AreEqual(values[0].Value, "Netwtw04");
            Assert.AreEqual(values[1].Value, "2");
            Assert.AreEqual(values[2].Value, "NIC_Service_WINT_64");
            Assert.AreEqual(values[3].Value, "Common_EventLog_WINT_64");
        }