void searchTraktWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            SearchTraktResults res = new SearchTraktResults();
            res.ErrorMessage = string.Empty;
            res.TraktLinks = new List<CrossRef_AniDB_TraktVMV2>();
            res.ExtraInfo = string.Empty;

            try
            {
                SearchCriteria crit = e.Argument as SearchCriteria;
                if (!string.IsNullOrEmpty(crit.ExtraInfo))
                    res.ExtraInfo = crit.ExtraInfo;

                try
                {
                    List<JMMServerBinary.Contract_Azure_CrossRef_AniDB_Trakt> xrefs = JMMServerVM.Instance.clientBinaryHTTP.GetTraktCrossRefWebCache(crit.AnimeID, true);
                    if (xrefs != null && xrefs.Count > 0)
                    {
                        foreach (JMMServerBinary.Contract_Azure_CrossRef_AniDB_Trakt xref in xrefs)
                        {
                            CrossRef_AniDB_TraktVMV2 xrefAzure = new CrossRef_AniDB_TraktVMV2(xref);
                            res.TraktLinks.Add(xrefAzure);
                        }
                    }
                }
                catch (Exception ex)
                {
                    res.ErrorMessage = ex.Message;
                }

                e.Result = res;
            }
            catch (Exception ex)
            {
                res.ErrorMessage = ex.Message;
                e.Result = res;
            }
        }
        void dataWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            TraktWorkerJob job = e.Argument as TraktWorkerJob;
            BackgroundWorker worker = sender as BackgroundWorker;

            // Get all the seies data
            List<JMMServerBinary.Contract_AnimeSeries> sersRaw = JMMServerVM.Instance.clientBinaryHTTP.GetAllSeries(JMMServerVM.Instance.CurrentUser.JMMUserID.Value);
            List<AnimeSeriesVM> allSeries = new List<AnimeSeriesVM>();
            foreach (JMMServerBinary.Contract_AnimeSeries contract in sersRaw)
            {
                AnimeSeriesVM ser = new AnimeSeriesVM(contract);
                allSeries.Add(ser);
                if (stopWorker) return;
            }

            List<SortPropOrFieldAndDirection> sortCriteria = new List<SortPropOrFieldAndDirection>();
            sortCriteria.Add(new SortPropOrFieldAndDirection("SeriesName", false, SortType.eString));
            allSeries = Sorting.MultiSort<AnimeSeriesVM>(allSeries, sortCriteria);

            if (stopWorker) return;

            System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)delegate ()
            {
                WorkerStatus = "Getting all Trakt Cross Ref data...";
            });

            // get all the trakt links
            List<CrossRef_AniDB_TraktVMV2> allTraktCrossRefs = new List<CrossRef_AniDB_TraktVMV2>();
            List<JMMServerBinary.Contract_CrossRef_AniDB_TraktV2> traktxrefs = JMMServerVM.Instance.clientBinaryHTTP.GetAllTraktCrossRefs();
            foreach (JMMServerBinary.Contract_CrossRef_AniDB_TraktV2 raw in traktxrefs)
            {
                allTraktCrossRefs.Add(new CrossRef_AniDB_TraktVMV2(raw));
                if (stopWorker) return;
            }

            int counter = 0;
            int problemCount = 0;

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

                dataWorker.ReportProgress(0, new TraktWorkerStatusContainer("Populating series data", allSeries.Count, counter, ser.SeriesName));

                TraktSeriesData trakt = new TraktSeriesData(ser);

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

                System.Windows.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("Checking series", job.TraktData.Count, curFile, data.SeriesName));

                if (stopWorker) return;
                if (job.CheckTraktLinks)
                {
                    data.Status = "Checking if Trakt data is valid...";
                    bool valid = true;

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

                if (stopWorker) return;
                if (job.CheckCommunityLinks)
                {
                    data.Status = "Checking Trakt link against community recommendation...";

                    List<JMMServerBinary.Contract_Azure_CrossRef_AniDB_Trakt> xrefs = JMMServerVM.Instance.clientBinaryHTTP.GetTraktCrossRefWebCache(data.AnimeID, false);
                    List<CrossRef_AniDB_TraktVMV2> commTraktLinks = new List<CrossRef_AniDB_TraktVMV2>();
                    foreach (JMMServerBinary.Contract_Azure_CrossRef_AniDB_Trakt xref in xrefs)
                    {
                        CrossRef_AniDB_TraktVMV2 xrefComm = new CrossRef_AniDB_TraktVMV2(xref);
                        commTraktLinks.Add(xrefComm);
                    }
                    data.SetCommTraktLinks(commTraktLinks);

                    if (data.HasUserTraktLink)
                    {
                        data.CompareTraktLinks();
                        if (!data.UserTraktLinkMatch && data.HasCommTraktLink) problemCount++;
                    }
                    else
                    { }
                }
            }
        }
        void communityWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            SearchCommunityResults res = new SearchCommunityResults();
            res.ErrorMessage = string.Empty;
            res.TvDBLinks = new List<CrossRef_AniDB_TvDBVMV2>();
            res.TraktLinks = new List<CrossRef_AniDB_TraktVMV2>();
            res.ExtraInfo = string.Empty;
            res.AnimeID = -1;

            try
            {
                AniDB_AnimeVM anime = e.Argument as AniDB_AnimeVM;
                if (anime == null) return;

                res.AnimeID = anime.AnimeID;

                SearchCriteria crit = new SearchCriteria();
                crit.AnimeID = anime.AnimeID;
                crit.ExtraInfo = string.Empty;

                // search for TvDB links
                try
                {
                    List<JMMServerBinary.Contract_Azure_CrossRef_AniDB_TvDB> xrefs = JMMServerVM.Instance.clientBinaryHTTP.GetTVDBCrossRefWebCache(crit.AnimeID, true);
                    if (xrefs != null && xrefs.Count > 0)
                    {
                        foreach (JMMServerBinary.Contract_Azure_CrossRef_AniDB_TvDB xref in xrefs)
                        {
                            CrossRef_AniDB_TvDBVMV2 xrefAzure = new CrossRef_AniDB_TvDBVMV2(xref);
                            res.TvDBLinks.Add(xrefAzure);
                        }
                    }
                }
                catch (Exception ex)
                {
                    res.ErrorMessage = ex.Message;
                }

                // search for Trakt links
                try
                {
                    List<JMMServerBinary.Contract_Azure_CrossRef_AniDB_Trakt> xrefs = JMMServerVM.Instance.clientBinaryHTTP.GetTraktCrossRefWebCache(crit.AnimeID, true);
                    if (xrefs != null && xrefs.Count > 0)
                    {
                        foreach (JMMServerBinary.Contract_Azure_CrossRef_AniDB_Trakt xref in xrefs)
                        {
                            CrossRef_AniDB_TraktVMV2 xrefAzure = new CrossRef_AniDB_TraktVMV2(xref);
                            res.TraktLinks.Add(xrefAzure);
                        }
                    }
                }
                catch (Exception ex)
                {
                    res.ErrorMessage = ex.Message;
                }

                e.Result = res;
            }
            catch (Exception ex)
            {
                res.ErrorMessage = ex.Message;
                e.Result = res;
            }
        }
        void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            TraktSeriesSearchResults.Clear();
            CrossRef_AniDB_TraktResult.Clear();

            HasWebCacheRec = false;
            if (!JMMServerVM.Instance.ServerOnline) return;

            this.Cursor = Cursors.Wait;
            try
            {

                // first find what the community recommends
                List<JMMServerBinary.Contract_Azure_CrossRef_AniDB_Trakt> xrefs = JMMServerVM.Instance.clientBinaryHTTP.GetTraktCrossRefWebCache(AnimeID, false);
                if (xrefs != null && xrefs.Count > 0)
                {
                    foreach (JMMServerBinary.Contract_Azure_CrossRef_AniDB_Trakt xref in xrefs)
                    {
                        CrossRef_AniDB_TraktVMV2 xrefAzure = new CrossRef_AniDB_TraktVMV2(xref);
                        CrossRef_AniDB_TraktResult.Add(xrefAzure);
                    }

                    HasWebCacheRec = true;
                }

                // now search Trakt

                List<JMMServerBinary.Contract_TraktTVShowResponse> traktResults = JMMServerVM.Instance.clientBinaryHTTP.SearchTrakt(txtSearch.Text.Trim());
                foreach (JMMServerBinary.Contract_TraktTVShowResponse traktResult in traktResults)
                    TraktSeriesSearchResults.Add(new TraktTVShowResponseVM(traktResult));
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
            finally
            {
                this.Cursor = Cursors.Arrow;
            }
        }