/// <summary>
        /// Start broadcasting.
        /// </summary>
        public void StartNotify()
        {
            ConsoleKeyInfo keyInfo = new ConsoleKeyInfo();

            Random rnd = new Random();

            while (keyInfo.Key != ConsoleKey.Escape)
            {
                WeatherInfo weather = new WeatherInfo()
                {
                    Temperature = rnd.Next(-30, 35),
                    Humidity    = rnd.Next(0, 99),
                    Pressure    = rnd.Next(0, 999),
                };

                Console.Clear();
                OnNewWeather(this, weather);

                Thread.Sleep(500);
                if (Console.KeyAvailable)
                {
                    keyInfo = Console.ReadKey();
                }
            }
        }
Exemplo n.º 2
0
        private void GenerateNewInfo()
        {
            int temperature = random.Next(0, 30);
            int humidity    = random.Next(0, 100);
            int pressure    = random.Next(0, 10000);

            _weatherInfo = new WeatherInfo(temperature, humidity, pressure);
        }
        /// <summary>
        /// Notify observer about change of info.
        /// </summary>
        /// <param name="sender">Reference to sender.</param>
        /// <param name="info">Information.</param>
        protected virtual void OnNewWeather(object sender, WeatherInfo info)
        {
            if (ReferenceEquals(info, null))
            {
                return;
            }

            NewWeather(this, info);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Notify all subscribers about new state.
 /// </summary>
 /// <param name="sender">The element with new state.</param>
 /// <param name="info">The state.</param>
 protected virtual void Notify(WeatherInfo info)
 {
     NewMail(this, info);
 }