예제 #1
0
        private async void buttonLookupWeather_Click(object sender, EventArgs e)
        {
            textBoxResults.Clear();
            string strWeather = await WeatherProcessor.LoadWeather(textBoxZipCode.Text);

            textBoxResults.Text = strWeather;
        }
예제 #2
0
 //Work with cities informations functions
 #region Get WeatherInformation for City
 private async void GetWeatherInformationsForCity(CityModel inCity)
 {
     if (inCity != null && inCity.coord != null)
     {
         inCity.CityWeather = await WeatherProcessor.LoadWeather(inCity.coord.Lat.ToString(), inCity.coord.Lon.ToString());
     }
 }
예제 #3
0
 public void Test_construction_with_mixed_null_parameters_throws_null_exception(IReader reader, IMapper mapper, IWriter writer, IMessageHub hub, ILogger logger)
 {
     // Arrange.
     // Act.
     // Assert.
     Assert.Throws <ArgumentNullException>(() => _processor = new WeatherProcessor(reader, mapper, writer, hub, logger));
 }
예제 #4
0
        /// <summary>
        /// Wyodrębnia potrzebne dane z pliku JSON
        /// </summary>
        /// <returns></returns>
        /// Zobacz <see cref="WeatherProcessor.LoadWeatherInfo(string)"/> do połączeniz systemem API

        private async Task LoadInfo()
        {
            if (City.nameOfTheCity == null)
            {
                City.nameOfTheCity = "Wrocław";
            }
            try
            {
                var weather = await WeatherProcessor.LoadWeatherInfo(City.nameOfTheCity);

                double temp    = weather.main.temp;
                int    celsius = (int)(temp - 273.15);
                temperatureText.Text = $"{ celsius } ℃";

                Weather[] array = weather.weather.ToArray();

                descText.Text = array[0].description;

                string img       = $"http://openweathermap.org/img/wn/{ array[0].icon }@2x.png";
                var    uriSource = new Uri(img, UriKind.Absolute);
                weatherImage.Source = new BitmapImage(uriSource);

                City.nameOfTheCity = weather.name;
                cityName.Text      = City.nameOfTheCity;
            }
            catch
            {
                MessageBox.Show("Błędna nazwa miasta");
            }
        }
예제 #5
0
        public async Task SetLocation([Remainder] string location)
        {
            IGuildUser guser = Context.Message.Author as IGuildUser;
            EntityUser user  = new EntityUser(guser);

            if (_userRepo.GetUserById(user.Id) != null)
            {
                user = _userRepo.GetUserById(user.Id);
            }

            //check if location exists
            WeatherModel wm = await WeatherProcessor.GetWeatherDataName(location);

            if (wm == null)
            {
                throw new NoLocationFoundException();
            }

            if (_repo.UserHasLocation(user))
            {
                _repo.ChangeLocation(user, location);
                _repo.SaveChanges();
                await Context.Channel.SendMessageAsync($"Location updated to {location}");
            }
            else
            {
                _repo.AddLocation(user, location);
                _repo.SaveChanges();
                await Context.Channel.SendMessageAsync($"Location set to {location}");
            }
        }
예제 #6
0
 public WeatherProcessorTests()
 {
     _reader     = Substitute.For <IReader>();
     _mapper     = Substitute.For <IMapper>();
     _writer     = Substitute.For <IWriter>();
     _logger     = Substitute.For <ILogger>();
     _messageHub = Substitute.For <IMessageHub>();
     _processor  = new WeatherProcessor(_reader, _mapper, _writer, _messageHub, _logger);
 }
예제 #7
0
        private async Task LoadWeather()
        {
            // Load weather using the OpenWeatherMap API
            WeatherModel weather = await WeatherProcessor.LoadWeather();

            ViewData["temperature"] = weather.Temp;
            ViewData["icon"]        = $"http://openweathermap.org/img/w/{ weather.Icon }.png";
            ViewData["description"] = weather.Description;
            ViewData["city"]        = weather.City;
            ViewData["country"]     = weather.Country;
        }
예제 #8
0
        /// <summary>
        /// A simple function that takes a zip code and returns a description of the weather
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task <object> FunctionHandler(dynamic input, ILambdaContext context)
        {
            Console.WriteLine("-------- Function Handler ----------");
            //.WriteLine(input);

            // Check if we need to initialize our HTTPRequest
            if (HttpRequest.APIClient == null)
            {
                // Retrieved the Open Weather APP ID from the environment
                string strAppID = Environment.GetEnvironmentVariable("OpenWeatherAppID");

                // Now use it to initialize the HTTPRequest
                WeatherProcessor.InitializeWeatherProcessor(strAppID);
            }

            // Parameter data passed with Invoke AWS Lambda Function request.
            string strZipCode = input?["Details"]?["Parameters"]?.ZipCode;

            if (string.IsNullOrEmpty(strZipCode) || strZipCode.Length != 5)
            {
                Console.WriteLine("Zip code was not set or wasn't five digits");
                return(new
                {
                    message = "ZipCode parameter was not set"
                });
            }

            Console.WriteLine($"Zip Code: {strZipCode}");

            // Lookup the weather for the zip code
            try
            {
                string strWeather = await WeatherProcessor.LoadWeather(strZipCode);

                Console.WriteLine(strWeather);

                // Return it
                var result = new
                {
                    message = $"\"{strWeather}\""
                };
                return(result);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Exception: {ex.Message}");
                return(new
                {
                    message = $"The Lambda Function had an exception.  {ex.Message}"
                });
            }
        }
        public IComponent CreateComponent(IMessageHub hub, string fileName)
        {
            var file      = WeatherConfig.GetFileSystem();
            var logger    = WeatherConfig.GetLoggerConfiguration();
            var reader    = new WeatherReader(file, logger);
            var mapper    = new WeatherMapper(logger);
            var notify    = new WeatherNotifier(logger);
            var processor = new WeatherProcessor(reader, mapper, notify, hub, logger);

            _weatherComponent = new Types.WeatherComponent(reader, mapper, notify, processor, fileName);

            return(_weatherComponent);
        }
예제 #10
0
        private async Task LoadW(string Lat, string Lon)
        {
            var weather = await WeatherProcessor.LoadWeather(Lat, Lon);

            List <DailyModel> daily = weather.Daily;
            //Console.WriteLine(weather.Lat);
            int i = daily[0].Dt;
            //Console.WriteLine(i);
            DateTime date = new DateTime(long.Parse(i.ToString()));

            date.ToString("yyyyMMdd");
            //Console.WriteLine(date);
        }
예제 #11
0
        public async Task CreateForecast(string city)
        {
            try
            {
                Console.WriteLine("Please enter the amount of forecasts:");
                var count = Console.ReadLine();
                var data  = await WeatherProcessor.LoadWeatherAsync(city, Int32.Parse(count));

                DisplayForecast(data);
            }
            catch (Exception e)
            {
                ErrorLogService.StoreErrorLog(e.ToString());
            }
        }
예제 #12
0
        public async Task GetWeather(string name)
        {
            if (name == "set")
            {
                await SetLocation();
            }
            else
            {
                WeatherModel wm = await WeatherProcessor.GetWeatherDataName(name);

                if (wm == null)
                {
                    throw new NoLocationFoundException();
                }
                else
                {
                    wm.FixMapping();
                    await WeatherEmbedBuilder.DisplayWeather(wm, Context as SocketCommandContext);
                }
            }
        }
예제 #13
0
 private void Form1_Load(object sender, EventArgs e)
 {
     WeatherProcessor.InitializeWeatherProcessor(Properties.Settings.Default.OpenWeatherAppID);
 }
예제 #14
0
        public async void LoadWeatherData(string id, decimal lon, decimal lat, string city, int searchType, LangChooser lc, UnitChooser uc)
        {
            XmlDocument GotResponse = new XmlDocument();

            if (searchType == 1)
            {
                GotResponse = await WeatherProcessor.LoadWeather(id, lc, uc);
            }
            if (searchType == 2)
            {
                GotResponse = await WeatherProcessor.LoadWeather(lat, lon, lc, uc);
            }
            if (searchType == 3)
            {
                GotResponse = await WeatherProcessor.LoadWeather(city, lc, uc);
            }

            if (GotResponse.LastChild != null)
            {
                foreach (XmlElement element in GotResponse.LastChild)
                {   //LastChild is current the other oe is the format header
                    //on this level we have 11 nodes
                    if (element.Name == "city")
                    {
                        resultWeater.ID   = int.Parse(element.GetAttribute("id"));
                        resultWeater.Name = element.GetAttribute("name");
                        foreach (XmlElement item in element)            // city has 4 childNodes - iterete through
                        {
                            if (item.Name == "coord")
                            {
                                resultWeater.Longitude = decimal.Parse(item.GetAttribute("lon"));
                                resultWeater.Latitude  = decimal.Parse(item.GetAttribute("lat"));
                            }
                            if (item.Name == "country")
                            {
                                resultWeater.CountrySign = item.InnerText;
                            }
                            if (item.Name == "sun")
                            {
                                resultWeater.SunRise = DateTime.Parse(item.GetAttribute("rise"));
                                resultWeater.SunSet  = DateTime.Parse(item.GetAttribute("set"));
                            }
                        }
                    }
                    if (element.Name == "temperature")
                    {
                        resultWeater.Temperature     = decimal.Parse(element.GetAttribute("value"));
                        resultWeater.TemperatureUnit = element.GetAttribute("unit");
                    }
                    if (element.Name == "humidity")
                    {
                        resultWeater.Humidity     = int.Parse(element.GetAttribute("value"));
                        resultWeater.HumidityUnit = element.GetAttribute("unit");
                    }
                    if (element.Name == "pressure")
                    {
                        resultWeater.Pressure     = int.Parse(element.GetAttribute("value"));
                        resultWeater.PressureUnit = element.GetAttribute("unit");
                    }
                    if (element.Name == "wind")
                    {
                        foreach (XmlElement item in element)
                        {
                            if (item.Name == "speed")
                            {
                                resultWeater.WindSpeed     = decimal.Parse(item.GetAttribute("value"));
                                resultWeater.WindSpeedUnit = item.GetAttribute("unit");
                            }
                            if (item.Name == "direction")
                            {
                                resultWeater.WindDirection = item.GetAttribute("name");
                            }
                        }
                    }
                    if (element.Name == "clouds")
                    {
                        resultWeater.CloudName = element.GetAttribute("name");
                    }
                    if (element.Name == "visibility")
                    {
                        resultWeater.Visibility = int.Parse(element.GetAttribute("value"));
                    }
                    if (element.Name == "lastupdate")
                    {
                        resultWeater.LastUpdate = DateTime.Parse(element.GetAttribute("value"));
                    }
                }
            }
            else
            {
                MessageBox.Show("Nem található ilyen adat, a bezárást követően próblája újra", "Hiba", MessageBoxButtons.OK);
                this.Close();
            }
            DisplayWeather();
        }