Ejemplo n.º 1
0
        /// <summary>
        /// Program entry point.
        /// </summary>
        /// <param name="args">CLI args</param>
        /// <returns>status code</returns>
        static int Main(string[] args)
        {
            var parser = new CliParser((configuration) =>
            {
                configuration.CaseSensitive = false;
                configuration.HelpWriter    = Console.Error;
            });

            var cmdOpts = default(CliArgs);

            parser.ParseArguments <CliArgs>(args).WithParsed(opts => cmdOpts = opts);

            if (cmdOpts == null)
            {
                return(-1);
            }

            // after this, RandomSoup should be a rougly 1200 character string
            // which is more than enough for email address generation.
            RandomSoup = Enumerable.Range(0, 100)
                         .Select(x => Path.GetRandomFileName().Replace(".", ""))
                         .Aggregate((x, y) => x + y);

            var pubCount = 0;

            if (cmdOpts.ExcludePublicDomains && cmdOpts.ExcludeGeneratedDomains)
            {
                Console.WriteLine("ERROR: Flags force exclusion " +
                                  "of all types of address. None were generated.");
                return(0);
            }

            if (cmdOpts.ExcludeGeneratedDomains)
            {
                pubCount = cmdOpts.Count;
            }
            else
            {
                // create a randomized breakdown.
                pubCount = Convert.ToInt32(Math.Round(
                                               cmdOpts.Count * ((double)(new Random().Next(3, 7) * 10) / 100)));
            }

            // get a listing of 200 randomly generated domains.
            var domains = Enumerable.Range(0, 200).Select(v => GenerateRandomDomainName()).ToList();

            var emailListing = new SortedSet <string>();

            // keep generating randomized emails until we have the
            // desired number of public domain emails.
            // NOTE: This is done in a loop to ensure we get the desired
            // count even in the case where some duplicated are generated.
            while (emailListing.Count < pubCount)
            {
                var email = string.Format("{0}@{1}",
                                          GenerateRandomStringPart(new Random().Next(1, cmdOpts.MaxEmailPartLength)),
                                          KnownPublicMailProviders[new Random().Next(0, KnownPublicMailProviders.Length - 1)]);
                emailListing.Add(email);
            }

            // now just keep populating generated email addresses
            // until we've reached the desired count.
            while (emailListing.Count < cmdOpts.Count)
            {
                var email = string.Format("{0}@{1}",
                                          GenerateRandomStringPart(new Random().Next(1, cmdOpts.MaxDomainPartLength)),
                                          domains[new Random().Next(0, domains.Count - 1)]);
                emailListing.Add(email);
            }

            // push results to desired output destination (console or file)
            DumpResults(cmdOpts, emailListing);

            return(0);
        }