コード例 #1
0
ファイル: MobileClient.cs プロジェクト: quangfox/Espera
        private async Task <ResponseInfo> GetSoundCloudSongs(JToken parameters)
        {
            var searchTerm = parameters["searchTerm"].ToObject <string>();

            try
            {
                var requestCache = Locator.Current.GetService <IBlobCache>(BlobCacheKeys.RequestCacheContract);
                var songFinder   = new SoundCloudSongFinder(requestCache);

                IReadOnlyList <SoundCloudSong> songs = await songFinder.GetSongsAsync(searchTerm);

                // Cache the latest SoundCloud search request, so we can find the songs by GUID when
                // we add one to the playlist later
                this.lastSoundCloudRequest = songs;

                JObject content = MobileHelper.SerializeSongs(songs);

                return(CreateResponse(ResponseStatus.Success, content));
            }

            catch (NetworkSongFinderException)
            {
                return(CreateResponse(ResponseStatus.Failed, "Couldn't retrieve any SoundCloud songs"));
            }
        }
コード例 #2
0
            public async Task NullSearchTermDefaultsToEmptyString()
            {
                var songs = new[] { new SoundCloudSong { IsStreamable = true, StreamUrl = new Uri("http://blabla.com"), PermaLinkUrl = new Uri("http://blabla") } };
                var cache = new InMemoryBlobCache();
                cache.InsertObject(BlobCacheKeys.GetKeyForSoundCloudCache(string.Empty), songs);
                var finder = new SoundCloudSongFinder(cache);

                var result = await finder.GetSongsAsync();

                Assert.Equal(1, result.Count);
            }
コード例 #3
0
            public async Task UsesCachedSongsIfAvailable()
            {
                const string searchTerm = "Foo";
                var songs = new[] { new SoundCloudSong { IsStreamable = true, StreamUrl = new Uri("http://blabla.com"), PermaLinkUrl = new Uri("http://blabla") } };
                var cache = new InMemoryBlobCache();
                cache.InsertObject(BlobCacheKeys.GetKeyForSoundCloudCache(searchTerm), songs);
                var finder = new SoundCloudSongFinder(cache);

                var result = await finder.GetSongsAsync(searchTerm);

                Assert.Equal(1, result.Count);
            }
コード例 #4
0
            public async Task NullSearchTermDefaultsToEmptyString()
            {
                var songs = new[] { new SoundCloudSong {
                                        IsStreamable = true, StreamUrl = new Uri("http://blabla.com"), PermaLinkUrl = new Uri("http://blabla")
                                    } };
                var cache = new InMemoryBlobCache();

                cache.InsertObject(BlobCacheKeys.GetKeyForSoundCloudCache(string.Empty), songs);
                var finder = new SoundCloudSongFinder(cache);

                var result = await finder.GetSongsAsync();

                Assert.Equal(1, result.Count);
            }
コード例 #5
0
            public async Task UsesCachedSongsIfAvailable()
            {
                const string searchTerm = "Foo";
                var          songs      = new[] { new SoundCloudSong {
                                                      IsStreamable = true, StreamUrl = new Uri("http://blabla.com"), PermaLinkUrl = new Uri("http://blabla")
                                                  } };
                var cache = new InMemoryBlobCache();

                cache.InsertObject(BlobCacheKeys.GetKeyForSoundCloudCache(searchTerm), songs);
                var finder = new SoundCloudSongFinder(cache);

                var result = await finder.GetSongsAsync(searchTerm);

                Assert.Equal(1, result.Count);
            }
コード例 #6
0
        private async Task<ResponseInfo> GetSoundCloudSongs(JToken parameters)
        {
            var searchTerm = parameters["searchTerm"].ToObject<string>();

            try
            {
                var requestCache = Locator.Current.GetService<IBlobCache>(BlobCacheKeys.RequestCacheContract);
                var songFinder = new SoundCloudSongFinder(requestCache);

                IReadOnlyList<SoundCloudSong> songs = await songFinder.GetSongsAsync(searchTerm);

                // Cache the latest SoundCloud search request, so we can find the songs by GUID when
                // we add one to the playlist later
                this.lastSoundCloudRequest = songs;

                JObject content = MobileHelper.SerializeSongs(songs);

                return CreateResponse(ResponseStatus.Success, content);
            }

            catch (NetworkSongFinderException)
            {
                return CreateResponse(ResponseStatus.Failed, "Couldn't retrieve any SoundCloud songs");
            }
        }