예제 #1
0
        public void ChildsAdd(VFile file)
        {
            string name = file.FileName;
            VFile  cp   = this.FindInChilds(name);

            if (cp != null)
            {
                int i = 0;
                while (cp != null)
                {
                    i++;
                    // Думал вот сейчас напишешь одну строчку, а фот фиг тебе, експешен кидает на кривые пути(
                    // name = Path.GetFileNameWithoutExtension(file.FileName) + "(" + i.ToString() + ")" + Path.GetExtension(file.FileName);
                    int dotPos = file.FileName.LastIndexOf('.');
                    if (dotPos > -1)
                    {
                        name = file.FileName.Substring(0, dotPos) + "(" + i.ToString() + ")" + file.FileName.Substring(dotPos);
                    }
                    else
                    {
                        name = file.FileName + "(" + i.ToString() + ")";
                    }

                    cp = this.FindInChilds(name);
                }
                file.FileName = name;
            }

            Childs.Add(file);
        }
예제 #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
        private void GroupFile()
        {
            if (Childs.Count <= 500)
            {
                return;
            }
            const int maxFile = 500;

            /*if (Childs.First().GetType() == typeof(Folder))
             * {
             *  maxFile = 100;
             * }
             * else if (Childs.Count < maxFile)
             * {
             *  return;
             * }*/

            BlockingList <VFile> replaceChilds = new BlockingList <VFile>();
            List <VFile>         copy          = Childs.Select(item => item).ToList(); // clone list

            copy.Sort((a, b) => string.Compare(a.FileName, b.FileName, StringComparison.Ordinal));
            for (var i = 0; i <= (copy.Count / maxFile); i++)
            {
                var residue = copy.Count - (i * maxFile);         // остаток
                residue = residue < maxFile ? residue : maxFile;
                IList <VFile> tmp        = copy.GetRange(i * maxFile, residue);
                var           folderName = VFile.ClearName(tmp[0].FileName, false).Substring(0, 1) + ".." + VFile.ClearName(tmp[residue - 1].FileName, false).Substring(0, 1);
                var           fNode      = new Folder(folderName);

                foreach (VFile curFile in tmp)
                {
                    fNode.Childs.Add(curFile);
                }
                fNode.IsLoaded = true;
                replaceChilds.Add(fNode);
            }
            Childs = replaceChilds;
        }
예제 #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 DownloadAniDBCover(VM_AniDB_Anime anime, bool forceDownload)
        {
            if (string.IsNullOrEmpty(anime.Picname))
            {
                return;
            }

            try
            {
                ImageDownloadRequest req = new ImageDownloadRequest(ImageEntityType.AniDB_Cover, anime, forceDownload);

                // check if this file has already been downloaded and exists
                if (!req.ForceDownload)
                {
                    // check to make sure the file actually exists
                    if (!File.Exists(anime.PosterPathNoDefaultPlain))
                    {
                        imagesToDownload.Add(req);
                        OnQueueUpdateEvent(new QueueUpdateEventArgs(QueueCount));
                        return;
                    }

                    // the file exists so don't download it again
                    return;
                }

                imagesToDownload.Add(req);
                OnQueueUpdateEvent(new QueueUpdateEventArgs(QueueCount));
            }
            catch (Exception ex)
            {
                BaseConfig.MyAnimeLog.Write(ex.ToString());
            }
        }