Ejemplo n.º 1
0
        static async Task Main(string[] args)
        {
            do
            {
                IWeatherChannel  weatherChannel = new WeatherChannel();
                var              subscriber1    = new WeatherSubscriber("Subscriber 1", weatherChannel);
                var              subscriber2    = new WeatherSubscriber("Subscriber 2", weatherChannel);
                WeatherPublisher publisher      = new WeatherPublisher(weatherChannel);

                await publisher.PublishDataAsync();

                subscriber1.UnSubscribe();

                var subscriber3 = new WeatherSubscriber("Subscriber 3", weatherChannel);

                await publisher.PublishDataAsync();

                subscriber2.UnSubscribe();
                subscriber3.UnSubscribe();

                Console.WriteLine("Do you want to continue (Y/N)? ");
            } while (Console.ReadLine().ToUpper() == "Y");
        }
Ejemplo n.º 2
0
        private void AddLocation()
        {
            string city = "";

            if (!GetKeyboard(ref city) || String.IsNullOrEmpty(city))
            {
                return;
            }
            try
            {
                // Perform actual search
                WeatherChannel weather = new WeatherChannel();
                ArrayList      cities  = weather.SearchCity(city);

                if (cities.Count <= 0)
                {
                    GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK);
                    dlg.SetHeading(8);
                    dlg.SetLine(1, 412);
                    dlg.SetLine(2, "");
                    dlg.DoModal(GetID);
                    return;
                }

                GUIDialogMenu dialogCitySelect = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
                if (dialogCitySelect != null)
                {
                    dialogCitySelect.Reset();
                    dialogCitySelect.ShowQuickNumbers = false;
                    dialogCitySelect.SetHeading(396); // Select Location
                    foreach (WeatherChannel.City _city in cities)
                    {
                        dialogCitySelect.Add(_city.Name + " (" + _city.Id + ")");
                    }

                    dialogCitySelect.DoModal(GetID);
                    if (dialogCitySelect.SelectedLabel >= 0)
                    {
                        WeatherChannel.City newcity = (WeatherChannel.City)cities[dialogCitySelect.SelectedLabel];
                        LocationInfo        loc     = new LocationInfo();
                        loc.City           = newcity.Name;
                        loc.CityCode       = newcity.Id;
                        loc.UrlSattelite   = "";
                        loc.UrlTemperature = "";
                        loc.UrlUvIndex     = "";
                        loc.UrlWinds       = "";
                        loc.UrlHumidity    = "";
                        loc.UrlPrecip      = "";
                        availableLocations.Add(loc);

                        SaveLocations();
                        SetDefaultLocation();  // Reset the default location as necessary
                        InitDefaultLocation(); // Refresh default location button as necessary
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("MyWeather settings error: {0}", ex.ToString());
            }
        }