Пример #1
0
        static void Main(string[] args)
        {
            WeatherData             data = new WeatherData();
            CurrentConditionsReport currentConditionsReport = new CurrentConditionsReport();
            StatisticReport         statisticReport         = new StatisticReport();

            data.Register(currentConditionsReport);
            data.Register(statisticReport);
            int    time = 0, period = 0;
            string str = " ";

            while (!int.TryParse(str, out time) || time < 0)
            {
                Console.WriteLine("Enter time in seconds: ");
                str = Console.ReadLine();
            }

            str = " ";
            while (!int.TryParse(str, out period) || period < 0)
            {
                Console.WriteLine("Enter period in milliseconds: ");
                str = Console.ReadLine();
            }

            Start(time, period, data);

            Console.WriteLine(statisticReport.GenerateReport());
        }
Пример #2
0
        static void Main(string[] args)
        {
            WeatherData             sender = new WeatherData();
            CurrentConditionsReport currentConditionsReport =
                new CurrentConditionsReport(sender);

            currentConditionsReport.Subscribe(sender);
            StatisticReport statisticReport = new StatisticReport(sender);

            statisticReport.Subscribe(sender);
            WeatherInfo weatherInfo = new WeatherInfo(20, 740, 75);

            sender.Notify(sender, weatherInfo);
            Random rnd = new Random();

            for (int i = 0; i < 10; i++)
            {
                Thread.Sleep(500);
                weatherInfo = new WeatherInfo(
                    rnd.Next(-3, 20),
                    rnd.Next(730, 780),
                    rnd.Next(60, 95));
                sender.Notify(sender, weatherInfo);
                Console.WriteLine("Temperature {0}, Pressure {1}, Humidity {2}",
                                  currentConditionsReport.WthrInfo.Temperature,
                                  currentConditionsReport.WthrInfo.Pressure,
                                  currentConditionsReport.WthrInfo.Humidity);
            }

            Console.WriteLine();
            Console.WriteLine("Stat report:");
            Console.WriteLine("MinTemperature: {0}", statisticReport.GetTemperatureMin());
            Console.WriteLine("MaxTemperature: {0}", statisticReport.GetTemperatureMax());
            Console.WriteLine("MinPressure: {0}", statisticReport.GetPresureMin());
            Console.WriteLine("MaxPressure: {0}", statisticReport.GetPresureMax());
            Console.WriteLine("MinHumidity: {0}", statisticReport.GetHumidityMin());
            Console.WriteLine("MinHumidity: {0}", statisticReport.GetHumidityMax());
            Console.WriteLine("AverageTemperature: {0}", statisticReport.GetTemperatureAverage());
            Console.WriteLine("AveragePressure: {0}", statisticReport.GetPressureAverage());
            Console.WriteLine("AverageHumidity: {0}", statisticReport.GetHumidityAverage());

            currentConditionsReport.UnSubscribe(sender);
            sender.Notify(sender, weatherInfo);
            try
            {
                Console.WriteLine("Temperature: {0}", currentConditionsReport.WthrInfo.Temperature);
            }
            catch (ArgumentNullException e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("Try again!!!");
            Thread.Sleep(3000);
            currentConditionsReport.Subscribe(sender);
            sender.Notify(sender, weatherInfo);
            Console.WriteLine("Temperature: {0}", currentConditionsReport.WthrInfo.Temperature);

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            var weatherData             = new WeatherData();
            var currentConditionsReport = new CurrentConditionsReport();
            var statisticsReport        = new StatisticReport();

            weatherData.Register(currentConditionsReport);
            weatherData.Register(statisticsReport);

            var weatherInfo = new WeatherInfo()
            {
                Temperature = 10, Humidity = 15, Pressure = 30
            };

            weatherData.UpdateWeatherInfo(weatherInfo);

            Console.WriteLine(currentConditionsReport.MakeReport() + "\n\n");
            Console.WriteLine(statisticsReport.MakeReport() + "\n\n");

            weatherInfo.Temperature = -10;
            weatherInfo.Humidity    = 3;
            weatherInfo.Pressure    = 87;
            weatherData.UpdateWeatherInfo(weatherInfo);

            Console.WriteLine(currentConditionsReport.MakeReport() + "\n\n");
            Console.WriteLine(statisticsReport.MakeReport() + "\n\n");
        }
Пример #4
0
        static void Main(string[] args)
        {
            WeatherData weather = new WeatherData();

            StatisticReport         report        = new StatisticReport();
            CurrentConditionsReport currentReport = new CurrentConditionsReport();

            weather.NewMail += report.Update;
            weather.NewMail += currentReport.Update;

            ConsoleKey command;

            Console.WriteLine("Press Q to watch current weather or ESC to stop.");
            do
            {
                while (!Console.KeyAvailable)
                {
                }
                command = Console.ReadKey(true).Key;

                if (command == ConsoleKey.Q)
                {
                    Console.WriteLine(currentReport);
                }
            }while (command != ConsoleKey.Escape);


            Console.WriteLine("All records:");
            Console.WriteLine(report.ToString());

            Console.ReadKey();
        }
Пример #5
0
        public static void Main(string[] args)
        {
            var weatherData = new WeatherData();

            var currentReport   = new CurrentConditionsReport();
            var statisticReport = new StatisticReport();

            currentReport.Subscribe(weatherData);
            statisticReport.Subscribe(weatherData);

            var simulator = new SendingDataForWeatherDataSimulator();
            var timer     = new Timer();

            weatherData.StartCheckingData(500);
            simulator.StartGeneration(weatherData, timer, 600);

            Console.WriteLine("Press enter to stop simulation");
            Console.ReadLine();

            simulator.StopGenerating(timer);
            weatherData.StopCheckingData();

            currentReport.Unsubscribe(weatherData);
            statisticReport.Unsubscribe(weatherData);

            Console.WriteLine(currentReport);
            Console.WriteLine(statisticReport);
        }
        static void Main(string[] args)
        {
            WeatherData             weatherData             = new WeatherData();
            StatisticReport         statisticReport         = new StatisticReport(weatherData);
            CurrentConditionsReport currentConditionsReport = new CurrentConditionsReport(weatherData);

            weatherData.Start();
            Console.ReadKey();
        }
Пример #7
0
        static void Main(string[] args)
        {
            WeatherData             weather           = new WeatherData();
            CurrentConditionsReport observer          = new CurrentConditionsReport(weather);
            StatisticReport         statisticObserver = new StatisticReport(weather);

            weather.Start();
            Console.Read();
        }
Пример #8
0
        private static void Main(string[] args)
        {
            weather   = new WeatherData();
            statistic = new StatisticReport();
            current   = new CurrentConditionsReport();

            statistic.Register(weather);
            current.Register(weather);
            GetReports();
        }
Пример #9
0
        static void Main(string[] args)
        {
            WeatherData weatherData = new WeatherData();

            StatisticReport         statisticReport         = new StatisticReport(weatherData);
            CurrentConditionsReport currentConditionsReport = new CurrentConditionsReport(weatherData);

            weatherData.GenerateInfo();

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            WeatherData             waetherStation   = new WeatherData();
            CurrentConditionsReport conditionsReport = new CurrentConditionsReport();
            StatisticReport         statisticReport  = new StatisticReport();

            conditionsReport.Register(waetherStation);
            statisticReport.Register(waetherStation);
            statisticReport.Unregister(waetherStation);

            waetherStation.StartNotify();
        }
        static void TestPatternWithInterfaces()
        {
            WeatherInfo weatherInfo = new WeatherInfo()
            {
                Temperature = 1, Humidity = 2, Pressure = 2,
            };
            WeatherData weatherData = new WeatherData();

            Report currentReport   = new CurrentConditionsReport(weatherData);
            Report statisticReport = new StatisticReport(weatherData);

            weatherData.Start(5);
        }
Пример #12
0
        private static void Main(string[] args)
        {
            weather   = new WeatherData();
            statistic = new StatisticReport();
            current   = new CurrentConditionsReport();

            weather.Register(statistic);
            weather.Register(current);

            Thread getThread = new Thread(GetReports);

            getThread.Start();
            weather.StartGenerator();
        }
Пример #13
0
        static void Main(string[] args)
        {
            WeatherData weatherData = new WeatherData();

            CurrentConditionsReport current   = new CurrentConditionsReport();
            StatisticReport         statistic = new StatisticReport(10, 80, 756);

            weatherData.Register(current);
            weatherData.Register(statistic);

            weatherData.EmulateWeatherChange();
            weatherData.EmulateWeatherChange();

            Console.ReadKey();
        }
Пример #14
0
        public static void Main(string[] args)
        {
            var weatherStation = new WeatherData();
            var currentInfo    = new CurrentConditionsReport();
            var statisticInfo  = new StatisticReport();

            currentInfo.Register(weatherStation);
            statisticInfo.Register(weatherStation);

            while (true)
            {
                Thread.Sleep(2000);
                weatherStation.GenerateWeather();
                Console.WriteLine("Current info: " + currentInfo);
                Console.WriteLine("Statistic: " + statisticInfo);
            }
        }
Пример #15
0
        static void Main(string[] args)
        {
            var weatherData              = new WeatherData();
            var currentConditionsReport  = new CurrentConditionsReport();
            var currentConditionsReport1 = new CurrentConditionsReport();
            var statisticReport          = new StatisticReport();

            weatherData.Register(statisticReport);
            weatherData.Register(currentConditionsReport);
            weatherData.Register(currentConditionsReport1);

            Thread weatherStationThread = new Thread(weatherData.GenerateInfo);

            weatherStationThread.Start();

            Thread.Sleep(10000);
            weatherData.Unregister(currentConditionsReport);
        }
Пример #16
0
        static void Main(string[] args)
        {
            Console.WriteLine("Create Current Conditions Report");
            CurrentConditionsReport conditionsReport = new CurrentConditionsReport();

            Console.WriteLine("Create Statistic Report");
            StatisticReport statisticReport = new StatisticReport();

            Console.WriteLine("Create observable object: Weather data");
            WeatherData weatherData = new WeatherData(50, 2);

            Console.WriteLine("Register observers Current Conditions Report and Statistic Report");
            weatherData.Register(conditionsReport);
            weatherData.Register(statisticReport);

            weatherData.StartMeasure();
            Console.ReadLine();
        }
Пример #17
0
        public static void Main(string[] args)
        {
            WeatherData observable = new WeatherData();

            StatisticReport         reporter  = new StatisticReport();
            CurrentConditionsReport condition = new CurrentConditionsReport(observable);

            reporter.Register(observable);

            TimerCallback callback = GenerateInfo;
            Timer         timer    = new Timer(callback, observable, 0, 2000);

            if (Console.ReadKey() != null)
            {
                timer.Dispose();
            }

            Console.ReadKey();
        }
Пример #18
0
        static void Main(string[] args)
        {
            var sender = new WeatherData();
            var currentConditionsReport = new CurrentConditionsReport();
            var statisticReport         = new StatisticReport();

            //Subscribe
            sender.WeatherDataChandged += currentConditionsReport.Update;
            sender.WeatherDataChandged += statisticReport.Update;


            var weatherInfoEventArgs = new WeatherInfoEventArgs(20, 740, 75);

            sender.NewWeatherDataAvailable(weatherInfoEventArgs);
            Console.WriteLine("Temperature {0}, Pressure {1}, Humidity {2}",
                              currentConditionsReport.WthrInfo.Temperature,
                              currentConditionsReport.WthrInfo.Pressure,
                              currentConditionsReport.WthrInfo.Humidity);
            sender.NewWeatherDataAvailable(weatherInfoEventArgs);

            // WeatherStation emulation
            Random rnd = new Random();

            for (int i = 0; i < 10; i++)
            {
                Thread.Sleep(10);
                weatherInfoEventArgs = new WeatherInfoEventArgs(
                    rnd.Next(-3, 20),
                    rnd.Next(730, 780),
                    rnd.Next(60, 95));
                sender.NewWeatherDataAvailable(weatherInfoEventArgs);
                Console.WriteLine("Temperature {0}, Pressure {1}, Humidity {2}",
                                  currentConditionsReport.WthrInfo.Temperature,
                                  currentConditionsReport.WthrInfo.Pressure,
                                  currentConditionsReport.WthrInfo.Humidity);
            }

            Console.WriteLine();
            Console.WriteLine("Stat report:");
            Console.WriteLine("MinTemperature: {0}", statisticReport.GetTemperatureMin());
            Console.WriteLine("MaxTemperature: {0}", statisticReport.GetTemperatureMax());
            Console.WriteLine("MinPressure: {0}", statisticReport.GetPressureMin());
            Console.WriteLine("MaxPressure: {0}", statisticReport.GetPresureMax());
            Console.WriteLine("MinHumidity: {0}", statisticReport.GetHumidityMin());
            Console.WriteLine("MinHumidity: {0}", statisticReport.GetHumidityMax());
            Console.WriteLine("AverageTemperature: {0}", statisticReport.GetTemperatureAverage());
            Console.WriteLine("AveragePressure: {0}", statisticReport.GetPressureAverage());
            Console.WriteLine("AverageHumidity: {0}", statisticReport.GetHumidityAverage());

            //Unsubscribe
            Console.WriteLine("Unsubscribe");
            sender.WeatherDataChandged -= currentConditionsReport.Update;
            weatherInfoEventArgs        = new WeatherInfoEventArgs(20, 740, 75);
            sender.NewWeatherDataAvailable(weatherInfoEventArgs);
            Console.WriteLine("Temperature: {0}", currentConditionsReport.WthrInfo.Temperature);

            //Subscribe
            Console.WriteLine("Subscribe");
            Thread.Sleep(1000);
            sender.WeatherDataChandged += currentConditionsReport.Update;
            weatherInfoEventArgs        = new WeatherInfoEventArgs(20, 740, 75);
            sender.NewWeatherDataAvailable(weatherInfoEventArgs);

            Console.WriteLine("Temperature: {0}", currentConditionsReport.WthrInfo.Temperature);

            Console.ReadLine();
        }