Example #1
0
        private static void RunIt(string config, Generator gen, IStorage storage, IValidator validator, IList <string> allowed)
        {
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("===========================");
            Console.WriteLine(" " + config);
            Console.WriteLine("===========================");

            GenerateResult res = gen.Generate(allowed, validator, storage);

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Generated: {0:#,##0}", res.EntriesGenerated);
            Console.WriteLine("Valid: {0:#,##0}", res.ValidEntries);
            Console.WriteLine("In: {0}", res.TimeUsed);

            totalEntriesGenerated += res.EntriesGenerated;
            totalValidEntries     += res.ValidEntries;
            totalTimeUsed          = totalTimeUsed.Add(res.TimeUsed);
        }
Example #2
0
        public GenerateResult Generate(IList <string> allowedCharacters, IValidator validator, IStorage storage)
        {
            var result     = new GenerateResult();
            var permutator = new Permutator();
            var max        = this.GetNumberOfPermutations(allowedCharacters);


            Stopwatch sw = new Stopwatch();

            sw.Start();
            Console.WriteLine();
            foreach (string name in permutator.GetPermutations(allowedCharacters))
            {
                result.EntriesGenerated++;

                if (result.EntriesGenerated % 100 == 0)
                {
                    Console.Write(".");
                }
                if (result.EntriesGenerated % 10000 == 0)
                {
                    Console.WriteLine("[{0:#,##0}/{1:#,##0} (valid:{2:#,##0})]", result.EntriesGenerated, max, result.ValidEntries);
                }


                if (validator.IsValid(name))
                {
                    result.ValidEntries++;
                    storage.Save(name);
                }
            }
            sw.Stop();

            result.TimeUsed = sw.Elapsed;

            return(result);
        }