Пример #1
0
        /// <summary>
        /// Creates an IResultList for the paging object located in the response to a Spotify URI.
        /// </summary>
        /// <returns>The IResultList.</returns>
        /// <param name="uri">The entire Spotify request URI (including the BASE_ADDRESS).</param>
        /// <param name="isWrapped">
        /// If set to <c>true</c>, the paging object is wrapped in a SearchResult, which actually contains multiple
        /// paging objects. We deduce which one to use based on type parameter Q.
        /// </param>
        /// <typeparam name="T">The internal data type; an instance of IMetadata.</typeparam>
        /// <typeparam name="Q">The json data type; an instance of IMetadataResult.</typeparam>
        public IResultList <T> PagingUri <T, Q>(string uri, bool isWrapped) where T : IMetadata where Q : IMetadataResult
        {
            var task = Task.Run(async() =>
            {
                return(await GetJsonFullUri(uri));
            });

            var json = task.Result;

            PagingObjectResult <Q> theList;

            if (isWrapped)
            {
                var jsonResult = JsonConvert.DeserializeObject <SearchResult <Q> >(json);
                theList = PagingObjectResult <Q> .CastTypeParam <Q>(jsonResult.Items);
            }
            else
            {
                theList = JsonConvert.DeserializeObject <PagingObjectResult <Q> >(json);
            }

            // Store metadata in the cache so we can use it, if possible
            foreach (var item in theList.items)
            {
                metadata.CacheSubmit(item);
            }

            var search = new PagingWrapper <T, Q>(theList, this, isWrapped);

            return(search);
        }
Пример #2
0
        internal SpotifyPlaylist(MetadataFactory factory, PartialPlaylistResult result, WebApi webApi)
        {
            this.factory = factory;
            this.uri     = result.uri;
            this.name    = result.name;

            var trackHref = result.tracks.href;

            var wrap = new PagingWrapper <ISong, PlaylistTrackResult>(trackHref, webApi, false);

            this.page1 = wrap;
        }
Пример #3
0
        internal SpotifyPlaylist(MetadataFactory factory, PlaylistResult result, WebApi webApi)
        {
            this.factory = factory;
            this.uri     = result.uri;
            this.name    = result.name;

            PagingObjectResult <PlaylistTrackResult> tracks = result.tracks;

            var wrap = new PagingWrapper <ISong, PlaylistTrackResult>(tracks, webApi, false);

            this.page1 = wrap;

            // Submit items for caching
            foreach (var playlistTrack in tracks.items)
            {
                this.factory.CacheSubmit(playlistTrack);
            }
        }