Exemplo n.º 1
0
        public SpeakersViewModel(AzureService azureService = null)
        {
            var service = azureService ?? DependencyService.Get <AzureService>();

            GetSpeakers = ReactiveCommand.CreateFromObservable(() => service.GetSpeakers());

            GetSpeakers
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(speakers =>
            {
                Speakers.Clear();
                Speakers.AddRange(speakers);
            });

            GetSpeakers.IsExecuting
            .ToProperty(this, vm => vm.IsBusy, out busy);

            GetSpeakers.ThrownExceptions
            .SelectMany(error => ConnectionError.Handle(error))
            .Subscribe();

            // go to details page when Speaker is set
            this.WhenAnyValue(vm => vm.Speaker)
            .Where(speaker => speaker != null)
            .Subscribe(speaker => this.PushPageFromCacheAsync <Details.DetailsViewModel>(vm => vm.Speaker = speaker));

            this.ThrownExceptions
            .Subscribe(ex =>
            {
                Debug.WriteLine(ex.Message);
            });
        }
        public SpeakersViewModel(AzureService azureService = null)
        {
            var service = azureService ?? DependencyService.Get <AzureService>();

            GetSpeakers = ReactiveCommand.CreateFromTask(_ => service.GetSpeakers());

            GetSpeakers
            .ObserveOn(RxApp.MainThreadScheduler)
            .SubscribeOn(RxApp.MainThreadScheduler)
            .Subscribe(speakers =>
            {
                Speakers.Clear();
                Speakers.AddRange(speakers);
            });

            GetSpeakers.IsExecuting
            .ToProperty(this, vm => vm.IsBusy, out busy);

            GetSpeakers.ThrownExceptions
            .Subscribe(error => Application.Current.MainPage.DisplayAlert("Error!", error.Message, "OK"));

            // go to details page when Speaker is set
            this.WhenAnyValue(vm => vm.Speaker)
            .Where(speaker => speaker != null)
            .Subscribe(speaker => this.PushPageFromCacheAsync <DetailsViewModel>(vm => vm.Speaker = speaker));

            this.ThrownExceptions
            .Subscribe(ex =>
            {
                Debug.WriteLine(ex.Message);
            });
        }