Exemple #1
0
        /// <summary>
        /// Move to the next OmdbItem
        /// </summary>
        /// <returns></returns>
        public async Task MoveNext()
        {
            this._currentIndex += 1;
            if (this._currentIndex == this.Count)
            {
                throw new System.Exception("Attempted to move to next and there are no further items. Please check with HasNext before using MoveNext.");
            }

            if (this._currentIndex == this._omdbItems.Count)
            {
                this._currentPage += 1;
                OmdbSearchResults results = await this._client.InternalSearchByTitleAsync(this._search, this._resultType, this._yearOfRelease, this._currentPage);

                if (results.Response.HasValue && !results.Response.Value)
                {
                    this._currentPage  -= 1;
                    this._currentIndex -= 1;
                    throw new System.Exception("Attempted to move to next and there was no further pages. Please check with HasNext before using MoveNext.");
                }

                if (results.Search != null)
                {
                    this._omdbItems.AddRange(results.Search);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Initialize the Lazy Omdb Search List with all of the known contents.
        /// </summary>
        /// <returns>The initalized Omdb List so that it can be chained if so desired</returns>
        /// <exception cref="OmdbException">Thrown when the search fails for some reason</exception>
        internal async Task <LazyOmdbList> InitializeAsync()
        {
            OmdbSearchResults results = await this._client.InternalSearchByTitleAsync(this._search, this._resultType, this._yearOfRelease, this._currentPage);

            if (results.Response is false)
            {
                throw new OmdbException(results.Error);
            }

            if (results.Search != null)
            {
                this._omdbItems.AddRange(results.Search);
            }

            if (results.TotalResults != null)
            {
                this.Count = (int)results.TotalResults;
            }

            return(this);
        }