예제 #1
0
        public DoorService(IOutboundEventBus outboundEventBus, SwitchDriver doorReedSwitch)
        {
            _outboundEventBus = outboundEventBus;
            _doorReedSwitch   = doorReedSwitch;

            OnDoorOpened = (sender, e) =>
            {
                _outboundEventBus.Send(new DoorOpenedEvent());
            };
            OnDoorClosed = (sender, e) =>
            {
                _outboundEventBus.Send(new DoorClosedEvent());
            };
        }
        public WindowsManagingService(LinearActuatorDriver window1Actuator,
                                      LinearActuatorDriver window2Actuator,
                                      SwitchDriver window1ReedSwitch,
                                      SwitchDriver window2ReedSwitch,
                                      SwitchDriver window1ControlSwitch,
                                      SwitchDriver window2ControlSwitch,
                                      IOutboundEventBus outboundEventBus)
        {
            _windowActuators       = new[] { window1Actuator, window2Actuator };
            _windowReedSwitches    = new[] { window1ReedSwitch, window2ReedSwitch };
            _windowControlSwitches = new[] { window1ControlSwitch, window2ControlSwitch };
            _windowStates          = new[] { window1ReedSwitch.GetState(), window2ReedSwitch.GetState() };
            _outboundEventBus      = outboundEventBus;

            OnWindow1Opened = (sender, e) =>
            {
                _windowStates[0] = SwitchState.Opened;
                _outboundEventBus.Send(new WindowOpenedEvent(0));
            };
            OnWindow1Closed = (sender, e) =>
            {
                _windowStates[0] = SwitchState.Closed;
                _windowActuators[0].StopMoving();
                _outboundEventBus.Send(new WindowClosedEvent(0));
            };

            OnWindow2Opened = (sender, e) =>
            {
                _windowStates[1] = SwitchState.Opened;
                _outboundEventBus.Send(new WindowOpenedEvent(1));
            };

            OnWindow2Closed = (sender, e) =>
            {
                _windowStates[1] = SwitchState.Closed;
                _windowActuators[1].StopMoving();
                _outboundEventBus.Send(new WindowClosedEvent(1));
            };

            //Control switches
            OnWindow1ControlSwitchOpened = (sender, e) => { OpenWindowAsync(0); };
            OnWindow1ControlSwitchClosed = (sender, e) =>
            {
                if (_windowStates[0] == SwitchState.Closed)
                {
                    return;
                }

                CloseWindowAsync(0);
            };

            OnWindow2ControlSwitchOpened = (sender, e) => { OpenWindowAsync(1); };

            OnWindow2ControlSwitchClosed = (sender, e) =>
            {
                if (_windowStates[1] == SwitchState.Closed)
                {
                    return;
                }

                CloseWindowAsync(1);
            };
        }