示例#1
0
        /// <summary>Adds a <see cref="TraktShow" />, which will be added to the watchlist post.</summary>
        /// <param name="show">The Trakt show, which will be added.</param>
        /// <param name="season">
        /// A season number for a season in the given show. The complete season will be added to the watchlist.
        /// </param>
        /// <param name="seasons">
        /// An optional array of season numbers for seasons in the given show.
        /// The complete seasons will be added to the watchlist.
        /// </param>
        /// <returns>The current <see cref="TraktSyncWatchlistPostBuilder" /> instance.</returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown, if the given show is null.
        /// Thrown, if the given show ids are null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Thrown, if the given show has no valid ids set.
        /// Thrown, if the given show has an year set, which has more or less than four digits.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Thrown, if at least one of the given season numbers is below zero.
        /// </exception>
        public TraktSyncWatchlistPostBuilder AddShow(TraktShow show, int season, params int[] seasons)
        {
            ValidateShow(show);

            EnsureShowsListExists();

            var seasonsToAdd = new int[seasons.Length + 1];

            seasonsToAdd[0] = season;
            seasons.CopyTo(seasonsToAdd, 1);

            var showSeasons = new List <TraktSyncWatchlistPostShowSeason>();

            for (int i = 0; i < seasonsToAdd.Length; i++)
            {
                if (seasonsToAdd[i] < 0)
                {
                    throw new ArgumentOutOfRangeException("at least one season number not valid");
                }

                showSeasons.Add(new TraktSyncWatchlistPostShowSeason {
                    Number = seasonsToAdd[i]
                });
            }

            var existingShow = _watchlistPost.Shows.Where(s => s.Ids == show.Ids).FirstOrDefault();

            if (existingShow != null)
            {
                existingShow.Seasons = showSeasons;
            }
            else
            {
                var watchlistShow = new TraktSyncWatchlistPostShow();
                watchlistShow.Ids   = show.Ids;
                watchlistShow.Title = show.Title;
                watchlistShow.Year  = show.Year;

                watchlistShow.Seasons = showSeasons;
                (_watchlistPost.Shows as List <TraktSyncWatchlistPostShow>).Add(watchlistShow);
            }

            return(this);
        }
示例#2
0
        /// <summary>Adds a <see cref="TraktShow" />, which will be added to the watchlist post.</summary>
        /// <param name="show">The Trakt show, which will be added.</param>
        /// <param name="seasons">
        /// An <see cref="PostSeasons" /> instance, containing season and episode numbers.<para />
        /// If it contains episode numbers, only the episodes with the given episode numbers will be added to the watchlist.
        /// </param>
        /// <returns>The current <see cref="TraktSyncWatchlistPostBuilder" /> instance.</returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown, if the given show is null.
        /// Thrown, if the given show ids are null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Thrown, if the given show has no valid ids set.
        /// Thrown, if the given show has an year set, which has more or less than four digits.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Thrown, if at least one of the given season numbers in <paramref name="seasons" /> is below zero.
        /// Thrown, if at least one of the given episode numbers in <paramref name="seasons" /> is below zero.
        /// </exception>
        public TraktSyncWatchlistPostBuilder AddShow(TraktShow show, PostSeasons seasons)
        {
            ValidateShow(show);
            EnsureShowsListExists();

            if (_watchlistPost.Shows == null)
            {
                _watchlistPost.Shows = new List <TraktSyncWatchlistPostShow>();
            }

            List <TraktSyncWatchlistPostShowSeason> showSeasons = null;

            if (seasons.Count() > 0)
            {
                showSeasons = new List <TraktSyncWatchlistPostShowSeason>();

                foreach (var season in seasons)
                {
                    if (season.Number < 0)
                    {
                        throw new ArgumentOutOfRangeException("at least one season number not valid", nameof(season));
                    }

                    var showSingleSeason = new TraktSyncWatchlistPostShowSeason {
                        Number = season.Number
                    };

                    if (season.Episodes != null && season.Episodes.Count() > 0)
                    {
                        var showEpisodes = new List <TraktSyncWatchlistPostShowEpisode>();

                        foreach (var episode in season.Episodes)
                        {
                            if (episode < 0)
                            {
                                throw new ArgumentOutOfRangeException("at least one episode number not valid", nameof(seasons));
                            }

                            showEpisodes.Add(new TraktSyncWatchlistPostShowEpisode {
                                Number = episode
                            });
                        }

                        showSingleSeason.Episodes = showEpisodes;
                    }

                    showSeasons.Add(showSingleSeason);
                }
            }

            var existingShow = _watchlistPost.Shows.Where(s => s.Ids == show.Ids).FirstOrDefault();

            if (existingShow != null)
            {
                existingShow.Seasons = showSeasons;
            }
            else
            {
                var watchlistShow = new TraktSyncWatchlistPostShow();
                watchlistShow.Ids   = show.Ids;
                watchlistShow.Title = show.Title;
                watchlistShow.Year  = show.Year;

                watchlistShow.Seasons = showSeasons;
                (_watchlistPost.Shows as List <TraktSyncWatchlistPostShow>).Add(watchlistShow);
            }

            return(this);
        }