Esempio n. 1
0
        private void BtnStart_Click(object sender, RoutedEventArgs e)
        {
            stopWorker      = false;
            ShowStartButton = false;
            ShowStopButton  = true;
            //ShowPauseButton = true;

            WorkerStatus = Shoko.Commons.Properties.Resources.Community_GettingData;

            TraktResults.Clear();

            TraktWorkerJob job = new TraktWorkerJob();

            job.TraktData       = TraktResults;
            job.CheckTraktLinks = chkTraktValid.IsChecked.Value;
            if (job.CheckTraktLinks)
            {
                job.FixTraktLinks = chkTraktValidCleanup.IsChecked.Value;
            }
            job.CheckCommunityLinks = chkCommRec.IsChecked.Value;
            job.MaxProblems         = int.MaxValue;
            if (chkLimitSeries.IsChecked.Value && udLimitSeries.Value.HasValue)
            {
                job.MaxProblems = udLimitSeries.Value.Value;
            }

            dataWorker.RunWorkerAsync(job);
        }
Esempio n. 2
0
        void dataWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            TraktWorkerJob   job    = e.Argument as TraktWorkerJob;
            BackgroundWorker worker = sender as BackgroundWorker;

            // Get all the seies data
            List <VM_AnimeSeries_User> allSeries = VM_ShokoServer.Instance.ShokoServices.GetAllSeries(VM_ShokoServer.Instance.CurrentUser.JMMUserID).CastList <VM_AnimeSeries_User>().OrderBy(a => a.SeriesName).ToList();

            if (stopWorker)
            {
                return;
            }

            Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action) delegate()
            {
                WorkerStatus = Shoko.Commons.Properties.Resources.Community_TraktRef;
            });

            // get all the trakt links
            List <VM_CrossRef_AniDB_TraktV2> allTraktCrossRefs = VM_ShokoServer.Instance.ShokoServices.GetAllTraktCrossRefs().CastList <VM_CrossRef_AniDB_TraktV2>();

            if (stopWorker)
            {
                return;
            }

            int counter      = 0;
            int problemCount = 0;

            foreach (VM_AnimeSeries_User ser in allSeries)
            {
                counter++;
                //Thread.Sleep(200);

                dataWorker.ReportProgress(0, new TraktWorkerStatusContainer(Shoko.Commons.Properties.Resources.Community_TraktPopulating, allSeries.Count, counter, ser.SeriesName));

                TraktSeriesData trakt = new TraktSeriesData(ser);

                // populate the Trakt data
                trakt.SetUserTraktLinks(allTraktCrossRefs.Where(x => x.AnimeID == ser.AniDB_ID));

                Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action) delegate()
                {
                    job.TraktData.Add(trakt);
                });


                if (stopWorker)
                {
                    return;
                }
            }
            if (stopWorker)
            {
                return;
            }


            int curFile = 0;

            foreach (TraktSeriesData data in job.TraktData)
            {
                if (stopWorker)
                {
                    return;
                }
                //Thread.Sleep(250);

                if (problemCount == job.MaxProblems)
                {
                    return;
                }

                curFile++;
                dataWorker.ReportProgress(0, new TraktWorkerStatusContainer(Shoko.Commons.Properties.Resources.Community_TraktSeriesCheck, job.TraktData.Count, curFile, data.SeriesName));

                if (stopWorker)
                {
                    return;
                }
                if (job.CheckTraktLinks)
                {
                    data.Status = Shoko.Commons.Properties.Resources.Community_TraktDataCheck;
                    bool valid = true;

                    if (data.HasUserTraktLink)
                    {
                        foreach (VM_CrossRef_AniDB_TraktV2 xref in data.UserTraktLinks)
                        {
                            bool thisValid = VM_ShokoServer.Instance.ShokoServices.CheckTraktLinkValidity(xref.TraktID, job.FixTraktLinks);
                            if (!thisValid)
                            {
                                valid = false;
                                problemCount++;
                            }
                        }
                        data.IsTraktLinkValid = valid;
                    }
                }

                if (stopWorker)
                {
                    return;
                }
                if (job.CheckCommunityLinks)
                {
                    data.Status = Shoko.Commons.Properties.Resources.Community_TraktCompare;

                    List <Azure_CrossRef_AniDB_Trakt> xrefs          = VM_ShokoServer.Instance.ShokoServices.GetTraktCrossRefWebCache(data.AnimeID, false);
                    List <VM_CrossRef_AniDB_TraktV2>  commTraktLinks = new List <VM_CrossRef_AniDB_TraktV2>();
                    foreach (Azure_CrossRef_AniDB_Trakt xref in xrefs)
                    {
                        commTraktLinks.Add((VM_CrossRef_AniDB_TraktV2)xref);
                    }
                    data.SetCommTraktLinks(commTraktLinks);

                    if (data.HasUserTraktLink)
                    {
                        data.CompareTraktLinks();
                        if (!data.UserTraktLinkMatch && data.HasCommTraktLink)
                        {
                            problemCount++;
                        }
                    }
                    else
                    {
                    }
                }
            }
        }