Ejemplo n.º 1
0
        private void Process()
        {
            while (!_stop)
            {
                SendMessageLater message;
                SendMessageLater marker = null;

                while (_alarms.TryDequeue(out message))
                {
                    if (message == marker)
                    {
                        _alarms.Enqueue(message);
                        break;
                    }

                    if ((DateTime.UtcNow - message.When).Seconds > 0)
                    {
                        _bus.Publish(message.Message);
                    }
                    else
                    {
                        marker = marker ?? message;
                        _alarms.Enqueue(message);
                    }
                }

                Thread.Sleep(1);
            }
            _stopped.Set();
        }
Ejemplo n.º 2
0
        public bool Handle(NeedToTakeAction message)
        {
            var sensor = message.MessageWithIssues as TemperatureChanged;

            if (sensor != null)
            {
                Console.WriteLine("Stopping sensor : {0} for 2 seconds", sensor.SensorName);
                _bus.Publish(new DisableSensor(sensor.SensorName));
                _bus.Publish(new SendMessageLater(DateTime.UtcNow.AddSeconds(2), new EnableSensor(sensor.SensorName)));
            }
            else
            {
                Console.WriteLine("Sending mail to an even more important man, problem with : {0}", message.MessageWithIssues.GetType().Name);
            }

            return(true);
        }
Ejemplo n.º 3
0
        public bool Handle(Message message)
        {
            var alertableMessage = message as IAlertable;

            if (alertableMessage != null && !_threshold.IsWithinThreshold(alertableMessage.Value))
            {
                _bus.Publish(new NeedToTakeAction(message));
            }

            return(_handler.Handle(message));
        }
 private void MakeSensorTick()
 {
     Task.Factory.StartNew(() => {
         var r = new Random();
         while (true)
         {
             if (!_stop)
             {
                 _appBus.Publish(new TemperatureChanged(r.Next(0, 150), this.ToString()));
                 Thread.Sleep(200);
             }
             Thread.Sleep(1);
         }
     });
 }