예제 #1
0
        public void NotifySubscribers()
        {
            var provider = new SubscriptionProvider(_subscriptionRepositoryFactory());

            provider.DeleteExpiredSubscriptions();

            List <SubscriptionInfo> subscriptions = provider.GetConfirmed();

            DateRange dateRange = new DateRange {
                From = DateTime.Now, To = DateTime.Now.AddDays(3)
            };

            var weatherProvider = new WeatherProvider(_sources);

            foreach (SubscriptionInfo subscription in subscriptions)
            {
                List <DateTime> rainDates = new List <DateTime>();
                Location        coords    = new Location {
                    Latitude = subscription.Latitude, Longitude = subscription.Longitude
                };
                List <Weather> weatherForecast = weatherProvider.GetWeather(dateRange, coords);
                foreach (Weather weather in weatherForecast)
                {
                    if (weather.Precipitation == Precipitation.Rain)
                    {
                        rainDates.Add(weather.Date);
                    }
                }
                if (rainDates.Count > 0)
                {
                    var emailMessage = EmailComposer.GetNotificationMail(subscription, rainDates);
                    EmailSender.SendEmail(emailMessage);
                    provider.UpdateNotifyDate(subscription);
                }
            }
        }