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);

            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();
        }
Пример #2
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            _logger.LogInformation("RFID Service is starting.");

            subscription = _rfidReader.WhenCardDetected.Subscribe(async cardData =>
            {
                _logger.LogInformation("Sending UID");

                await _rfidHubContext.Clients.All.SendAsync("ReceiveCardData", cardData);
            });

            await _rfidReader.StartAsync();

            _logger.LogInformation("RFID Service has started.");
        }