Esempio n. 1
0
        private static void ParseDaylyForecast(XDocument xDoc, WeatherInfoViewModel weatherInfo)
        {
            var forecast = xDoc.Root.Element("forecast").Elements();

            foreach (var node in forecast)
            {
                var      weatherDetails = new WeatherDetailsInfoViewModel();
                DateTime cleanDate;

                string dateString = node.Attribute("from").Value;
                DateTime.TryParseExact(dateString, "yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out cleanDate);

                weatherDetails.Time             = cleanDate.ToLocalTime();
                weatherDetails.WeatherState     = node.Element("symbol").Attribute("name").Value.ToUpper();
                weatherDetails.WeatherStateCode = int.Parse(node.Element("symbol").Attribute("number").Value);

                weatherDetails.WindDirection = node.Element("windDirection").Attribute("code").Value;
                weatherDetails.WindSpeed     = double.Parse(node.Element("windSpeed").Attribute("mps").Value);

                var temperatureNode = node.Element("temperature");

                weatherDetails.CurrentTemperature = double.Parse(temperatureNode.Attribute("value").Value);
                weatherDetails.MinimalTemperature = double.Parse(temperatureNode.Attribute("min").Value);
                weatherDetails.MaximalTemperature = double.Parse(temperatureNode.Attribute("max").Value);
                weatherDetails.Pressure           = double.Parse(node.Element("pressure").Attribute("value").Value);
                weatherDetails.Humidity           = double.Parse(node.Element("humidity").Attribute("value").Value);

                weatherInfo.ShortTermWeatherDetails.Add(weatherDetails);
            }
        }
Esempio n. 2
0
        public ActionResult Index()
        {
            //ExecutionEngine engine = new ExecutionEngine();
            //engine.Validate();

            WeatherInfoViewModel viewModel = new WeatherInfoViewModel();

            return(View("Index", viewModel));
        }
Esempio n. 3
0
        public void GetWorldTemperaturesWithMapper(WeatherInfoViewModel viewModel)
        {
            Weather_Request request = new Weather_Request()
            {
                City = viewModel.CityFilter
            };

            CallService <WeatherInfoViewModel, Weather_Request, Weather_Response, WeatherServiceClient>(viewModel, (c, req) => c.WeatherInfo(req));
        }
Esempio n. 4
0
        public ActionResult SearchLocations(WeatherInfoViewModel viewModel)
        {
            var serviceLayerInteractions = new Infrastructure.ServiceLayerInteractions();

            viewModel = serviceLayerInteractions.GetWorldTemperatures(viewModel);

            serviceLayerInteractions.GetWorldTemperaturesWithMapper(viewModel);

            return(View("Index", viewModel));
        }
Esempio n. 5
0
        private static void ParseBasicData(XDocument xDocDailyForecast, WeatherInfoViewModel weatherInfo)
        {
            weatherInfo.CityName    = xDocDailyForecast.Root.Element("location").Element("name").Value;
            weatherInfo.CountryName = xDocDailyForecast.Root.Element("location").Element("country").Value;

            DateTime cleanDate;
            string   dateString = xDocDailyForecast.Root.Element("sun").Attribute("rise").Value;

            DateTime.TryParseExact(dateString, "yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out cleanDate);

            weatherInfo.Sunrise = cleanDate.ToLocalTime();

            dateString = xDocDailyForecast.Root.Element("sun").Attribute("set").Value;
            DateTime.TryParseExact(dateString, "yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out cleanDate);

            weatherInfo.Sunset = cleanDate.ToLocalTime();
        }
Esempio n. 6
0
        public WeatherInfoViewModel GetWorldTemperatures(WeatherInfoViewModel viewModel)
        {
            var weatherInfoViewModel = new WeatherInfoViewModel();
            var request = new Weather_Request()
            {
                City = viewModel.CityFilter
            };
            var worldTemperaturesResponse = GetResponseFromServiceCall <Weather_Request, Weather_Response, WeatherServiceClient>(request, (c, req) => c.GetWorldTemperaturesSoap(req));

            var mapper = new WeatherInfoMapper();

            mapper.Map(worldTemperaturesResponse, weatherInfoViewModel);

            //var dummyRequest = new Dummy_Request();
            //var dummyResponse = GetResponseFromServiceCall<Dummy_Request, Dummy_Response, DummyServiceClient>(dummyRequest, (c, req) => c.GetData(dummyRequest));

            return(weatherInfoViewModel);
        }
Esempio n. 7
0
 public ActionResult Index(WeatherInfoViewModel model)
 {
     if (ModelState.IsValid == false)
     {
         return View( new WeatherInfoViewModel
         {
             WeatherCode = model.WeatherCode,
             WeatherInfo = null
         });
     }
     var weatherBug = new WeatherBug.WeatherBug();
     var info = weatherBug.checkWeather(WeatherBug.WeatherTypeEnum.ZipCode, model.WeatherCode.ToString());
     var viewModel = new WeatherInfoViewModel
     {
         WeatherCode = model.WeatherCode,
         WeatherInfo = info
     };
     return View(viewModel);
 }
        public ActionResult Visualize(int?month, int?year, int?page)
        {
            int pageSize   = 10;
            int pageNumber = page.HasValue ? Convert.ToInt32(page) : 1;

            var txOptions = new System.Transactions.TransactionOptions();

            txOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;

            using (var transaction = new TransactionScope(TransactionScopeOption.Required, txOptions))
            {
                using (var context = new WeatherDBEntities())
                {
                    WeatherInfoViewModel model = new WeatherInfoViewModel();
                    model.weatherInfo = context.Weathers.Where(m => false).ToPagedList(pageNumber, pageSize);
                    model.month       = month;
                    model.year        = year;

                    if (year == null && month == null)
                    {
                        model.weatherInfo = context.Weathers.ToList().ToPagedList <Weather>(pageNumber, pageSize);
                    }
                    else if (year == null && month != null)
                    {
                        model.errorMessage = "Specify year";
                    }
                    else if (year != null && month == null)
                    {
                        model.weatherInfo = context.Weathers.Where(m => m.Date.Year == year)
                                            .OrderBy(m => m.Date.Year)
                                            .ToPagedList(pageNumber, pageSize);
                    }
                    else
                    {
                        model.weatherInfo = context.Weathers.Where(m => (m.Date.Year == year && m.Date.Month == month))
                                            .OrderBy(m => m.Date.Year)
                                            .ToPagedList(pageNumber, pageSize);
                    }

                    return(View(model));
                }
            }
        }
Esempio n. 9
0
        public ActionResult Index(WeatherInfoViewModel model)
        {
            if (ModelState.IsValid == false)
            {
                return(View(new WeatherInfoViewModel
                {
                    WeatherCode = model.WeatherCode,
                    WeatherInfo = null
                }));
            }
            var weatherBug = new WeatherBug.WeatherBug();
            var info       = weatherBug.checkWeather(WeatherBug.WeatherTypeEnum.ZipCode, model.WeatherCode.ToString());
            var viewModel  = new WeatherInfoViewModel
            {
                WeatherCode = model.WeatherCode,
                WeatherInfo = info
            };

            return(View(viewModel));
        }
Esempio n. 10
0
        public static async Task <WeatherInfoViewModel> GetWeatherInformation(string locationName, bool forceRefresh = false)
        {
            if ((DateTime.Now - lastUpdate).TotalMinutes < 15 &&
                locationName == WeatherDataServiceConsumer.currentLocationName &&
                currentWeatherInfo != null &&
                !forceRefresh)
            {
                return(currentWeatherInfo);
            }

            var units = App.ApplicationViewModel.MeasurementUnits.ToString().ToLower();

            string dailyForecastString  = string.Format("http://api.openweathermap.org/data/2.5/forecast?q={0}&mode=xml&units={1}", locationName, units);
            string weeklyForecastString = string.Format("http://api.openweathermap.org/data/2.5/forecast/daily?q={0}&mode=xml&units={1}&cnt=7", locationName, units);

#if WINDOWS_PHONE_APP
            if (locationName != "CurrentLocation")
            {
                dailyForecastString  = string.Format("http://api.openweathermap.org/data/2.5/forecast?q={0}&mode=xml&units={1}", locationName, units);
                weeklyForecastString = string.Format("http://api.openweathermap.org/data/2.5/forecast/daily?q={0}&mode=xml&units={1}&cnt=7", locationName, units);
            }
            else
            {
                Geolocator geolocator = new Geolocator();
                geolocator.DesiredAccuracyInMeters = 50;

                Geoposition geoposition = await geolocator.GetGeopositionAsync();

                dailyForecastString = string.Format("http://api.openweathermap.org/data/2.5/forecast?lat={0}&lon={1}&mode=xml&units={2}",
                                                    geoposition.Coordinate.Latitude, geoposition.Coordinate.Longitude, units);
                weeklyForecastString = string.Format("http://api.openweathermap.org/data/2.5/forecast/daily?lat={0}&lon={1}&mode=xml&units={2}&cnt=7",
                                                     geoposition.Coordinate.Latitude, geoposition.Coordinate.Longitude, units);
            }
#endif

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(dailyForecastString);

            var response = await request.GetResponseAsync().ConfigureAwait(false);

            var stream = response.GetResponseStream();

            var    streamReader = new StreamReader(stream);
            string responseText = streamReader.ReadToEnd();

            XDocument xDocDailyForecast = null;
            try
            {
                xDocDailyForecast = XDocument.Parse(responseText);
            }
            catch
            {
                return(null);
            }

            var weatherInfo = new WeatherInfoViewModel();

            ParseBasicData(xDocDailyForecast, weatherInfo);

            ParseDaylyForecast(xDocDailyForecast, weatherInfo);

            HttpWebRequest weeklyRequest = (HttpWebRequest)WebRequest.Create(weeklyForecastString);

            response = await weeklyRequest.GetResponseAsync().ConfigureAwait(false);

            stream = response.GetResponseStream();

            streamReader = new StreamReader(stream);
            responseText = streamReader.ReadToEnd();

            XDocument xDocWeeklyForecast = null;

            try
            {
                xDocWeeklyForecast = XDocument.Parse(responseText);
            }
            catch
            {
                return(null);
            }

            ParseWeeklyForecast(xDocWeeklyForecast, weatherInfo);

            lastUpdate          = DateTime.Now;
            currentLocationName = locationName;
            currentWeatherInfo  = weatherInfo;

            return(weatherInfo);
        }
Esempio n. 11
0
        public void CityWeatherViewModelAdditionTest()
        {
            try
            {
                // Arrange
                const string CAPE_TOWN    = "Cape Town";
                const string STELLENBOSCH = "Stellenbosch";

                var restService             = Substitute.For <IRestService>();
                var queryService            = Substitute.For <IQueryService>();
                var navigationService       = Substitute.For <INavigationService>();
                var settingsService         = Substitute.For <ISettingsService>();
                var locationService         = Substitute.For <ILocationService>();
                var popupnNavigationService = Substitute.For <IPopupNavigation>();


                settingsService.UserCities.Returns(new List <string>
                {
                    CAPE_TOWN, STELLENBOSCH
                });
                queryService.GenerateQuery(CAPE_TOWN).Returns(CAPE_TOWN);
                queryService.GenerateQuery(STELLENBOSCH).Returns(STELLENBOSCH);
                restService.GetWeatherData(CAPE_TOWN).Returns(result => Task.FromResult(
                                                                  Populate(CAPE_TOWN, 20)));

                restService.GetWeatherData(STELLENBOSCH).Returns(result => Task.FromResult(
                                                                     Populate(STELLENBOSCH, 30)));

                var viewModel = new WeatherInfoViewModel(navigationService, restService, queryService, settingsService, locationService, popupnNavigationService);
                viewModel.GetWeatherCommand.Execute(null);
                // Assert
                Assert.That(viewModel.CityWeatherViewModels.Count() == 3);
                var dummyModel        = viewModel.CityWeatherViewModels.FirstOrDefault(vm => vm.Location == "Dummy");
                var capeTownModel     = viewModel.CityWeatherViewModels.FirstOrDefault(vm => vm.Location == CAPE_TOWN);
                var stellenboschModel =
                    viewModel.CityWeatherViewModels.FirstOrDefault(vm => vm.Location == STELLENBOSCH);

                if (capeTownModel != null)
                {
                    Assert.That(capeTownModel != null);
                    Assert.That(capeTownModel.Location == CAPE_TOWN);
                    Assert.That(capeTownModel.Temperature == 20);
                    Assert.That(capeTownModel.Humidity == 21);
                    Assert.That(capeTownModel.Sunrise == 22);
                    Assert.That(capeTownModel.Sunset == 23);
                    Assert.That(capeTownModel.WindSpeed == 25);
                }
                else
                {
                    Assert.Fail();
                }

                if (stellenboschModel != null)
                {
                    Assert.That(stellenboschModel != null);
                    Assert.That(stellenboschModel.Location == STELLENBOSCH);
                    Assert.That(stellenboschModel.Temperature == 30);
                    Assert.That(stellenboschModel.Humidity == 31);
                    Assert.That(stellenboschModel.Sunrise == 32);
                    Assert.That(stellenboschModel.Sunset == 33);
                    Assert.That(stellenboschModel.WindSpeed == 35);
                }
                else
                {
                    Assert.Fail();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }