Пример #1
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            _state.AccessTime   = TimeSpan.Parse(await GetParam("accessTime") ?? "00:00:10");
            _state.LockWhenShut = bool.Parse(await GetParam("lockOnClose") ?? bool.TrueString);
            _state.ArmWhenShut  = bool.Parse(await GetParam("armOnClose") ?? bool.TrueString);

            await _relayControlService.SetRelayStateAsync(1, false);

            await _commandReceiver.SetCommandHandler <Command, object>(CommandHandler);

            whenButtonPressedSubscription = WhenButtonPressedOpened.Subscribe(async _ =>
                                                                              await _mediator.Publish(new ButtonPressedNotification()));

            whenButtonReleasedSubscription = WhenButtonReleasedClosed.Subscribe(async _ =>
                                                                                await _mediator.Publish(new ButtonReleasedNotification()));

            whenSwitchClosedSubscription = WhenSwitchClosed.Subscribe(async _ =>
                                                                      await _mediator.Publish(new DoorClosedNotification()));

            whenSwitchOpenedSubscription = WhenSwitchOpened.Subscribe(async _ =>
                                                                      await _mediator.Publish(new DoorOpenedNotification()));

            whenMotionDetectedSubscription = WhenMotionDetected.Subscribe(async _ =>
                                                                          await _mediator.Publish(new MotionDetectedNotification()));

            whenMotionNotDetectedSubscription = WhenMotionNotDetected.Subscribe(async _ =>
                                                                                await _mediator.Publish(new MotionNotDetectedNotification()));

            whenCardDataReceivedSubscription = _rfidReader
                                               .WhenCardDetected
                                               .Throttle(TimeSpan.FromMilliseconds(800))
                                               .Subscribe(async cardData =>
                                                          await _mediator.Publish(new OnTagReadNotification(cardData)));

            await _rfidReader.StartAsync();
        }