示例#1
0
        private void OrderHistory(TraktActivity activity, ActivityListItemViewModel tempModel)
        {
            if (sortedOrderHistory == null)
            {
                sortedOrderHistory = new Dictionary <DateTime, List <ActivityListItemViewModel> >();
            }


            DateTime time = new DateTime(1970, 1, 1, 0, 0, 9, DateTimeKind.Utc);

            time = time.AddSeconds(activity.TimeStamp);
            time = time.ToLocalTime();
            DateTime onlyDay = new DateTime(time.Year, time.Month, time.Day);

            tempModel.Date = onlyDay;

            if (sortedOrderHistory.ContainsKey(onlyDay))
            {
                sortedOrderHistory[onlyDay].Add(tempModel);
            }
            else
            {
                List <ActivityListItemViewModel> tempList = new List <ActivityListItemViewModel>();
                tempList.Add(tempModel);
                sortedOrderHistory.Add(onlyDay, tempList);
            }
        }
示例#2
0
        private ActivityListItemViewModel Checkin(TraktActivity activity)
        {
            switch (activity.Type)
            {
            case "movie":
                return(new ActivityListItemViewModel()
                {
                    Activity = ((activity.User.Username.Equals(AppUser.Instance.UserName)) ? "You " : activity.User.Username + " ") + "checked in " + activity.Movie.Title, Name = activity.Movie.Title, TimeStamp = activity.TimeStamp, Imdb = activity.Movie.imdb_id, Screen = activity.Movie.Images.Poster, Type = "movie", Year = activity.Movie.year
                });

            case "show":
                return(new ActivityListItemViewModel()
                {
                    Activity = ((activity.User.Username.Equals(AppUser.Instance.UserName)) ? "You " : activity.User.Username + " ") + "checked in " + activity.Show.Title + ".", Name = activity.Show.Title, TimeStamp = activity.TimeStamp, Tvdb = activity.Show.tvdb_id, Imdb = activity.Show.imdb_id, Screen = activity.Show.Images.Poster, Type = "show", Year = activity.Show.year
                });

            case "episode":
                return(new ActivityListItemViewModel()
                {
                    Activity = ((activity.User.Username.Equals(AppUser.Instance.UserName)) ? "You " : activity.User.Username + " ") + "checked in " + activity.Show.Title + " - " + activity.Episode.Title + " ( " + activity.Episode.Season + "x" + activity.Episode.Number + " ) " + ".", Name = activity.Show.Title, TimeStamp = activity.TimeStamp, Imdb = activity.Show.imdb_id, Tvdb = activity.Show.tvdb_id, Screen = activity.Episode.Images.Screen, Type = "episode", Season = Int16.Parse(activity.Episode.Season), Episode = Int16.Parse(activity.Episode.Number), Year = activity.Show.year
                });
            }

            return(null);
        }
示例#3
0
        protected ActivityListItemViewModel DetermineActivity(TraktActivity activity, ActivityListItemViewModel tempModel)
        {
            switch (activity.Action)
            {
            case "watchlist":
                tempModel = AddToWatchList(activity);
                break;

            case "rating":
                tempModel = Rated(activity);
                break;

            case "checkin":
                tempModel = Checkin(activity);
                break;

            case "scrobble":
                tempModel = Scrobble(activity);
                break;

            case "shout":
                tempModel = Shout(activity);
                break;
            }

            return(tempModel);
        }
示例#4
0
        public void RefreshTraktActivity()
        {
            try
            {
                System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action) delegate()
                {
                    TraktActivity.Clear();
                    TraktShouts.Clear();
                });

                JMMServerBinary.Contract_Trakt_Activity traktActivity = JMMServerVM.Instance.clientBinaryHTTP.GetTraktFriendInfo(20,
                                                                                                                                 false, true, false);

                if (traktActivity.HasTraktAccount)
                {
                    string blankImageName = @"/Images/blankposter.png";
                    if (AppSettings.DashMetroImageType == DashboardMetroImageType.Fanart)
                    {
                        blankImageName = @"/Images/blankfanart.png";
                    }

                    int numItems = 0;

                    // first get all the shouts
                    foreach (JMMServerBinary.Contract_Trakt_FriendActivity contractAct in traktActivity.TraktFriendActivity)
                    {
                        if (contractAct.ActivityAction == (int)TraktActivityAction.Shout)
                        {
                            if (contractAct.ActivityType == (int)TraktActivityType.Episode)
                            {
                                Trakt_ActivityShoutEpisodeVM shoutEp = new Trakt_ActivityShoutEpisodeVM(contractAct);

                                TraktShoutTile tile = new TraktShoutTile()
                                {
                                    ShowName            = shoutEp.Shout.ShowTitle,
                                    ShowPicture         = blankImageName,
                                    Details             = shoutEp.Shout.EpisodeDescription + Environment.NewLine + shoutEp.Shout.Text,
                                    ShoutDateString     = shoutEp.ActivityDateString,
                                    FriendName          = shoutEp.User.Username,
                                    FriendPicture       = blankImageName,
                                    OnlineShowPicture   = shoutEp.Shout.OnlineImagePath,
                                    OnlineFriendPicture = shoutEp.User.Avatar,
                                    URL      = shoutEp.Shout.Episode_Url,
                                    TileSize = "Large",
                                    Height   = 100
                                };

                                TraktShouts.Add(tile);
                                imagesToDownload.Add(tile);
                                numItems = 1;
                            }
                            else
                            {
                                Trakt_ActivityShoutShowVM shoutShow = new Trakt_ActivityShoutShowVM(contractAct);

                                TraktShoutTile tile = new TraktShoutTile()
                                {
                                    ShowName            = shoutShow.Shout.ShowTitle,
                                    ShowPicture         = blankImageName,
                                    Details             = shoutShow.Shout.Text,
                                    ShoutDateString     = shoutShow.ActivityDateString,
                                    FriendName          = shoutShow.User.Username,
                                    FriendPicture       = blankImageName,
                                    URL                 = shoutShow.Shout.TraktShow.url,
                                    OnlineShowPicture   = shoutShow.Shout.OnlineImagePath,
                                    OnlineFriendPicture = shoutShow.User.Avatar,
                                    TileSize            = "Large",
                                    Height              = 100
                                };

                                TraktShouts.Add(tile);
                                imagesToDownload.Add(tile);
                                numItems = 1;
                            }
                        }
                    }

                    if (TraktShouts.Count > 0)
                    {
                        System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action) delegate()
                        {
                            TraktActivity.Add(TraktShouts[0]);
                        });
                    }

                    traktActivity = JMMServerVM.Instance.clientBinaryHTTP.GetTraktFriendInfo(AppSettings.DashMetro_TraktActivity_Items + 1,
                                                                                             false, false, true);

                    foreach (JMMServerBinary.Contract_Trakt_FriendActivity contractAct in traktActivity.TraktFriendActivity)
                    {
                        if (numItems == AppSettings.DashMetro_TraktActivity_Items)
                        {
                            break;
                        }

                        if (contractAct.ActivityAction == (int)TraktActivityAction.Scrobble)
                        {
                            Trakt_ActivityScrobbleVM scrobble = new Trakt_ActivityScrobbleVM(contractAct);

                            TraktActivityTile tile = new TraktActivityTile()
                            {
                                Scrobble       = scrobble,
                                ShowName       = scrobble.Episode.ShowTitle,
                                ShowPicture    = blankImageName,
                                EpisodeDetails = scrobble.Episode.EpisodeDescription,
                                URL            = scrobble.Episode.Episode_Url,
                                FriendName     = scrobble.User.Username,
                                FriendPicture  = blankImageName,
                                TileSize       = "Large",
                                Height         = 100
                            };

                            numItems++;

                            System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action) delegate()
                            {
                                TraktActivity.Add(tile);
                            });

                            imagesToDownload.Add(tile);
                        }
                    }
                }
                else
                {
                    Trakt_SignupVM signup = new Trakt_SignupVM();
                    System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action) delegate()
                    {
                        TraktActivity.Add(signup);
                    });
                }

                OnFinishedProcess(new FinishedProcessEventArgs(DashboardMetroProcessType.TraktActivity));
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
            finally
            {
            }
        }
示例#5
0
        public void RefreshTraktFriends(bool traktScrobbles, bool traktShouts)
        {
            try
            {
                System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action) delegate()
                {
                    TraktActivity.Clear();
                });

                JMMServerBinary.Contract_Trakt_Activity traktActivity = JMMServerVM.Instance.clientBinaryHTTP.GetTraktFriendInfo(AppSettings.Dash_TraktFriends_Items,
                                                                                                                                 AppSettings.Dash_TraktFriends_AnimeOnly, traktShouts, traktScrobbles);

                List <object> activity = new List <object>();

                if (traktActivity.HasTraktAccount)
                {
                    foreach (JMMServerBinary.Contract_Trakt_FriendFrequest contractFriend in traktActivity.TraktFriendRequests)
                    {
                        Trakt_FriendRequestVM req = new Trakt_FriendRequestVM(contractFriend);
                        activity.Add(req);
                    }

                    foreach (JMMServerBinary.Contract_Trakt_FriendActivity contractAct in traktActivity.TraktFriendActivity)
                    {
                        if (contractAct.ActivityAction == (int)TraktActivityAction.Scrobble)
                        {
                            Trakt_ActivityScrobbleVM scrobble = new Trakt_ActivityScrobbleVM(contractAct);

                            if (!string.IsNullOrEmpty(scrobble.UserFullImagePath) && !File.Exists(scrobble.UserFullImagePath))
                            {
                                // re-download the friends avatar image
                                try
                                {
                                    System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action) delegate()
                                    {
                                        ImageDownloadRequest req = new ImageDownloadRequest(ImageEntityType.Trakt_ActivityScrobble, scrobble, true);
                                        MainWindow.imageHelper.DownloadImage(req);
                                    });
                                }
                                catch (Exception ex)
                                {
                                    logger.ErrorException(ex.ToString(), ex);
                                }
                            }

                            activity.Add(scrobble);
                        }
                        else if (contractAct.ActivityAction == (int)TraktActivityAction.Shout)
                        {
                            if (contractAct.ActivityType == (int)TraktActivityType.Episode)
                            {
                                Trakt_ActivityShoutEpisodeVM shoutEp = new Trakt_ActivityShoutEpisodeVM(contractAct);
                                activity.Add(shoutEp);
                            }
                            else
                            {
                                Trakt_ActivityShoutShowVM shoutShow = new Trakt_ActivityShoutShowVM(contractAct);
                                activity.Add(shoutShow);
                            }
                        }
                    }

                    foreach (JMMServerBinary.Contract_Trakt_Friend contract in traktActivity.TraktFriends)
                    {
                        if (contract.WatchedEpisodes != null && contract.WatchedEpisodes.Count > 0)
                        {
                            Trakt_FriendVM friend = new Trakt_FriendVM(contract);
                            activity.Add(friend);
                        }
                    }
                }
                else
                {
                    Trakt_SignupVM signup = new Trakt_SignupVM();
                    activity.Add(signup);
                }

                System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action) delegate()
                {
                    foreach (object act in activity)
                    {
                        TraktActivity.Add(act);
                    }
                    ViewTraktActivity.Refresh();
                });
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
            finally
            {
            }
        }
示例#6
0
        public void RefreshData(bool traktScrobbles, bool traktShouts, bool refreshContinueWatching, bool refreshRecentAdditions, bool refreshOtherWidgets, RecentAdditionsType addType)
        {
            try
            {
                IsLoadingData = true;

                // clear all displayed data
                System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action) delegate()
                {
                    if (refreshContinueWatching)
                    {
                        EpsWatchNext_Recent.Clear();
                    }
                    if (refreshRecentAdditions)
                    {
                        RecentAdditions.Clear();
                    }

                    if (refreshOtherWidgets)
                    {
                        SeriesMissingEps.Clear();
                        EpsWatchedRecently.Clear();
                        MiniCalendar.Clear();
                        RecommendationsWatch.Clear();
                        RecommendationsDownload.Clear();
                        TraktActivity.Clear();
                    }

                    if (refreshOtherWidgets)
                    {
                        ViewEpsWatchedRecently.Refresh();
                        ViewSeriesMissingEps.Refresh();
                        ViewMiniCalendar.Refresh();
                        ViewRecommendationsWatch.Refresh();
                        ViewRecommendationsDownload.Refresh();
                        ViewTraktActivity.Refresh();
                        ViewRecentAdditions.Refresh();
                    }

                    if (refreshContinueWatching)
                    {
                        ViewEpsWatchNext_Recent.Refresh();
                    }
                    if (refreshRecentAdditions)
                    {
                        ViewRecentAdditions.Refresh();
                    }
                });

                DateTime start = DateTime.Now;
                MainListHelperVM.Instance.RefreshGroupsSeriesData();
                TimeSpan ts = DateTime.Now - start;

                logger.Trace("Dashboard Time: RefreshGroupsSeriesData: {0}", ts.TotalMilliseconds);

                if (refreshContinueWatching && UserSettingsVM.Instance.DashWatchNextEpExpanded)
                {
                    RefreshEpsWatchNext_Recent();
                }

                if (refreshRecentAdditions && UserSettingsVM.Instance.DashRecentAdditionsExpanded)
                {
                    RefreshRecentAdditions(addType);
                }

                if (refreshOtherWidgets)
                {
                    if (UserSettingsVM.Instance.DashRecentlyWatchEpsExpanded)
                    {
                        RefreshRecentlyWatchedEps();
                    }

                    if (UserSettingsVM.Instance.DashSeriesMissingEpisodesExpanded)
                    {
                        RefreshSeriesMissingEps();
                    }

                    if (UserSettingsVM.Instance.DashMiniCalendarExpanded)
                    {
                        RefreshMiniCalendar();
                    }

                    if (UserSettingsVM.Instance.DashRecommendationsWatchExpanded)
                    {
                        RefreshRecommendationsWatch();
                    }

                    if (UserSettingsVM.Instance.DashRecommendationsDownloadExpanded)
                    {
                        RefreshRecommendationsDownload();
                    }

                    if (UserSettingsVM.Instance.DashTraktFriendsExpanded)
                    {
                        RefreshTraktFriends(traktScrobbles, traktShouts);
                    }
                }

                IsLoadingData = false;
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
            finally
            {
            }
        }
示例#7
0
        protected ActivityListItemViewModel DetermineActivityWithFilter(int type, TraktActivity activity)
        {
            ActivityListItemViewModel tempModel = null;

            try
            {
                switch (activity.Action)
                {
                case "watchlist":
                    if (type == 4 || (type >= 0 && type < 4))
                    {
                        if (type == 1 && activity.User.Username.Equals(AppUser.Instance.UserName))
                        {
                            break;
                        }
                        else if (type == 2 && !activity.User.Username.Equals(AppUser.Instance.UserName))
                        {
                            break;
                        }

                        tempModel = AddToWatchList(activity);
                    }
                    break;

                case "rating":
                    if (type == 5 || (type >= 0 && type < 4))
                    {
                        if (type == 1 && activity.User.Username.Equals(AppUser.Instance.UserName))
                        {
                            break;
                        }
                        else if (type == 2 && !activity.User.Username.Equals(AppUser.Instance.UserName))
                        {
                            break;
                        }

                        tempModel = Rated(activity);
                    }
                    break;

                case "checkin":
                    if (type == 6 || (type >= 0 && type < 4))
                    {
                        if (type == 1 && activity.User.Username.Equals(AppUser.Instance.UserName))
                        {
                            break;
                        }
                        else if (type == 2 && !activity.User.Username.Equals(AppUser.Instance.UserName))
                        {
                            break;
                        }

                        tempModel = Checkin(activity);
                    }
                    break;

                case "scrobble":
                    if (type == 7 || (type >= 0 && type < 4))
                    {
                        if (type == 1 && activity.User.Username.Equals(AppUser.Instance.UserName))
                        {
                            break;
                        }
                        else if (type == 2 && !activity.User.Username.Equals(AppUser.Instance.UserName))
                        {
                            break;
                        }

                        tempModel = Scrobble(activity);
                    }
                    break;

                case "shout":
                    if (type == 8 || (type >= 0 && type < 4))
                    {
                        if (type == 1 && activity.User.Username.Equals(AppUser.Instance.UserName))
                        {
                            break;
                        }
                        else if (type == 2 && !activity.User.Username.Equals(AppUser.Instance.UserName))
                        {
                            break;
                        }

                        tempModel = Shout(activity);
                    }
                    break;
                }
            }
            catch (NullReferenceException) { }
            return(tempModel);
        }