예제 #1
0
파일: Program.cs 프로젝트: dougallison/hfdp
        static void Main(string[] args)
        {
            var weatherStation          = new WeatherStation();
            var currentConditionDisplay = new CurrentConditionsDisplay();

            currentConditionDisplay.Subscribe(weatherStation);

            var forecastDisplay = new ForecastDisplay();

            forecastDisplay.Subscribe(weatherStation);

            var statisticsDisplay = new StatisticsDisplay();

            statisticsDisplay.Subscribe(weatherStation);

            var heatIndexDisplay = new HeatIndexDisplay();

            heatIndexDisplay.Subscribe(weatherStation);

            weatherStation.TrackWeather(new WeatherData(80, 65, 30.4f));
            weatherStation.TrackWeather(new WeatherData(82, 70, 29.2f));
            weatherStation.TrackWeather(new WeatherData(78, 90, 29.2f));

            Console.WriteLine();
            weatherStation.EndTransmission();
        }
예제 #2
0
 private static void RegisterObservers(WeatherData wd)
 {
     _ = new ConditionDisplay(wd);
     _ = new StatisticsDisplay(wd);
     _ = new ForecastDisplay(wd);
     // HeatIndexDisplay heatIndexDisplay = new HeatIndexDisplay(wd);
 }
        static void Main(string[] args)
        {
            WeatherData weatherData = new WeatherData();
            CurrentConditionsDisplay currentConditionsDisplay = new CurrentConditionsDisplay(weatherData);
            StatisticsDisplay        statisticsDisplay        = new StatisticsDisplay(weatherData);
            ForecastDisplay          forecastDisplay          = new ForecastDisplay(weatherData);
            HeatIndexDisplay         heatIndexDisplay         = new HeatIndexDisplay(weatherData);

            weatherData.SetMeasurements(80, 65, 30.4f);
            weatherData.SetMeasurements(82, 70, 29.2f);
            weatherData.SetMeasurements(78, 90, 29.2f);
        }
예제 #4
0
        public void Run()
        {
            WeatherData wd = new WeatherData();

            CurrentConditionsDisplay currentConditionsDisplay = new CurrentConditionsDisplay(wd);
            StatisticsDisplay        statisticsDisplay        = new StatisticsDisplay(wd);
            ForecastDisplay          forecastDisplay          = new ForecastDisplay(wd);
            HeatIndexDisplay         heheatDisplay            = new HeatIndexDisplay(wd);

            wd.UpdateMeasurements(80, 65, 30.4f);
            wd.UpdateMeasurements(82, 70, 29.2f);
            wd.UpdateMeasurements(78, 90, 29.2f);
        }
예제 #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("WeatherStation");

            WeatherData weatherData = new WeatherData();

            StatisticsDisplay statisticsDisplay = new StatisticsDisplay(weatherData);
            ForecastDisplay   forecastDisplay   = new ForecastDisplay(weatherData);
            CurrentConditions currentConditions = new CurrentConditions(weatherData);

            while (true)
            {
                weatherData.MeasurementsChanged();
                Thread.Sleep(1000);
            }
        }
예제 #6
0
        public static void Main()
        {
            WeatherData weatherData = new WeatherData();

            CurrentConditionsDisplay currentConditionsDisplay = new CurrentConditionsDisplay(weatherData);
            StatisticsDisplay        statisticsDisplay        = new StatisticsDisplay(weatherData);
            ForcastDisplay           forcastDisplay           = new ForcastDisplay(weatherData);
            HeatIndexDisplay         heatIndexDisplay         = new HeatIndexDisplay(weatherData);

            Console.WriteLine("The Weather Station App...");

            weatherData.SetMeasurements(80, 65, 30.4f);
            weatherData.SetMeasurements(82, 70, 29.2f);
            weatherData.SetMeasurements(78, 90, 29.2f);

            Console.ReadLine();
        }
        private static void DoWork()
        {
            WeatherProvider          weatherProvider   = new WeatherProvider();
            CurrentConditionsDisplay currentDisplay    = new CurrentConditionsDisplay();
            ForecastDisplay          forecastDisplay   = new ForecastDisplay();
            StatisticsDisplay        statisticsDisplay = new StatisticsDisplay();
            HeatIndexDisplay         heatIndexDisplay  = new HeatIndexDisplay();

            currentDisplay.Subscribe(weatherProvider);
            forecastDisplay.Subscribe(weatherProvider);
            statisticsDisplay.Subscribe(weatherProvider);
            heatIndexDisplay.Subscribe(weatherProvider);

            weatherProvider.SetMeasurements(80, 65, 30.4f);
            weatherProvider.SetMeasurements(82, 70, 29.2f);
            weatherProvider.SetMeasurements(78, 90, 29.2f);
            weatherProvider.EndService();
        }
        static void Main()
        {
            WeatherData weatherData = new WeatherData();

            CurrentConditionsDisplay currentDisplay    = new CurrentConditionsDisplay(weatherData);
            StatisticsDisplay        statisticsDisplay = new StatisticsDisplay(weatherData);
            ForecastDisplay          forecastDisplay   = new ForecastDisplay(weatherData);

            weatherData.SetMeasurements(80, 65, 30.4f);
            Console.WriteLine("++++++++++++++++++++++");
            weatherData.SetMeasurements(82, 70, 29.2f);
            Console.WriteLine("++++++++++++++++++++++");
            weatherData.SetMeasurements(78, 90, 29.2f);

            //currentDisplay.Display();
            //Console.WriteLine("=======================");
            //statisticsDisplay.Display();
            //Console.WriteLine("=======================");
            //forecastDisplay.Display();
            //Console.WriteLine("=======================");
        }
예제 #9
0
        static void Main(string[] args)
        {
            WeatherData weatherData = new WeatherData();

            CurrentConditionsDisplay currentConditionsDisplay = new CurrentConditionsDisplay();
            StatisticsDisplay        statisticsDisplay        = new StatisticsDisplay();

            weatherData.RegisterObserver(currentConditionsDisplay);
            weatherData.RegisterObserver(statisticsDisplay);

            weatherData.MeasurementsChanged();

            currentConditionsDisplay.Display();
            statisticsDisplay.Display();

            weatherData.MeasurementsChanged();

            currentConditionsDisplay.Display();
            statisticsDisplay.Display();

            Console.ReadKey();
        }
예제 #10
0
        static void Main(string[] args)
        {
            // Create new weather station object
            WeatherData weatherData = new WeatherData();

            // Create new displays and attach them to the new station in the constructor
            CurrentConditionDisplay currentDisplay    = new CurrentConditionDisplay(weatherData);
            StatisticsDisplay       statisticsDisplay = new StatisticsDisplay(weatherData);
            ForecastDisplay         forecastDisplay   = new ForecastDisplay(weatherData);
            HeatIndexDisplay        heatIndexDisplay  = new HeatIndexDisplay(weatherData);

            // Update the weather
            weatherData.SetMeasurements(80, 65, 30.4f);
            weatherData.SetMeasurements(82, 70, 29.2f);

            // Detach ForecastDisplay
            weatherData.Detach(forecastDisplay);

            // Update should now exclude the forecast text
            weatherData.SetMeasurements(78, 90, 29.2f);


            Console.Read();
        }
예제 #11
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            Console.WriteLine("OpenWeatherAPI Example Application");
            Console.WriteLine();

            Console.WriteLine("Виберіть місто для перегляду погоди:");
            //var city = Console.ReadLine();
            string city1 = "Hrebinka";
            string city2 = "Kiev";
            string city3 = "London";

            Console.WriteLine();

            WeatherCity weather1 = new WeatherCity(city1);
            WeatherCity weather2 = new WeatherCity(city2);
            WeatherCity weather3 = new WeatherCity(city3);

            //створюємо Subject
            WeatherData sinopticUa = new WeatherData();

            //створюємо Observers
            CurrentConditionDisplay display1 = new CurrentConditionDisplay();
            StatisticsDisplay       display2 = new StatisticsDisplay();
            ForecastDisplay         display3 = new ForecastDisplay();

            //підписуємо підписників на sinopticUa
            sinopticUa.EventWeather += display1.OnNext;
            sinopticUa.EventWeather += display2.OnNext;
            sinopticUa.EventWeather += display3.OnNext;
            sinopticUa.EventWeather += new Action <WeatherCity>((new  ForecastDisplay()).OnNext);
            //sinopticUa.EventWeather += x=> {   new WeatherCity("Lviv"); };

            //Змінюємо показники погоди
            sinopticUa.SetMeasuremants(weather1);
            //Розсилаємо погоду
            sinopticUa.Notify();

            sinopticUa.SetMeasuremants(weather2);
            sinopticUa.Notify();
            sinopticUa.SetMeasuremants(weather3);
            sinopticUa.Notify();

            Console.WriteLine();

            display2.canUse          = false;           // display2 відписується від sinopticUa
            sinopticUa.EventWeather -= display1.OnNext; // sinopticUa відписує display1

            sinopticUa.Notify();


            //запишемо погоду в файл
            WeatherCreator creator = new WeatherCreator();

            creator.SaveToFile(weather3 as IWeatherCity, @"D:\WeatherCity.txt");

            List <IWeatherCity> arr = creator.ReadFromFile(@"D:\WeatherCity1.txt");

            Console.ReadLine();

            DAOWeather weather = new DAOWeather("myDB2");

            weather.PrintConnectionInfo();
            Console.WriteLine();
        }