Esempio n. 1
0
 private static void ForceRegexCompilation(Category root)
 {
     foreach (Category c in root.Categories)
     {
         c.Pattern.IsMatch("");
         ForceRegexCompilation(c);
     }
 }
Esempio n. 2
0
        private static Category GenerateCategories(int levels, int count, Category parent)
        {
            if (levels == 0)
                return parent;

            for (int i = 0; i < count; i++)
            {
                string name = PasswordGenerator.Generate(5, PasswordCharacters.AllLetters);
                string pattern = PasswordGenerator.Generate(2, PasswordCharacters.AllLetters);
                Category child = new Category(name, pattern);
                parent.Categories.Add(child);
                GenerateCategories(levels - 1, count, child);
            }

            return parent;
        }
Esempio n. 3
0
        private static void Categorize(Category root)
        {
            // Match items for this level
            foreach (Category c in root.Categories)
            {
                foreach (string i in root.Items)
                {
                    if (c.Match(i))
                    {
                        matches++;
                        c.Items.Add(i);
                    }
                }
            }

            // Recurse through child categories
            foreach (Category c in root.Categories)
                Categorize(c);
        }
Esempio n. 4
0
 private static Category GenerateCategories(int levels, int count)
 {
     Category root = new Category("Root", "");
     return GenerateCategories(levels, count, root);
 }
Esempio n. 5
0
        private static void ParallelCategorize(Category root)
        {
            // Match items for this level
            Parallel.ForEach(root.Categories,
                (c) =>
                {
                    foreach (string i in root.Items)
                    {
                        if (c.Match(i))
                        {
                            Interlocked.Add(ref matches, 1);
                            c.Items.Add(i);
                        }
                    }
                });

            // Recurse through child categories
            Parallel.ForEach(root.Categories, (c) => ParallelCategorize(c));
        }