public async Task <HostInfoAnalyzeResult> AnalyzeHostsAsync() { HostInfoAnalyzeResult result = new HostInfoAnalyzeResult(); try { var hostInfos = await reader.ReadAsync(); result.HostsCount = hostInfos.Count; Task <HostInfo[]> aggregateTask = null; try { var tasks = hostInfos.Select(hi => resolver.ResolveIpAsync(hi)).ToArray(); aggregateTask = Task.WhenAll(tasks); await aggregateTask; result.SuccessAnalyzedHostCount = tasks.Length; } catch (Exception) { result.SuccessAnalyzedHostCount = result.HostsCount - aggregateTask.Exception.InnerExceptions.Count; loggerFacade.Log(LogLevel.Error, "Resolving ip address problem.", aggregateTask.Exception); } await writer.WriteAsync(hostInfos); result.HostInfoSuccessSaved = true; } catch (Exception e) { loggerFacade.Log(LogLevel.Error, "Can't analyze hosts", e); } return(result); }
public async Task <HostInfo> ResolveIpAsync(HostInfo hostInfo) { try { return(await resolver.ResolveIpAsync(hostInfo)); } catch (Exception e) { logger.Log( LogLevel.Error, $"Can't resolve ip address from host {hostInfo.Url}", e); throw; } }