public CachingSongFetcher(ISongFetcher <T> wrappedFetcher, IBlobCache cache, string cacheKey, TimeSpan cacheDuration) { if (wrappedFetcher == null) { throw new ArgumentNullException("wrappedFetcher"); } if (cache == null) { throw new ArgumentNullException(); } if (String.IsNullOrWhiteSpace(cacheKey)) { throw new ArgumentException("Cache key can't be null or empty", "cacheKey"); } if (cacheDuration < TimeSpan.Zero) { throw new ArgumentOutOfRangeException("cacheDuration"); } this.wrappedFetcher = wrappedFetcher; this.cache = cache; this.cacheKey = cacheKey; this.cacheDuration = cacheDuration; }
public ArtistsViewModel(ISongFetcher <T> songFetcher, string serializationKey) { if (songFetcher == null) { throw new ArgumentNullException("songFetcher"); } this.Activator = new ViewModelActivator(); this.WhenActivated(() => { var disposable = new CompositeDisposable(); this.LoadCommand = ReactiveCommand.CreateAsyncObservable(_ => songFetcher.GetSongsAsync() .Timeout(LoadCommandTimeout, RxApp.TaskpoolScheduler) .TakeUntil(disposable)); this.artists = this.LoadCommand .Do(x => this.songs = x) .Select(GetArtists) .ToProperty(this, x => x.Artists, new List <string>()); this.WhenAnyValue(x => x.SelectedArtist).Where(x => x != null) .Select(FilterSongsByArtist) .Select(x => BlobCache.LocalMachine.InsertObject(serializationKey, x)) .Concat() .Subscribe(); return(disposable); }); }
public RemoteArtistsViewModel(ISongFetcher <NetworkSong> songFetcher = null, IBlobCache cache = null) : base(new CachingSongFetcher <NetworkSong>(songFetcher ?? new RemoteSongFetcher(), cache ?? BlobCache.LocalMachine, BlobCacheKeys.RemoteSongs, CacheDuration), BlobCacheKeys.SelectedRemoteSongs) { }