コード例 #1
0
        }     // end of method ProcessCityData

        /// <summary>
        /// Allows this <see cref="Thread"/> to access the widget controls running on another <see cref="Thread"/>.
        /// </summary>
        /// <param name="frmPreferences">The <see cref="Form"/> which it's controls require access from this <see cref="Thread"/>.</param>
        public static void AccessFormControlProperty(PreferencesForm frmPreferences)
        {
            frmPreferences.cboLocation.Focus();
            frmPreferences.cboLocation.Items.AddRange(matchList);

            frmPreferences.btnSearch.Image           = null;
            frmPreferences.btnSearch.Text            = "Search";
            frmPreferences.cboLocation.DropDownStyle = ComboBoxStyle.DropDown;
            frmPreferences.cboLocation.DroppedDown   = true;
        }// end of method AccessFormControlsOnOtherThread
コード例 #2
0
        }// end of method frmPreferences_Activated

        private void frmPreferences_Load(object sender, EventArgs e)
        {
            frmPreference = this;

            flpIconSet.Controls.Clear();    // remove any previous icon set used and reload at runtime

            LoadInstalledIconPacks();

            // Weather tab
            #region Test Data (un-comment lines for testing)
            //WeatherLionMain.authorizedProviders = new string[] {
            //        WeatherLionMain.DARK_SKY, WeatherLionMain.OPEN_WEATHER,
            //        WeatherLionMain.WEATHER_BIT, WeatherLionMain.YAHOO_WEATHER };

            //WeatherLionMain.storedPreferences.StoredPreferences.Provider = WeatherLionMain.DARK_SKY;
            //WeatherLionMain.storedPreferences.StoredPreferences.Location = "Pine Hills, FL";
            //WeatherLionMain.storedPreferences.StoredPreferences.Interval = 1800000;
            //WeatherLionMain.storedPreferences.StoredPreferences.UseMetric = false;
            //WeatherLionMain.storedPreferences.StoredPreferences.UseSystemLocation = false;
            //WeatherLionMain.storedPreferences.StoredPreferences.WidgetBackground = "default";
            //WeatherLionMain.storedPreferences.StoredPreferences.IconSet = "hero";
            //List<string> preferenceUpdated = new List<string>();

            #endregion

            // load the combo box with the default weather providers
            cboWeatherProviders.Items.Clear(); // refresh the list
            cboWeatherProviders.Items.AddRange(WeatherLionMain.authorizedProviders);

            // select current weather provider
            cboWeatherProviders.SelectedItem = WeatherLionMain.storedPreferences.StoredPreferences.Provider;

            // select the current weather provider
            cboLocation.Text = WeatherLionMain.storedPreferences.StoredPreferences.Location;

            // select the current refresh period
            string updateInterval = UtilityMethod.MillisecondsToMinutes(
                WeatherLionMain.storedPreferences.StoredPreferences.Interval).ToString();

            lblInterval.Text = $"{updateInterval} min.";
            cboRefreshInterval.SelectedItem = updateInterval;

            chkUseMetric.Checked = WeatherLionMain.storedPreferences.StoredPreferences.UseMetric;

            chkUseSystemLocation.Checked = WeatherLionMain.storedPreferences.StoredPreferences.UseSystemLocation;

            // load the three background options
            picDefault.ImageLocation = DEFAULT_BACKGROUND_IMAGE;
            picAndroid.ImageLocation = ANDROID_BACKGROUND_IMAGE;
            picRabalac.ImageLocation = RABALAC_BACKGROUND_IMAGE;

            // Icon Set tab
            foreach (Control c in tabIconSet.Controls)
            {
                if (c is FlowLayoutPanel)
                {
                    foreach (Control sc in c.Controls)
                    {
                        if (sc is FlowLayoutPanel)
                        {
                            foreach (Control tc in sc.Controls)
                            {
                                if (tc is RadioButton)
                                {
                                    RadioButton rb = tc as RadioButton;

                                    rb.CheckedChanged += new EventHandler(IconSetChanged);
                                }// end of if block
                                else if (tc is PictureBox)
                                {
                                    PictureBox pb = tc as PictureBox;

                                    pb.Click += new EventHandler(SelectIconSetRadioButton);
                                } // end of if block
                            }     // end of for each loop
                        }         // end of if block
                    }             // end of inner foreach block
                }                 // end of if block
            }                     // end of foreach block

            // Background tab
            // Make the radio buttons on each page mutually exclusive
            foreach (Control c in tabBackground.Controls)
            {
                if (c is FlowLayoutPanel)
                {
                    foreach (Control sc in c.Controls)
                    {
                        if (sc is RadioButton)
                        {
                            RadioButton rb = sc as RadioButton;

                            rb.CheckedChanged += new EventHandler(BackgroundChanged);
                        }// end of if block
                        else if (sc is PictureBox)
                        {
                            PictureBox pb = sc as PictureBox;

                            pb.Click += new EventHandler(SelectBackgroundRadioButton);
                        } // end of if block
                    }     // end of inner foreach block
                }         // end of if block
            }             // end of foreach block

            switch (WeatherLionMain.storedPreferences.StoredPreferences.WidgetBackground)
            {
            case "default":
                radDefault.Checked = true;
                break;

            case "android":
                radAndroid.Checked = true;
                break;

            case "rabalac":
                radRabalac.Checked = true;
                break;

            default:
                break;
            }// end of switch block

            // About tab
            rtbAbout.Rtf = @"{\rtf1\pc \qc \b Weather Lion\b0" +
                           @"\line Author: Paul O. Patterson" +
                           @"\line BushBungalo Productions™  2005 - " + DateTime.Now.Year +
                           @"\line Version: 1.0" +
                           @"\line © All rights reserved" +
                           @"\line\line\ql\par Weather Lion is an ongoing effort to create a desktop weather widget " +
                           @"using the C# programming language as well as other languages as I " +
                           @"continue to grow as a computer programmer.\par0" +
                           @"\line\line\line Praise Ye YAH!!!}";

            // ensure that the changes list is empty (comment out during testing)
            WeatherLionMain.runningWidget.preferenceUpdated.Clear();

            LoadKnownPlaces();
        }// end of method frmPreferences_Load
コード例 #3
0
        }// end of default constructor

        public CityDataService(string url, string service, PreferencesForm activeForm)
        {
            m_url          = url;
            m_service      = service;
            frmPreferences = activeForm;
        }// end of three-argument constructor
コード例 #4
0
        /// <summary>
        /// Load a required assets and prepare for program execution
        /// </summary>
        public static void Launch()
        {
            #region WeatherLion launch sequence

            UtilityMethod.LogMessage(UtilityMethod.LogLevel.INFO, "Initiating startup...", "WeatherLionMain::Launch");

            // build the required storage files
            if (BuildRequiredDatabases() == 1)
            {
                UtilityMethod.LogMessage(UtilityMethod.LogLevel.INFO,
                                         "All required databases constructed successfully.",
                                         "WeatherLionMain::Launch");
            }// end of if block
            else
            {
                UtilityMethod.LogMessage(UtilityMethod.LogLevel.SEVERE,
                                         "All required databases were not constructed successfully.",
                                         "WeatherLionMain::Launch");
            }// end of else block

            // check that the required access keys are available
            LionSecurityManager.Init();

            // Load only the providers who have access keys assigned to them
            List <string> wxOnly = LionSecurityManager.webAccessGranted;

            wxOnly.Sort();  // sort the list

            // GeoNames is not a weather provider so it cannot be select here
            wxOnly.Remove("GeoNames");

            authorizedProviders = wxOnly.ToArray();

            // ensure that program has all the default assets needed for functioning properly
            HealthCheck();

            // load user preferences
            storedPreferences = Preference.GetSavedPreferences();

            string previousWeatherData = $"{DATA_DIRECTORY_PATH}{WEATHER_DATA_XML}";

            connectedToInternet = UtilityMethod.HasInternetConnection();

            // check for an Internet connection or previous weather data stored local
            if (!connectedToInternet && !File.Exists(previousWeatherData))
            {
                UtilityMethod.ShowMessage("The program will not run without a working internet connection or "
                                          + "data that was previously stored locally" +
                                          "\nResolve your Internet connection and relaunch the program.", null);

                Application.Exit(); // terminate the program
            }// end of if block
            else if (connectedToInternet)
            {
                // obtain the current city of the connected Internet service
                currentCity = UtilityMethod.GetSystemLocation();

                if (currentCity != null)
                {
                    if (currentCity.regionCode != null)
                    {
                        systemLocation = $"{currentCity.cityName}, {currentCity.regionCode}";
                    }// end of if block
                    else
                    {
                        systemLocation = $"{currentCity.cityName}, {currentCity.countryName}";
                    } // end of else block
                }     // end of if block

                // if the user requires the current detected city location to be used as default
                if (storedPreferences.StoredPreferences.UseSystemLocation)
                {
                    if (systemLocation != null)
                    {
                        // use the detected city location as the default
                        storedPreferences.StoredPreferences.Location = systemLocation;

                        if (!storedPreferences.StoredPreferences.Location.Equals(systemLocation))
                        {
                            // update the preferences file
                            Preference.SaveProgramConfiguration("prefs", "Location", systemLocation);

                            // save the city to the local WorldCites database
                            UtilityMethod.AddCityToDatabase(
                                currentCity.cityName, currentCity.countryName,
                                currentCity.countryCode, currentCity.regionName,
                                currentCity.regionCode, currentCity.latitude,
                                currentCity.longitude);

                            JSONHelper.ExportToJSON(currentCity);
                            XMLHelper.ExportToXML(currentCity);
                        } // end of if block
                    }     // end of if block
                    else
                    {
                        UtilityMethod.ShowMessage("The program was unable to obtain your system's location."
                                                  + "\nYour location will have to be set manually using the preferences dialog.", null);

                        PreferencesForm pf = new PreferencesForm();
                        pf.Show();
                    } // end of else block
                }     // end of if block
            }         // end of else if block

            Init();

            #endregion
        }// end of method Launch