public BackChannelConnection(AlarmEventsService alarmEvents)
        {
            _alarmEvents = alarmEvents ?? throw new ArgumentNullException(nameof(alarmEvents));

            _alarmEvents.AsObservable()
            .Where(x => x.Type == AlarmEvent.EventType.SensorAlarm && x.Status)
            .Subscribe(e =>
            {
                if (e.Numbers.FirstOrDefault() == 1)
                {
                    Connect();
                    _isDuplexMode = false;
                }
            });
        }
Пример #2
0
        public AlarmRingerViewModel(AlarmEventsService alarmEvents)
        {
            _wavePlayer = new WaveOut();

            var streamInfo = Application.GetResourceStream(new Uri("pack://application:,,,/Assets/DoorBell.mp3"));

            _wavePlayer.Init(new LoopStream(new Mp3FileReader(streamInfo.Stream)));

            ChangeActiveStateCommand = new RelayCommand <bool>(ChangeActiveState);

            ChangeMutedStateCommand = new RelayCommand(ChangeMuteState);

            alarmEvents.AsObservable()
            .Where(x => x.Type == AlarmEvent.EventType.SensorAlarm && x.Status)
            .Select(x => true)
            .ObserveOnDispatcher(DispatcherPriority.Send)
            .Subscribe(ChangeActiveState);
        }
Пример #3
0
        public IntercomViewModel(RtspDataService rtsp, AlarmEventsService alarmEvents)
        {
            _rtsp = rtsp ?? throw new ArgumentNullException(nameof(rtsp));

            _backChannelConnection = new BackChannelConnection(alarmEvents);

            IsDoorLocked = true;
            IsActive     = false;

            ChangeLockStateCommand = new RelayCommand(ChangeLockState);

            ChangeCallStateCommand = new RelayCommand(ChangeCallState);

            alarmEvents.AsObservable()
            .Where(x => x.Type == AlarmEvent.EventType.SensorAlarm && x.Status)
            .ObserveOnDispatcher(DispatcherPriority.Send)
            .Subscribe(e =>
            {
                IsActive = false;
                _activeCall?.Dispose();
            });
        }
        public IObservable <(bool Status, string Message)> UnlockDoor()
        {
            var isDuplexMode = _isDuplexMode;

            if (_isDuplexMode)
            {
                Disconnect();
            }

            return(Observable
                   .FromAsync(UnlockDoorAsync)
                   .Select(response =>
            {
                if (!response.Status)
                {
                    return Observable.Return(response);
                }
                else
                {
                    return _alarmEvents.AsObservable()
                    .Where(x => x.Type == AlarmEvent.EventType.SensorOutAlarm && x.Status == false)
                    .Timeout(TimeSpan.FromSeconds(10))
                    .Select(x => (response.Status, response.Message))
                    .OnErrorResumeNext <(bool Status, string Message)>(Observable.Return((false, "Device is not healthy.")));
                }
            })
                   .Switch()
                   .OnErrorResumeNext <(bool Status, string Message)>(Observable.Return((false, "Unable to unlock door.")))
                   .Take(1)
                   .Do(_ =>
            {
                if (isDuplexMode)
                {
                    Connect();
                }
            }));
        }