public void Subscribe(string eventName, IEventReceiver receiver)
        {
            if (!eventFilter.ContainsKey(eventName))
            {
                Log(LogLevel.Error, Resources.MissingEventSubError, eventName);
                return;
            }

            if (stateCallbacks.ContainsKey(eventName))
            {
                var ev = stateCallbacks[eventName]();
                if (ev != null)
                {
                    receiver.HandleEvent(ev);
                }
            }

            lock (eventFilter[eventName])
            {
                if (!eventFilter[eventName].Contains(receiver))
                {
                    eventFilter[eventName].Add(receiver);
                }
            }
        }
示例#2
0
        public void DoUpdate()
        {
            if (_sensors.GetBrewButtonStatus() == BrewButtonStatus.PUSHED)
            {
                _eventReceiver.HandleEvent(Events.ButtonPushed);
            }

            switch (_sensors.GetWarmerPlateStatus())
            {
            case WarmerPlateStatus.POT_EMPTY:
                _eventReceiver.HandleEvent(Events.PotEmpty);
                break;

            case WarmerPlateStatus.POT_NOT_EMPTY:
                _eventReceiver.HandleEvent(Events.PotPresent);
                break;

            case WarmerPlateStatus.WARMER_EMPTY:
                _eventReceiver.HandleEvent(Events.PotRemoved);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            switch (_sensors.GetBoilerStatus())
            {
            case BoilerStatus.EMPTY:
                _eventReceiver.HandleEvent(Events.BoilerEmpty);
                break;

            case BoilerStatus.NOT_EMPTY:
                _eventReceiver.HandleEvent(Events.BoilerNotEmpty);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }