コード例 #1
0
        private void ProcessImages()
        {
            foreach (object req in imagesToDownload)
            {
                try
                {
                    if (req.GetType() == typeof(Trakt_ShoutUserVM))
                    {
                        Trakt_ShoutUserVM tile = req as Trakt_ShoutUserVM;


                        //user
                        Uri    uriUser      = new Uri(tile.UserOnlineImagePath);
                        string filenameUser = Path.GetFileName(uriUser.LocalPath);
                        string tempNameUser = Path.Combine(Path.GetTempPath(), filenameUser);

                        using (WebClient client = new WebClient())
                        {
                            client.Headers.Add("user-agent", "JMM");


                            if (!File.Exists(tempNameUser))
                            {
                                if (tile.UserOnlineImagePath.Length > 0)
                                {
                                    client.DownloadFile(tile.UserOnlineImagePath, tempNameUser);
                                }
                            }
                            if (File.Exists(tempNameUser))
                            {
                                tile.DelayedUserImage = tempNameUser;
                            }
                        }
                    }

                    if (req.GetType() == typeof(AniDB_RecommendationVM))
                    {
                        AniDB_RecommendationVM tile = req as AniDB_RecommendationVM;

                        // unfortunately AniDB doesn't have any user images yet
                        // we will use a placeholder
                        tile.DelayedUserImage = tile.UserImagePathForDisplay;
                    }


                    imagesToDownload.Remove(req);
                }
                catch (Exception ex)
                {
                    imagesToDownload.Remove(req);
                    logger.ErrorException(ex.ToString(), ex);
                }
            }
        }
コード例 #2
0
        void shoutsWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            AnimeSeriesVM            ser        = e.Argument as AnimeSeriesVM;
            List <Trakt_ShoutUserVM> tempShouts = new List <Trakt_ShoutUserVM>();

            try
            {
                System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action) delegate()
                {
                    Shouts.Clear();
                });

                // get shouts from trakt
                List <JMMServerBinary.Contract_Trakt_ShoutUser> rawShouts = JMMServerVM.Instance.clientBinaryHTTP.GetTraktShoutsForAnime(ser.AniDB_ID);
                foreach (JMMServerBinary.Contract_Trakt_ShoutUser contract in rawShouts)
                {
                    Trakt_ShoutUserVM shout = new Trakt_ShoutUserVM(contract);

                    shout.DelayedUserImage = @"/Images/blankposter.png";
                    System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action) delegate()
                    {
                        Shouts.Add(shout);
                    });

                    imagesToDownload.Add(shout);
                }

                // get recommendations from AniDB
                List <JMMServerBinary.Contract_AniDB_Recommendation> rawRecs = JMMServerVM.Instance.clientBinaryHTTP.GetAniDBRecommendations(ser.AniDB_ID);
                foreach (JMMServerBinary.Contract_AniDB_Recommendation contract in rawRecs)
                {
                    AniDB_RecommendationVM rec = new AniDB_RecommendationVM(contract);

                    rec.DelayedUserImage = @"/Images/blankposter.png";
                    System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action) delegate()
                    {
                        Shouts.Add(rec);
                    });

                    imagesToDownload.Add(rec);
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
        }
コード例 #3
0
        void refreshDataWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            List <Trakt_ShoutUserVM> tempShouts = new List <Trakt_ShoutUserVM>();

            try
            {
                AnimeSeriesVM animeSeries = (AnimeSeriesVM)e.Argument;
                if (animeSeries == null)
                {
                    return;
                }

                List <JMMServerBinary.Contract_Trakt_ShoutUser> rawShouts = JMMServerVM.Instance.clientBinaryHTTP.GetTraktShoutsForAnime(animeSeries.AniDB_ID);
                foreach (JMMServerBinary.Contract_Trakt_ShoutUser contract in rawShouts)
                {
                    Trakt_ShoutUserVM shout = new Trakt_ShoutUserVM(contract);


                    if (!string.IsNullOrEmpty(shout.UserFullImagePath) && !File.Exists(shout.UserFullImagePath))
                    {
                        // re-download the friends avatar image
                        try
                        {
                            ImageDownloadRequest req = new ImageDownloadRequest(ImageEntityType.Trakt_ShoutUser, shout, false);
                            MainWindow.imageHelper.DownloadImage(req);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                        }
                    }

                    tempShouts.Add(shout);
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }

            e.Result = tempShouts;
        }
コード例 #4
0
ファイル: ImageDownloader.cs プロジェクト: alimbada/jmmclient
        private string GetEntityID(ImageDownloadRequest req)
        {
            switch (req.ImageType)
            {
            case ImageEntityType.AniDB_Cover:

                AniDB_AnimeVM anime = req.ImageData as AniDB_AnimeVM;
                return(anime.AnimeID.ToString());

            case ImageEntityType.TvDB_Cover:

                TvDB_ImagePosterVM poster = req.ImageData as TvDB_ImagePosterVM;
                return(poster.TvDB_ImagePosterID.ToString());

            case ImageEntityType.TvDB_Banner:

                TvDB_ImageWideBannerVM banner = req.ImageData as TvDB_ImageWideBannerVM;
                return(banner.TvDB_ImageWideBannerID.ToString());

            case ImageEntityType.TvDB_Episode:

                TvDB_EpisodeVM episode = req.ImageData as TvDB_EpisodeVM;
                return(episode.TvDB_EpisodeID.ToString());

            case ImageEntityType.TvDB_FanArt:

                TvDB_ImageFanartVM fanart = req.ImageData as TvDB_ImageFanartVM;
                return(fanart.TvDB_ImageFanartID.ToString());

            case ImageEntityType.MovieDB_Poster:

                MovieDB_PosterVM moviePoster = req.ImageData as MovieDB_PosterVM;
                return(moviePoster.MovieDB_PosterID.ToString());

            case ImageEntityType.MovieDB_FanArt:

                MovieDB_FanartVM movieFanart = req.ImageData as MovieDB_FanartVM;
                return(movieFanart.MovieDB_FanartID.ToString());

            case ImageEntityType.Trakt_Poster:

                Trakt_ImagePosterVM traktPoster = req.ImageData as Trakt_ImagePosterVM;
                return(traktPoster.Trakt_ImagePosterID.ToString());

            case ImageEntityType.Trakt_Fanart:

                Trakt_ImageFanartVM trakFanart = req.ImageData as Trakt_ImageFanartVM;
                return(trakFanart.Trakt_ImageFanartID.ToString());

            case ImageEntityType.Trakt_Friend:

                Trakt_FriendVM trakFriend = req.ImageData as Trakt_FriendVM;
                return(trakFriend.Trakt_FriendID.ToString());

            case ImageEntityType.Trakt_ActivityScrobble:

                Trakt_ActivityScrobbleVM trakScrobble = req.ImageData as Trakt_ActivityScrobbleVM;
                return(trakScrobble.User.Trakt_FriendID.ToString());

            case ImageEntityType.Trakt_ShoutUser:

                Trakt_ShoutUserVM traktShoutUser = req.ImageData as Trakt_ShoutUserVM;
                return(traktShoutUser.User.Trakt_FriendID.ToString());

            case ImageEntityType.Trakt_Episode:

                Trakt_EpisodeVM trakEp = req.ImageData as Trakt_EpisodeVM;
                return(trakEp.Trakt_EpisodeID.ToString());

            case ImageEntityType.Trakt_WatchedEpisode:

                Trakt_WatchedEpisodeVM trakwEp = req.ImageData as Trakt_WatchedEpisodeVM;
                return(trakwEp.Trakt_EpisodeID.ToString());

            default:
                return("");
            }
        }
コード例 #5
0
ファイル: ImageDownloader.cs プロジェクト: alimbada/jmmclient
        private string GetFileName(ImageDownloadRequest req, bool thumbNailOnly)
        {
            switch (req.ImageType)
            {
            case ImageEntityType.AniDB_Cover:

                AniDB_AnimeVM anime = req.ImageData as AniDB_AnimeVM;
                return(anime.PosterPathNoDefaultPlain);

            case ImageEntityType.TvDB_Cover:

                TvDB_ImagePosterVM poster = req.ImageData as TvDB_ImagePosterVM;
                return(poster.FullImagePathPlain);

            case ImageEntityType.TvDB_Banner:

                TvDB_ImageWideBannerVM banner = req.ImageData as TvDB_ImageWideBannerVM;
                return(banner.FullImagePathPlain);

            case ImageEntityType.TvDB_Episode:

                TvDB_EpisodeVM episode = req.ImageData as TvDB_EpisodeVM;
                return(episode.FullImagePathPlain);

            case ImageEntityType.TvDB_FanArt:

                TvDB_ImageFanartVM fanart = req.ImageData as TvDB_ImageFanartVM;

                if (thumbNailOnly)
                {
                    return(fanart.FullThumbnailPathPlain);
                }
                else
                {
                    return(fanart.FullImagePathPlain);
                }

            case ImageEntityType.MovieDB_Poster:

                MovieDB_PosterVM moviePoster = req.ImageData as MovieDB_PosterVM;
                return(moviePoster.FullImagePathPlain);

            case ImageEntityType.MovieDB_FanArt:

                MovieDB_FanartVM movieFanart = req.ImageData as MovieDB_FanartVM;
                return(movieFanart.FullImagePathPlain);

            case ImageEntityType.Trakt_Poster:

                Trakt_ImagePosterVM traktPoster = req.ImageData as Trakt_ImagePosterVM;
                return(traktPoster.FullImagePathPlain);

            case ImageEntityType.Trakt_Fanart:

                Trakt_ImageFanartVM trakFanart = req.ImageData as Trakt_ImageFanartVM;
                return(trakFanart.FullImagePathPlain);

            case ImageEntityType.Trakt_Friend:

                Trakt_FriendVM trakFriend = req.ImageData as Trakt_FriendVM;
                return(trakFriend.FullImagePathPlain);

            case ImageEntityType.Trakt_ActivityScrobble:

                Trakt_ActivityScrobbleVM trakScrobble = req.ImageData as Trakt_ActivityScrobbleVM;
                return(trakScrobble.UserFullImagePathPlain);

            case ImageEntityType.Trakt_ShoutUser:

                Trakt_ShoutUserVM trakShoutUser = req.ImageData as Trakt_ShoutUserVM;
                return(trakShoutUser.UserFullImagePathPlain);

            case ImageEntityType.Trakt_Episode:

                Trakt_EpisodeVM trakEp = req.ImageData as Trakt_EpisodeVM;
                return(trakEp.FullImagePathPlain);

            case ImageEntityType.Trakt_WatchedEpisode:

                Trakt_WatchedEpisodeVM trakwEp = req.ImageData as Trakt_WatchedEpisodeVM;
                return(trakwEp.FullImagePathPlain);

            default:
                return("");
            }
        }