public ILogger GetAttemptsNumbers() { var topLevelDomain = Domains.Where(IsTopLevel).First(); curlDetails.DomainId = topLevelDomain.AdmtiveDomainId; var lines = fileProcessor.ReadAttemptsFile(curlDetails).ToList(); curlDetails.Attempts = new Dictionary <string, int>(); foreach (var domain in Domains.Except(DomainsWithFiles)) { Index++; var count = lines .Where(line => line.Contains($"'{domain.AdmtiveDomainId}'")) .Select(number => number.GetBefore("x")) .Count(); curlDetails.Attempts.Add(domain.AdmtiveDomainId, count); var message = $"{Index}:\t{count} attempts were done for downloading file for '{domain.AdmtiveDomainId}'.\n"; if (Constants.EVEN.Contains(count)) { logger.Success = message; } if (Constants.ODD.Contains(count)) { logger.Error = message; } var state = GetLoggerState(); logger.AddLog(state); } return(logger); }
public ILogger SetAttemptsFile() { curlDetails.Directory = DirectoryInfo; foreach (var domain in Domains.Except(DomainsWithFiles)) { Index++; curlDetails.DomainId = domain.AdmtiveDomainId; if (domain.IsTopLevel()) { curlDetails.AttemptsFile = Constants.GetAttemptsFilename(curlDetails); fileProcessor.SetAttemptsFile(curlDetails); } else { File.AppendAllText(curlDetails.AttemptsFile, Constants.SetAttemptText(curlDetails), Encoding.UTF8); } logger.Success = $"{Index}:\tAttempt for downloading file for {domain.AdmtiveDomainId} domain was done.\n"; var state = GetLoggerState(); logger.AddLog(state); } return(logger); }