public async Task SendWeatherInformation(CancellationToken cancellationToken = default) { var weatherService = _serviceProxyFactory.GetWeatherService(); var users = await GetUserLocationsAsync(); if (users == null || !users.Any()) { _logger.Log("No user configurations found, exiting"); return; } var weatherInfoCache = new Dictionary <string, WeatherInformation>(); foreach (var user in users) { var cacheKey = user.City + user.State; if (!weatherInfoCache.TryGetValue(cacheKey, out WeatherInformation weatherInfo)) { weatherInfo = await weatherService.GetWeatherInformationAsync(user.City, user.State, cancellationToken); weatherInfoCache.TryAdd(cacheKey, weatherInfo); } var subject = $"Weather Update - {user.City} {user.State}"; var body = BuildEmailBody(weatherInfo, user); var emailService = _serviceProxyFactory.GetEmailService(); await emailService.SendEmailAsync(user.Emails, subject, body.ToString()); } }
internal virtual async Task SendIPAddressViaEmail(IPAddress ipAddress, ILogger logger, CancellationToken cancellationToken = default) { const string subject = "Current IP Address"; var to = _appSettings.RecipientEmails.ToList(); var body = $"Your current IP Address is {ipAddress}"; var emailService = _serviceProxyFactory.GetEmailService(logger); await emailService.SendEmailAsync(to, subject, body, cancellationToken); }