コード例 #1
0
        /// <summary>
        /// gets the activity for the currently logged in user from 
        /// the local cache
        /// </summary>
        private TraktActivity GetMyActivityFromCache()
        {
            int i = 0;
            int maxActivityItems = TraktSkinSettings.DashboardActivityFacadeMaxItems;
            TraktActivity activity = new TraktActivity();

            // create activities from cached data
            activity.Timestamps = new TraktActivity.TraktTimestamps { Current = DateTime.UtcNow.ToEpoch() };
            activity.Activities = new List<TraktActivity.Activity>();

            TraktLogger.Debug("Getting current user cached activity");

            #region watched episodes
            if (TraktSettings.DashboardActivityFilter.Types.Episodes && TraktSettings.DashboardActivityFilter.Actions.Watched)
            {
                var watchedEpisodes = TraktCache.GetWatchedEpisodesFromTrakt(true);
                if (watchedEpisodes != null)
                {
                    foreach (var episode in watchedEpisodes.OrderByDescending(e => e.WatchedAt).Take(maxActivityItems))
                    {
                        var watchedEpActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.scrobble.ToString(),
                            Type = ActivityType.episode.ToString(),
                            Episode = new TraktEpisodeSummary
                            {
                                Ids = new TraktEpisodeId(),
                                Number = episode.Number,
                                Season = episode.Season
                            },
                            Show = new TraktShowSummary
                            {
                                Title = episode.ShowTitle,
                                Year = episode.ShowYear,
                                Ids = new TraktShowId
                                {
                                    Imdb = episode.ShowImdbId,
                                    Trakt = episode.ShowId,
                                    Tvdb = episode.ShowTvdbId
                                },
                            },
                            Timestamp = episode.WatchedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(watchedEpActivity);
                    }
                }
            }
            #endregion

            #region watched movies
            if (TraktSettings.DashboardActivityFilter.Types.Movies && TraktSettings.DashboardActivityFilter.Actions.Watched)
            {
                var watchedMovies = TraktCache.GetWatchedMoviesFromTrakt(true);
                if (watchedMovies != null)
                {
                    foreach (var movie in watchedMovies.OrderByDescending(m => m.LastWatchedAt).Take(maxActivityItems))
                    {
                        var watchedEpActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.scrobble.ToString(),
                            Type = ActivityType.movie.ToString(),
                            Movie = new TraktMovieSummary
                            {
                                Ids = movie.Movie.Ids,
                                Title = movie.Movie.Title,
                                Year = movie.Movie.Year
                            },
                            Timestamp = movie.LastWatchedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(watchedEpActivity);
                    }
                }
            }
            #endregion

            #region collected episodes
            if (TraktSettings.DashboardActivityFilter.Types.Episodes && TraktSettings.DashboardActivityFilter.Actions.Collected)
            {
                var collectedEpisodes = TraktCache.GetCollectedEpisodesFromTrakt(true);
                if (collectedEpisodes != null)
                {
                    foreach (var episode in collectedEpisodes.OrderByDescending(e => e.CollectedAt).Take(maxActivityItems))
                    {
                        var collectedEpActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.collection.ToString(),
                            Type = ActivityType.episode.ToString(),
                            Episodes = new List<TraktEpisodeSummary>
                            {
                                new TraktEpisodeSummary
                                {
                                    Ids = new TraktEpisodeId(),
                                    Number = episode.Number,
                                    Season = episode.Season
                                }
                            },
                            Show = new TraktShowSummary
                            {
                                Title = episode.ShowTitle,
                                Year = episode.ShowYear,
                                Ids = new TraktShowId
                                {
                                    Imdb = episode.ShowImdbId,
                                    Trakt = episode.ShowId,
                                    Tvdb = episode.ShowTvdbId
                                },
                            },
                            Timestamp = episode.CollectedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(collectedEpActivity);
                    }
                }
            }
            #endregion

            #region collected movies
            if (TraktSettings.DashboardActivityFilter.Types.Movies && TraktSettings.DashboardActivityFilter.Actions.Collected)
            {
                var collectedMovies = TraktCache.GetCollectedMoviesFromTrakt(true);
                if (collectedMovies != null)
                {
                    foreach (var movie in collectedMovies.OrderByDescending(m => m.CollectedAt).Take(maxActivityItems))
                    {
                        var collectedEpActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.collection.ToString(),
                            Type = ActivityType.movie.ToString(),
                            Movie = new TraktMovieSummary
                            {
                                Ids = movie.Movie.Ids,
                                Title = movie.Movie.Title,
                                Year = movie.Movie.Year
                            },
                            Timestamp = movie.CollectedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(collectedEpActivity);
                    }
                }
            }
            #endregion

            #region watchlisted episodes
            if (TraktSettings.DashboardActivityFilter.Types.Episodes && TraktSettings.DashboardActivityFilter.Actions.Watchlisted)
            {
                var watchlistedEpisodes = TraktCache.GetWatchlistedEpisodesFromTrakt(true);
                if (watchlistedEpisodes != null)
                {
                    foreach (var episode in watchlistedEpisodes.OrderByDescending(e => e.ListedAt).Take(maxActivityItems))
                    {
                        var watchlistedEpActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.watchlist.ToString(),
                            Type = ActivityType.episode.ToString(),
                            Episode = new TraktEpisodeSummary
                            {
                                Ids = episode.Episode.Ids,
                                Number = episode.Episode.Number,
                                Season = episode.Episode.Season,
                                Title = episode.Episode.Title
                            },
                            Show = new TraktShowSummary
                            {
                                Title = episode.Show.Title,
                                Year = episode.Show.Year,
                                Ids = episode.Show.Ids
                            },
                            Timestamp = episode.ListedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(watchlistedEpActivity);
                    }
                }
            }
            #endregion

            #region watchlisted shows
            if (TraktSettings.DashboardActivityFilter.Types.Shows && TraktSettings.DashboardActivityFilter.Actions.Watchlisted)
            {
                var watchlistedShows = TraktCache.GetWatchlistedShowsFromTrakt(true);
                if (watchlistedShows != null)
                {
                    foreach (var show in watchlistedShows.OrderByDescending(e => e.ListedAt).Take(maxActivityItems))
                    {
                        var watchlistedShowActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.watchlist.ToString(),
                            Type = ActivityType.show.ToString(),
                            Show = new TraktShowSummary
                            {
                                Title = show.Show.Title,
                                Year = show.Show.Year,
                                Ids = show.Show.Ids
                            },
                            Timestamp = show.ListedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(watchlistedShowActivity);
                    }
                }
            }
            #endregion

            #region watchlisted seasons
            if (TraktSettings.DashboardActivityFilter.Types.Seasons && TraktSettings.DashboardActivityFilter.Actions.Watchlisted)
            {
                var watchlistedSeasons = TraktCache.GetWatchlistedSeasonsFromTrakt(true);
                if (watchlistedSeasons != null)
                {
                    foreach (var item in watchlistedSeasons.OrderByDescending(e => e.ListedAt).Take(maxActivityItems))
                    {
                        var watchlistedSeasonActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.watchlist.ToString(),
                            Type = ActivityType.season.ToString(),
                            Show = new TraktShowSummary
                            {
                                Title = item.Show.Title,
                                Year = item.Show.Year,
                                Ids = item.Show.Ids
                            },
                            Season = new TraktSeasonSummary
                            {
                                Ids = item.Season.Ids,
                                Number = item.Season.Number
                            },
                            Timestamp = item.ListedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(watchlistedSeasonActivity);
                    }
                }
            }
            #endregion

            #region watchlisted movies
            if (TraktSettings.DashboardActivityFilter.Types.Movies && TraktSettings.DashboardActivityFilter.Actions.Watchlisted)
            {
                var watchlistedMovies = TraktCache.GetWatchlistedMoviesFromTrakt(true);
                if (watchlistedMovies != null)
                {
                    foreach (var movie in watchlistedMovies.OrderByDescending(e => e.ListedAt).Take(maxActivityItems))
                    {
                        var watchlistedMovieActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.watchlist.ToString(),
                            Type = ActivityType.movie.ToString(),
                            Movie = new TraktMovieSummary
                            {
                                Ids = movie.Movie.Ids,
                                Title = movie.Movie.Title,
                                Year = movie.Movie.Year
                            },
                            Timestamp = movie.ListedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(watchlistedMovieActivity);
                    }
                }
            }
            #endregion

            #region rated episodes
            if (TraktSettings.DashboardActivityFilter.Types.Episodes && TraktSettings.DashboardActivityFilter.Actions.Rated)
            {
                var ratedEpisodes = TraktCache.GetRatedEpisodesFromTrakt(true);
                if (ratedEpisodes != null)
                {
                    foreach (var episode in ratedEpisodes.OrderByDescending(e => e.RatedAt).Take(maxActivityItems))
                    {
                        var ratedEpActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.rating.ToString(),
                            Type = ActivityType.episode.ToString(),
                            Episode = new TraktEpisodeSummary
                            {
                                Ids = episode.Episode.Ids,
                                Number = episode.Episode.Number,
                                Season = episode.Episode.Season,
                                Title = episode.Episode.Title
                            },
                            Show = new TraktShowSummary
                            {
                                Title = episode.Show.Title,
                                Year = episode.Show.Year,
                                Ids = episode.Show.Ids
                            },
                            Rating = episode.Rating,
                            Timestamp = episode.RatedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(ratedEpActivity);
                    }
                }
            }
            #endregion

            #region rated seasons
            if (TraktSettings.DashboardActivityFilter.Types.Seasons && TraktSettings.DashboardActivityFilter.Actions.Rated)
            {
                var ratedSeasons = TraktCache.GetRatedSeasonsFromTrakt(true);
                if (ratedSeasons != null)
                {
                    foreach (var season in ratedSeasons.OrderByDescending(e => e.RatedAt).Take(maxActivityItems))
                    {
                        var ratedShowActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.rating.ToString(),
                            Type = ActivityType.season.ToString(),
                            Show = new TraktShowSummary
                            {
                                Title = season.Show.Title,
                                Year = season.Show.Year,
                                Ids = season.Show.Ids
                            },
                            Season = new TraktSeasonSummary
                            {
                                Ids = season.Season.Ids ?? new TraktSeasonId(),
                                Number = season.Season.Number
                            },
                            Rating = season.Rating,
                            Timestamp = season.RatedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(ratedShowActivity);
                    }
                }
            }
            #endregion

            #region rated shows
            if (TraktSettings.DashboardActivityFilter.Types.Shows && TraktSettings.DashboardActivityFilter.Actions.Rated)
            {
                var ratedShows = TraktCache.GetRatedShowsFromTrakt(true);
                if (ratedShows != null)
                {
                    foreach (var show in ratedShows.OrderByDescending(e => e.RatedAt).Take(maxActivityItems))
                    {
                        var ratedShowActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.rating.ToString(),
                            Type = ActivityType.show.ToString(),
                            Show = new TraktShowSummary
                            {
                                Title = show.Show.Title,
                                Year = show.Show.Year,
                                Ids = show.Show.Ids
                            },
                            Rating = show.Rating,
                            Timestamp = show.RatedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(ratedShowActivity);
                    }
                }
            }
            #endregion

            #region rated movies
            if (TraktSettings.DashboardActivityFilter.Types.Movies && TraktSettings.DashboardActivityFilter.Actions.Rated)
            {
                var ratedMovies = TraktCache.GetRatedMoviesFromTrakt(true);
                if (ratedMovies != null)
                {
                    foreach (var movie in ratedMovies.OrderByDescending(e => e.RatedAt).Take(maxActivityItems))
                    {
                        var ratedMovieActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.rating.ToString(),
                            Type = ActivityType.movie.ToString(),
                            Movie = new TraktMovieSummary
                            {
                                Ids = movie.Movie.Ids,
                                Title = movie.Movie.Title,
                                Year = movie.Movie.Year
                            },
                            Rating = movie.Rating,
                            Timestamp = movie.RatedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(ratedMovieActivity);
                    }
                }
            }
            #endregion

            #region lists
            if (TraktSettings.DashboardActivityFilter.Types.Lists)
            {
                var lists = TraktCache.GetCustomLists(true);
                if (lists != null)
                {
                    foreach (var list in lists.OrderByDescending(l => l.Key.UpdatedAt).Take(maxActivityItems))
                    {
                        var userList = list.Key;

                        if (TraktSettings.DashboardActivityFilter.Actions.Updated)
                        {
                            var listActivity = new TraktActivity.Activity
                            {
                                Id = i++,
                                Action = ActivityAction.updated.ToString(),
                                Type = ActivityType.list.ToString(),
                                List = userList,
                                Timestamp = list.Key.UpdatedAt,
                                User = GetUserProfile()
                            };

                            // add activity to the list
                            activity.Activities.Add(listActivity);
                        }

                        if (TraktSettings.DashboardActivityFilter.Actions.Added)
                        {
                            foreach (var listItem in list.Value.OrderByDescending(l => l.ListedAt).Take(maxActivityItems))
                            {
                                var listItemActivity = new TraktActivity.Activity
                                {
                                    Id = i++,
                                    Action = ActivityAction.item_added.ToString(),
                                    Type = listItem.Type,
                                    Timestamp = listItem.ListedAt,
                                    List = userList,
                                    Movie = listItem.Movie,
                                    Show = listItem.Show,
                                    Episode = listItem.Episode,
                                    Season = listItem.Season,
                                    Person = listItem.Person,
                                    User = GetUserProfile()
                                };

                                // add activity to the list
                                activity.Activities.Add(listItemActivity);
                            }
                        }
                    }
                }
            }
            #endregion

            #region commented episodes
            if (TraktSettings.DashboardActivityFilter.Types.Episodes && TraktSettings.DashboardActivityFilter.Actions.Commented)
            {
                var commentedEpisodes = TraktCache.GetCommentedEpisodesFromTrakt(true);
                if (commentedEpisodes != null)
                {
                    foreach (var comment in commentedEpisodes.OrderByDescending(c => c.Comment.CreatedAt).Take(maxActivityItems))
                    {
                        var commentedEpisodeActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = comment.Comment.IsReview ? ActivityAction.review.ToString() : ActivityAction.shout.ToString(),
                            Type = comment.Type,
                            Show = new TraktShowSummary
                            {
                                Ids = comment.Show.Ids,
                                Title = comment.Show.Title,
                                Year = comment.Show.Year
                            },
                            Episode = new TraktEpisodeSummary
                            {
                                Ids = comment.Episode.Ids,
                                Number = comment.Episode.Number,
                                Season = comment.Episode.Season,
                                Title = comment.Episode.Title
                            },
                            Shout = comment.Comment,
                            Timestamp = comment.Comment.CreatedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(commentedEpisodeActivity);
                    }
                }
            }
            #endregion

            #region commented seasons
            if (TraktSettings.DashboardActivityFilter.Types.Seasons && TraktSettings.DashboardActivityFilter.Actions.Commented)
            {
                var commentedSeasons = TraktCache.GetCommentedSeasonsFromTrakt(true);
                if (commentedSeasons != null)
                {
                    foreach (var comment in commentedSeasons.OrderByDescending(c => c.Comment.CreatedAt).Take(maxActivityItems))
                    {
                        var commentedSeasonActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = comment.Comment.IsReview ? ActivityAction.review.ToString() : ActivityAction.shout.ToString(),
                            Type = comment.Type,
                            Show = new TraktShowSummary
                            {
                                Ids = comment.Show.Ids,
                                Title = comment.Show.Title,
                                Year = comment.Show.Year
                            },
                            Season = new TraktSeasonSummary
                            {
                                Ids = comment.Season.Ids,
                                Number = comment.Season.Number
                            },
                            Shout = comment.Comment,
                            Timestamp = comment.Comment.CreatedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(commentedSeasonActivity);
                    }
                }
            }
            #endregion

            #region commented shows
            if (TraktSettings.DashboardActivityFilter.Types.Shows && TraktSettings.DashboardActivityFilter.Actions.Commented)
            {
                var commentedShows = TraktCache.GetCommentedShowsFromTrakt(true);
                if (commentedShows != null)
                {
                    foreach (var comment in commentedShows.OrderByDescending(c => c.Comment.CreatedAt).Take(maxActivityItems))
                    {
                        var commentedShowActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = comment.Comment.IsReview ? ActivityAction.review.ToString() : ActivityAction.shout.ToString(),
                            Type = comment.Type,
                            Show = new TraktShowSummary
                            {
                                Ids = comment.Show.Ids,
                                Title = comment.Show.Title,
                                Year = comment.Show.Year
                            },
                            Shout = comment.Comment,
                            Timestamp = comment.Comment.CreatedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(commentedShowActivity);
                    }
                }
            }
            #endregion

            #region commented movies
            if (TraktSettings.DashboardActivityFilter.Types.Movies && TraktSettings.DashboardActivityFilter.Actions.Commented)
            {
                var commentedMovies = TraktCache.GetCommentedMoviesFromTrakt(true);
                if (commentedMovies != null)
                {
                    foreach (var comment in commentedMovies.OrderByDescending(c => c.Comment.CreatedAt).Take(maxActivityItems))
                    {
                        var commentedMovieActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = comment.Comment.IsReview ? ActivityAction.review.ToString() : ActivityAction.shout.ToString(),
                            Type = comment.Type,
                            Movie = new TraktMovieSummary
                            {
                                Ids = comment.Movie.Ids,
                                Title = comment.Movie.Title,
                                Year = comment.Movie.Year
                            },
                            Shout = comment.Comment,
                            Timestamp = comment.Comment.CreatedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(commentedMovieActivity);
                    }
                }
            }
            #endregion

            #region commented lists
            if (TraktSettings.DashboardActivityFilter.Types.Lists && TraktSettings.DashboardActivityFilter.Actions.Commented)
            {
                var commentedLists = TraktCache.GetCommentedMoviesFromTrakt(true);
                if (commentedLists != null)
                {
                    foreach (var comment in commentedLists.OrderByDescending(c => c.Comment.CreatedAt).Take(maxActivityItems))
                    {
                        var commentedListActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = comment.Comment.IsReview ? ActivityAction.review.ToString() : ActivityAction.shout.ToString(),
                            Type = comment.Type,
                            List = comment.List,
                            Shout = comment.Comment,
                            Timestamp = comment.Comment.CreatedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(commentedListActivity);
                    }
                }
            }
            #endregion

            #region paused episodes
            if (TraktSettings.DashboardActivityFilter.Types.Episodes && TraktSettings.DashboardActivityFilter.Actions.Paused)
            {
                string lastEpisodeProcessedAt;
                var pausedEpisodes = TraktCache.GetPausedEpisodes(out lastEpisodeProcessedAt, true);
                if (pausedEpisodes != null)
                {
                    foreach (var pause in pausedEpisodes.OrderByDescending(e => e.PausedAt).Take(maxActivityItems))
                    {
                        var pausedEpisodeActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.pause.ToString(),
                            Type = ActivityType.episode.ToString(),
                            Show = new TraktShowSummary
                            {
                                Title = pause.Show.Title,
                                Year = pause.Show.Year,
                                Ids = pause.Show.Ids
                            },
                            Episode = new TraktEpisodeSummary
                            {
                                Ids = pause.Episode.Ids,
                                Number = pause.Episode.Number,
                                Season = pause.Episode.Season,
                                Title = pause.Episode.Title
                            },
                            Progress = pause.Progress,
                            Timestamp = pause.PausedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(pausedEpisodeActivity);
                    }
                }
            }
            #endregion

            #region paused movies
            if (TraktSettings.DashboardActivityFilter.Types.Movies && TraktSettings.DashboardActivityFilter.Actions.Paused)
            {
                string lastMovieProcessedAt;
                var pausedMovies = TraktCache.GetPausedMovies(out lastMovieProcessedAt, true);
                if (pausedMovies != null)
                {
                    foreach (var pause in pausedMovies.OrderByDescending(e => e.PausedAt).Take(maxActivityItems))
                    {
                        var pausedMovieActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.pause.ToString(),
                            Type = ActivityType.movie.ToString(),
                            Movie = new TraktMovieSummary
                            {
                                Ids = pause.Movie.Ids,
                                Title = pause.Movie.Title,
                                Year = pause.Movie.Year
                            },
                            Progress = pause.Progress,
                            Timestamp = pause.PausedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(pausedMovieActivity);
                    }
                }
            }
            #endregion

            #region liked comments
            if (TraktSettings.DashboardActivityFilter.Types.Comments && TraktSettings.DashboardActivityFilter.Actions.Liked)
            {
                var likedComments = TraktCache.GetLikedCommentsFromTrakt(true);
                if (likedComments != null)
                {
                    foreach (var like in likedComments.OrderByDescending(c => c.LikedAt).Take(maxActivityItems))
                    {
                        var likedCommentActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.like.ToString(),
                            Type = ActivityType.comment.ToString(),
                            Shout = like.Comment,
                            Timestamp = like.LikedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(likedCommentActivity);
                    }
                }
            }
            #endregion

            #region liked lists
            if (TraktSettings.DashboardActivityFilter.Types.Lists && TraktSettings.DashboardActivityFilter.Actions.Liked)
            {
                var likedLists = TraktCache.GetLikedListsFromTrakt(true);
                if (likedLists != null)
                {
                    foreach (var like in likedLists.OrderByDescending(c => c.LikedAt).Take(maxActivityItems))
                    {
                        var likedListActivity = new TraktActivity.Activity
                        {
                            Id = i++,
                            Action = ActivityAction.like.ToString(),
                            Type = ActivityType.list.ToString(),
                            List = like.List,
                            Timestamp = like.LikedAt,
                            User = GetUserProfile()
                        };

                        // add activity to the list
                        activity.Activities.Add(likedListActivity);
                    }
                }
            }
            #endregion

            TraktLogger.Debug("Finished getting users cached activity");

            // sort by time inserted into library
            activity.Activities = activity.Activities.OrderByDescending(a => a.Timestamp).Take(TraktSkinSettings.DashboardActivityFacadeMaxItems).ToList();

            return activity;
        }
コード例 #2
0
        private void OnActivitySelected(GUIListItem item, GUIControl parent)
        {
            TraktActivity.Activity activity = item.TVTag as TraktActivity.Activity;
            if (activity == null || string.IsNullOrEmpty(activity.Action) || string.IsNullOrEmpty(activity.Type))
            {
                ClearSelectedActivityProperties();
                return;
            }

            // remember last selected item
            PreviousSelectedActivity = activity;

            // set type and action properties
            GUIUtils.SetProperty("#Trakt.Selected.Activity.Type", activity.Type);
            GUIUtils.SetProperty("#Trakt.Selected.Activity.Action", activity.Action);

            GUICommon.SetUserProperties(activity.User);

            ActivityAction action = (ActivityAction)Enum.Parse(typeof(ActivityAction), activity.Action);
            ActivityType type = (ActivityType)Enum.Parse(typeof(ActivityType), activity.Type);

            switch (type)
            {
                case ActivityType.episode:
                    if (action == ActivityAction.seen || action == ActivityAction.collection)
                    {
                        if (activity.Episodes.Count > 1)
                        {
                            GUICommon.SetEpisodeProperties(activity.Show, activity.Episodes.First());
                        }
                        else
                        {
                            GUICommon.SetEpisodeProperties(activity.Show, activity.Episode);
                        }
                    }
                    else
                    {
                        GUICommon.SetEpisodeProperties(activity.Show, activity.Episode);
                    }
                    GUICommon.SetShowProperties(activity.Show);
                    break;

                case ActivityType.show:
                    GUICommon.SetShowProperties(activity.Show);
                    break;

                case ActivityType.season:
                    GUICommon.SetShowProperties(activity.Show);
                    GUICommon.SetSeasonProperties(activity.Show, activity.Season);
                    break;

                case ActivityType.movie:
                    GUICommon.SetMovieProperties(activity.Movie);
                    break;

                case ActivityType.list:
                    if (action == ActivityAction.item_added)
                    {
                        // return the name of the item added to the list
                        switch (activity.ListItem.Type)
                        {
                            case "show":
                                GUICommon.SetShowProperties(activity.ListItem.Show);
                                break;

                            case "season":
                                GUICommon.SetShowProperties(activity.ListItem.Show);
                                GUICommon.SetSeasonProperties(activity.ListItem.Show, activity.ListItem.Season);
                                break;

                            case "episode":
                                GUICommon.SetShowProperties(activity.ListItem.Show);
                                GUICommon.SetEpisodeProperties(activity.ListItem.Show, activity.ListItem.Episode);
                                break;

                            case "movie":
                                GUICommon.SetMovieProperties(activity.ListItem.Movie);
                                break;
                        }
                    }
                    break;

                case ActivityType.comment:
                    GUICommon.SetCommentProperties(activity.Shout, false);
                    break;
            }
        }