Example #1
0
 public void SaveWeatherList(List<WeatherForecast> weatherForecastLists, MeteoContext meteoContext)
 {
     foreach (WeatherForecast WeatherForecast in weatherForecastLists)
     {
         SaveWeather(WeatherForecast, meteoContext);
     }
 }
Example #2
0
 public void SaveWeather(WeatherForecast weatherForecast, MeteoContext meteoContext)
 {
     try
     {
         meteoContext.WeatherForecasts.Add(weatherForecast);
         meteoContext.SaveChanges();
     }
     catch (DbEntityValidationException ex)
     {
         throw;
     }
 }
Example #3
0
        public void InitTest()
        {
            xmlServiceMock = new Mock<IXmlService>();
            webClientServiceMock = new Mock<IWebClientService>();
            openWeatherServiceMock = new Mock<IOpenWeatherService>();
            xmlService = new XmlService();
            webClientService = new WebClientService();
            openWeatherService = new OpenWeatherService();

            IDbContext dbContext = new MeteoContext();
            IRepository<Location> locationRepository = new EfRepository<Location>(dbContext);
            IRepository<WeatherForecast> weatherForecastRepository = new EfRepository<WeatherForecast>(dbContext);
            meteoService = new MeteoService(locationRepository, weatherForecastRepository);
        }
Example #4
0
 static void Main(string[] args)
 {
     IDbContext context = new MeteoContext();
     IRepository<Location> locationRepository = new EfRepository<Location>(context);
     IRepository<WeatherForecast> weatherForecastRepository = new EfRepository<WeatherForecast>(context);
     IMeteoService meteoService = new MeteoService(locationRepository, weatherForecastRepository);
     //Weather prognoza = meteoService.GetWeather("Bydgoszcz", "205-07-12");
     //Console.WriteLine(prognoza);
     IXmlService xmlService = new XmlService();
     List<string> cities = meteoService.GetCities("cities.xml", xmlService);
     foreach (var city in cities)
     {
         Console.WriteLine(city);
     }
     Console.ReadLine();
 }
Example #5
0
 private void GetMeteoInfo()
 {
     try
     {
         IXmlService xmlService = new XmlService();
         WebClientService webClientService = new WebClientService();
         OpenWeatherService openWeatherService = new OpenWeatherService();
         IDbContext context = new MeteoContext();
         IRepository<Location> locationRepository = new EfRepository<Location>(context);
         IRepository<WeatherForecast> weatherForecastRepository = new EfRepository<WeatherForecast>(context);
         IMeteoService meteoService = new MeteoService(locationRepository, weatherForecastRepository);
         List<string> cities = meteoService.GetCities(AppDomain.CurrentDomain.BaseDirectory + @"\cities.xml", xmlService);
         List<WeatherForecast> weatherList = meteoService.GetWeatherList(cities, 16, webClientService, xmlService, openWeatherService);
         meteoService.SaveWeatherList(weatherList);
         LogHelper.WriteToLog(logName, string.Format("forecast weather {0} saved", DateTime.Now));
     }
     catch(Exception ex)
     {
         LogHelper.WriteToLog(logName, ex.Message);
         throw;
     }
 }