public SongTileViewModel(Song model, IPlayApi playApi)
        {
            Model = model;

            playApi.FetchImageForAlbum(model)
            .LoggedCatch(this, Observable.Return(default(BitmapImage)))
            .ToProperty(this, x => x.AlbumArt);

            QueueSong  = new ReactiveAsyncCommand();
            QueueAlbum = new ReactiveAsyncCommand();

            QueueSong.RegisterAsyncObservable(_ => playApi.QueueSong(Model))
            .Subscribe(
                x => this.Log().Info("Queued {0}", Model.name),
                ex => this.Log().WarnException("Failed to queue", ex));

            QueueAlbum.RegisterAsyncObservable(_ => playApi.AllSongsOnAlbum(Model.artist, Model.album))
            .SelectMany(x => x.ToObservable())
            .Select(x => reallyTryToQueueSong(playApi, x)).Concat()
            .Subscribe(
                x => this.Log().Info("Queued song"),
                ex => this.Log().WarnException("Failed to queue album", ex));

            QueueAlbum.ThrownExceptions.Subscribe(x => { });

            IsStarred     = model.starred;
            ToggleStarred = new ReactiveAsyncCommand();

            ToggleStarred.RegisterAsyncObservable(_ => IsStarred ? playApi.Unstar(Model) : playApi.Star(Model))
            .Select(_ => true).LoggedCatch(this, Observable.Return(false))
            .Subscribe(result => {
                if (result)
                {
                    IsStarred = !IsStarred;
                }
            }, ex => this.Log().WarnException("Couldn't star/unstar song", ex));

            ToggleStarred.ThrownExceptions.Subscribe(x => { });
        }
Exemple #2
0
        public SongTileViewModel(Song model, IPlayApi playApi)
        {
            Model = model;

            playApi.FetchImageForAlbum(model)
                .LoggedCatch(this, Observable.Return(default(BitmapImage)))
                .ToProperty(this, x => x.AlbumArt);

            QueueSong = new ReactiveAsyncCommand();
            QueueAlbum = new ReactiveAsyncCommand();

            QueueSong.RegisterAsyncObservable(_ => playApi.QueueSong(Model))
                .Subscribe(
                    x => this.Log().Info("Queued {0}", Model.name),
                    ex => this.Log().WarnException("Failed to queue", ex));

            QueueAlbum.RegisterAsyncObservable(_ => playApi.AllSongsOnAlbum(Model.artist, Model.album))
                .SelectMany(x => x.ToObservable())
                .Select(x => reallyTryToQueueSong(playApi, x)).Concat()
                .Subscribe(
                    x => this.Log().Info("Queued song"),
                    ex => this.Log().WarnException("Failed to queue album", ex));

            QueueAlbum.ThrownExceptions.Subscribe(x => { });

            IsStarred = model.starred;
            ToggleStarred = new ReactiveAsyncCommand();

            ToggleStarred.RegisterAsyncObservable(_ => IsStarred ? playApi.Unstar(Model) : playApi.Star(Model))
                .Select(_ => true).LoggedCatch(this, Observable.Return(false))
                .Subscribe(result => {
                    if (result) IsStarred = !IsStarred;
                }, ex => this.Log().WarnException("Couldn't star/unstar song", ex));

            ToggleStarred.ThrownExceptions.Subscribe(x => { });
        }
Exemple #3
0
 IObservable<Unit> reallyTryToQueueSong(IPlayApi playApi, Song song)
 {
     return Observable.Defer(() => playApi.QueueSong(song))
         .Timeout(TimeSpan.FromSeconds(20), RxApp.TaskpoolScheduler)
         .Retry(3);
 }
 IObservable <Unit> reallyTryToQueueSong(IPlayApi playApi, Song song)
 {
     return(Observable.Defer(() => playApi.QueueSong(song))
            .Timeout(TimeSpan.FromSeconds(20), RxApp.TaskpoolScheduler)
            .Retry(3));
 }