public async Task AggregateAsync() { TotalRides = 0; _rides.Clear(); foreach (var company in _companies) { _logger.Info($"Getting rides for {company.Name}"); var aggregate = new ScooterRide(); await foreach (var ride in company.EnumerateRidesAsync()) { TotalRides++; aggregate += ride; } _rides[company] = aggregate; } }
public async IAsyncEnumerable <ScooterRide> EnumerateRidesAsync() { var mails = _mailDataSource.EnumerateMailsAsync("*****@*****.**").ConfigureAwait(false); await foreach (var mail in mails) { var result = new ScooterRide(); try { int end; double distance; double minutes; double seconds; (distance, end) = Extract(mail, "Total Distance ("); (minutes, end) = Extract(mail, "Total Time (", "m", end); (seconds, end) = Extract(mail, " ", "s", end); var price = ParseOrDefault(_priceRegex.Match(mail).Groups["Price"].Value); end = 0; result = new ScooterRide { Price = price, Distance = distance * 1000, Time = minutes * 60 + seconds }; } catch (Exception e) { _logger.Warn(e, "Cannot parse Circ mail"); continue; } yield return(result); } }