Exemplo n.º 1
0
        protected IEnumerable <TraktSyncHistoryPostShowSeason> CreateShowSeasons(PostHistorySeasons seasons)
        {
            var showSeasons = new List <TraktSyncHistoryPostShowSeason>();

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

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

                if (season.WatchedAt.HasValue)
                {
                    showSingleSeason.WatchedAt = season.WatchedAt.Value.ToUniversalTime();
                }

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

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

                        var showEpisode = new TraktSyncHistoryPostShowEpisode {
                            Number = episode.Number
                        };

                        if (episode.WatchedAt.HasValue)
                        {
                            showEpisode.WatchedAt = episode.WatchedAt.Value.ToUniversalTime();
                        }

                        showEpisodes.Add(showEpisode);
                    }

                    showSingleSeason.Episodes = showEpisodes;
                }

                showSeasons.Add(showSingleSeason);
            }

            return(showSeasons);
        }
Exemplo n.º 2
0
        /// <summary>Adds a <see cref="TraktShow" />, which will be added to the history post.</summary>
        /// <param name="show">The Trakt show, which will be added.</param>
        /// <param name="seasons">
        /// An <see cref="PostHistorySeasons" /> 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 history.
        /// </param>
        /// <returns>The current <see cref="TraktSyncHistoryPostBuilder" /> 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 TraktSyncHistoryPostBuilder AddShow(TraktShow show, PostHistorySeasons seasons)
        {
            ValidateShow(show);

            if (seasons == null)
            {
                throw new ArgumentNullException(nameof(seasons));
            }

            EnsureShowsListExists();

            var showSeasons = CreateShowSeasons(seasons);

            CreateOrSetShow(show, showSeasons);

            return(this);
        }
        protected IEnumerable <ITraktSyncHistoryPostShowSeason> CreateShowSeasons(PostHistorySeasons seasons)
        {
            var showSeasons = new List <ITraktSyncHistoryPostShowSeason>();

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

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

                if (season.Episodes?.Count() > 0)
                {
                    var showEpisodes = new List <ITraktSyncHistoryPostShowEpisode>();

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

                        var showEpisode = new TraktSyncHistoryPostShowEpisode {
                            Number = episode.Number
                        };

                        showEpisodes.Add(showEpisode);
                    }

                    showSingleSeason.Episodes = showEpisodes;
                }

                showSeasons.Add(showSingleSeason);
            }

            return(showSeasons);
        }
        public void Test_TraktPost_SyncHistoryPostBuilder_AddShowAndSeasonsCollection()
        {
            ITraktShow show = new TraktShow
            {
                Title = "show title",
                Year  = 2020,
                Ids   = new TraktShowIds
                {
                    Trakt  = 1,
                    Slug   = "show-title",
                    Imdb   = "ttshowtitle",
                    Tmdb   = 1,
                    Tvdb   = 1,
                    TvRage = 1
                }
            };

            var seasons = new PostHistorySeasons
            {
                1,
                { 2, new PostHistoryEpisodes {
                      1, 2
                  } }
            };

            ITraktSyncHistoryPost syncHistoryPost = TraktPost.NewSyncHistoryPost()
                                                    .AddShowAndSeasonsCollection(show).WithSeasons(seasons)
                                                    .Build();

            syncHistoryPost.Should().NotBeNull();
            syncHistoryPost.Shows.Should().NotBeNull().And.HaveCount(1);

            ITraktSyncHistoryPostShow postShow = syncHistoryPost.Shows.ToArray()[0];

            postShow.Title = "show title";
            postShow.Year  = 2020;
            postShow.Ids.Should().NotBeNull();
            postShow.Ids.Trakt.Should().Be(1U);
            postShow.Ids.Slug.Should().Be("show-title");
            postShow.Ids.Imdb.Should().Be("ttshowtitle");
            postShow.Ids.Tmdb.Should().Be(1U);
            postShow.Ids.Tvdb.Should().Be(1U);
            postShow.Ids.TvRage.Should().Be(1U);
            postShow.WatchedAt.Should().BeNull();
            postShow.Seasons.Should().NotBeNull().And.HaveCount(2);

            ITraktSyncHistoryPostShowSeason[] showSeasons = postShow.Seasons.ToArray();

            showSeasons[0].Number.Should().Be(1);
            showSeasons[0].Episodes.Should().BeNull();

            showSeasons[1].Number.Should().Be(2);
            showSeasons[1].Episodes.Should().NotBeNull().And.HaveCount(2);

            ITraktSyncHistoryPostShowEpisode[] showSeasonEpisodes = showSeasons[1].Episodes.ToArray();

            showSeasonEpisodes[0].Number.Should().Be(1);
            showSeasonEpisodes[1].Number.Should().Be(2);

            syncHistoryPost.Movies.Should().NotBeNull().And.BeEmpty();
            syncHistoryPost.Episodes.Should().NotBeNull().And.BeEmpty();
        }
        private IEnumerable <ITraktSyncHistoryPostShowSeason> CreateSyncHistoryPostShowSeasons(PostHistorySeasons seasons)
        {
            var syncHistoryPostShowSeasons = new List <ITraktSyncHistoryPostShowSeason>();

            foreach (PostHistorySeason season in seasons)
            {
                var syncHistoryPostShowSeason = new TraktSyncHistoryPostShowSeason
                {
                    Number = season.Number
                };

                if (season.WatchedAt.HasValue)
                {
                    syncHistoryPostShowSeason.WatchedAt = season.WatchedAt.Value.ToUniversalTime();
                }

                if (season.Episodes?.Count() > 0)
                {
                    var syncHistoryPostShowEpisodes = new List <ITraktSyncHistoryPostShowEpisode>();

                    foreach (PostHistoryEpisode episode in season.Episodes)
                    {
                        var syncHistoryPostShowEpisode = new TraktSyncHistoryPostShowEpisode
                        {
                            Number = episode.Number
                        };

                        if (episode.WatchedAt.HasValue)
                        {
                            syncHistoryPostShowEpisode.WatchedAt = episode.WatchedAt.Value.ToUniversalTime();
                        }

                        syncHistoryPostShowEpisodes.Add(syncHistoryPostShowEpisode);
                    }

                    syncHistoryPostShowSeason.Episodes = syncHistoryPostShowEpisodes;
                }

                syncHistoryPostShowSeasons.Add(syncHistoryPostShowSeason);
            }

            return(syncHistoryPostShowSeasons);
        }
        private ITraktSyncHistoryPostShow CreateSyncHistoryPostShowWithSeasonsCollection(ITraktShow show, DateTime?watchedAt = null, PostHistorySeasons seasons = null)
        {
            var syncHistoryPostShow = CreateSyncHistoryPostShow(show, watchedAt);

            if (seasons != null)
            {
                syncHistoryPostShow.Seasons = CreateSyncHistoryPostShowSeasons(seasons);
            }

            return(syncHistoryPostShow);
        }
 /// <summary>Adds a <see cref="TraktShow" />, which will be added to the history post.</summary>
 /// <param name="show">The Trakt show, which will be added.</param>
 /// <param name="seasons">
 /// An <see cref="PostHistorySeasons" /> 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 history.
 /// </param>
 /// <returns>The current <see cref="TraktSyncHistoryPostBuilder" /> 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 new TraktSyncHistoryPostBuilder AddShow(TraktShow show, PostHistorySeasons seasons)
 {
     base.AddShow(show, seasons);
     return(this);
 }