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(); }
static void Main(string[] args) { var weatherData = new WeatherData(); var forecastDisplay = new ForecastDisplay(weatherData); var statDisplay = new StatisticDisplay(weatherData); weatherData.Humidity = 46.67; weatherData.Pressure = 20.23; weatherData.Temperature = 15.54; var displays = new List <IDisplay>(); displays.Add(forecastDisplay); displays.Add(statDisplay); weatherData.Humidity = 50.67; weatherData.Pressure = 67.23; weatherData.Temperature = 34.54; foreach (var display in displays) { display.Display(); } }
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); }
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); }
static void Main(string[] args) { var weatherData = new WeatherData(); var currentDisplay = new CurrentConditionsDisplay(weatherData); var staticsDisplay = new StaticsDisplay(weatherData); var forecastDisplay = new ForecastDisplay(weatherData); weatherData.SetMeasurements(80, 65, 30.4); weatherData.SetMeasurements(82, 70, 29.2); weatherData.SetMeasurements(78, 90, 29.2); Console.ReadKey(); }
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); } }
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("======================="); }
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(); }
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(); }