private HashSet <GmailDotGeneratorEmailModel> Generate() { var generatedEmails = new HashSet <GmailDotGeneratorEmailModel>(); var username = ""; Stopwatch sw = null; if (OnEstimatedCompletionTime != null) { sw = new Stopwatch(); sw.Start(); } var totalCombos = Configuration.MaximumEmails == 0 || Configuration.MaximumEmails > Configuration.TotalCombinations * 2 ? Configuration.TotalCombinations : Configuration.MaximumEmails / 2; var isMaximumEmailsOdd = Configuration.MaximumEmails % 2 == 1; totalCombos += isMaximumEmailsOdd ? 1 : 0; for (var i = 0; i < totalCombos; i++) { var binaryString = Convert.ToString(i, 2).PadLeft(Configuration.UsernameLengthMinusOne, '0'); for (var j = 0; j < Configuration.UsernameLengthMinusOne; j++) { username += Configuration.Username[j]; if (binaryString[j] == '1') { username += "."; } } username += Configuration.Username[Configuration.UsernameLengthMinusOne]; var generatorEmailModel1 = new GmailDotGeneratorEmailModel(username + "@gmail.com"); var generatorEmailModel2 = new GmailDotGeneratorEmailModel(username + "@googlemail.com"); generatedEmails.Add(generatorEmailModel1); generatedEmails.Add(generatorEmailModel2); if (OnEstimatedCompletionTime != null) { if (sw != null) { sw.Stop(); var remaining = Configuration.TotalCombinations * 2 - generatedEmails.Count; var estimatedCompletionTime = sw.ElapsedTicks * remaining; var gmailDotGeneratorEventArgs = new GmailDotGeneratorEventArgs(generatedEmails.Count, remaining, estimatedCompletionTime, generatorEmailModel1, generatorEmailModel2); EstimatedCompletionTimeChanged(gmailDotGeneratorEventArgs); } } username = ""; //sb.Clear(); } return(generatedEmails); }
private void EstimatedCompletionTimeChanged(GmailDotGeneratorEventArgs gmailDotGeneratorEventArgs) { OnEstimatedCompletionTime?.Invoke(this, gmailDotGeneratorEventArgs); }