Example #1
0
        /// <summary>
        /// Aquire the metar from the Internet and fills the WeatherInfoControl,
        /// if the downloading is successful and metar can be parsed correctly.
        /// This method is asynchronous. If the downloading finishes after ICAO
        /// text already changed, the weather update will not happen.
        /// </summary>
        public async Task GetMetarAndFillWeather()
        {
            DisableDnBtn();
            var w = wxControl;

            w.picBox.Visible = false;
            w.picBox.Image   = Properties.Resources.RedLight;

            string icao = airportControl.Icao;

            bool metarAcquired = await Task.Run(
                () => MetarDownloader.TryGetMetar(icao, out metar));

            // Because GetMetar method is asynchronous, it is neccessary to
            // check whether the currently entered ICAO code is still the
            // same as before. If the ICAO changed, we do not need to update.
            if (metarAcquired && icao == airportControl.Icao)
            {
                if (!WeatherAutoFiller.Fill(
                        metar,
                        w.windDirTxtBox,
                        w.windSpdTxtBox,
                        w.oatTxtBox,
                        w.tempUnitComboBox,
                        w.pressTxtBox,
                        w.pressUnitComboBox,
                        w.surfCondComboBox))
                {
                    wxControl.ShowError(
                        @"Metar has been downloaded but the weather " +
                        "information cannot be filled automatically.",
                        "");
                }
                else
                {
                    w.picBox.Image = Properties.Resources.GreenLight;
                }

                EnableViewBtn();
            }

            w.picBox.Visible = true;
            EnableDnBtn();
        }
Example #2
0
        // Get metar functions.
        private async Task GetMetarClicked(object sender, EventArgs e)
        {
            DisableDnBtn();
            var w = wxControl;

            w.picBox.Visible = false;
            w.picBox.Image   = Properties.Resources.RedLight;

            string icao = airportControl.Icao;

            bool metarAcquired = await Task.Run(
                () => MetarDownloader.TryGetMetar(icao, out metar));

            if (metarAcquired)
            {
                if (WeatherAutoFiller.Fill(
                        metar,
                        w.windDirTxtBox,
                        w.windSpdTxtBox,
                        w.oatTxtBox,
                        w.tempUnitComboBox,
                        w.pressTxtBox,
                        w.pressUnitComboBox,
                        w.surfCondComboBox) == false)
                {
                    wxControl.ShowError(
                        @"Metar has been downloaded but the weather " +
                        "information cannot be filled automatically.",
                        "");
                }
                else
                {
                    w.picBox.Image = Properties.Resources.GreenLight;
                }

                EnableViewBtn();
            }

            w.picBox.Visible = true;
            EnableDnBtn();
        }