예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="recognitionService"></param>
        public PreviewViewModel(RecognitionService recognitionService)
        {
            RecognitionService = recognitionService ?? throw new ArgumentNullException(nameof(recognitionService));

            Observable.FromEventPattern(
                RecognitionService,
                nameof(RecognitionService.Started))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(_ =>
            {
                IsStartedAgain = IsActive;
                Text           = "Waiting command...";
                IsActive       = true;
            });
            Observable.FromEventPattern <ICommand>(
                RecognitionService,
                nameof(RecognitionService.PreviewCommandReceived))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(pattern =>
            {
                Text = $"{pattern.EventArgs}";
            });
            Observable.FromEventPattern <ICommand>(
                RecognitionService,
                nameof(RecognitionService.CommandReceived))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(pattern =>
            {
                Text = pattern.EventArgs.IsEmpty
                        ? "Didn't get that."
                        : $"{pattern.EventArgs}";
            });
            Observable.FromEventPattern <ICommand>(
                RecognitionService,
                nameof(RecognitionService.CommandReceived))
            .Delay(TimeSpan.FromSeconds(3))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(_ =>
            {
                IsActive       = IsStartedAgain;
                Text           = IsStartedAgain ? Text : string.Empty;
                IsStartedAgain = false;
            });

            Close = ReactiveCommand.CreateFromTask(async cancellationToken =>
            {
                IsActive = false;

                await RecognitionService.StopAsync(cancellationToken).ConfigureAwait(false);
            }).WithDefaultCatch(this);
        }
예제 #2
0
        public static async Task Start5SecondsStart5SecondsStopTestAsync(
            this RecognitionService service,
            CancellationToken cancellationToken = default)
        {
            await service.StartAsync(cancellationToken);

            await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);

            await service.StartAsync(cancellationToken);

            await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);

            await service.StopAsync(cancellationToken);
        }