コード例 #1
0
        void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            HasWebCacheRec = false;
            if (!JMMServerVM.Instance.ServerOnline)
            {
                return;
            }

            this.Cursor = Cursors.Wait;
            try
            {
                CrossRef_AniDB_TvDBResult.Clear();
                // first find what the community recommends
                List <JMMServerBinary.Contract_Azure_CrossRef_AniDB_TvDB> xrefs = JMMServerVM.Instance.clientBinaryHTTP.GetTVDBCrossRefWebCache(AnimeID, false);
                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);
                        CrossRef_AniDB_TvDBResult.Add(xrefAzure);
                    }

                    HasWebCacheRec = true;
                }

                // now search the TvDB
                TVDBSeriesSearchResults = new List <TVDBSeriesSearchResultVM>();
                List <JMMServerBinary.Contract_TVDBSeriesSearchResult> tvResults = JMMServerVM.Instance.clientBinaryHTTP.SearchTheTvDB(txtSearch.Text.Trim());
                foreach (JMMServerBinary.Contract_TVDBSeriesSearchResult tvResult in tvResults)
                {
                    TVDBSeriesSearchResults.Add(new TVDBSeriesSearchResultVM(tvResult));
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
            finally
            {
                this.Cursor = Cursors.Arrow;
            }
        }
コード例 #2
0
        void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            HasWebCacheRec = false;
            if (!VM_ShokoServer.Instance.ServerOnline)
            {
                return;
            }

            Cursor = Cursors.Wait;
            try
            {
                CrossRef_AniDB_TvDBResult.Clear();
                // first find what the community recommends
                List <Azure_CrossRef_AniDB_TvDB> xrefs = VM_ShokoServer.Instance.ShokoServices.GetTVDBCrossRefWebCache(AnimeID, false);
                if (xrefs != null && xrefs.Count > 0)
                {
                    foreach (Azure_CrossRef_AniDB_TvDB xref in xrefs)
                    {
                        CrossRef_AniDB_TvDBResult.Add((VM_CrossRef_AniDB_TvDBV2)xref);
                    }

                    HasWebCacheRec = true;
                }

                // now search the TvDB
                TVDBSeriesSearchResults = VM_ShokoServer.Instance.ShokoServices.SearchTheTvDB(txtSearch.Text.Replace("`", "'").Trim()).CastList <VM_TVDB_Series_Search_Response>();
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
            finally
            {
                Cursor = Cursors.Arrow;
            }
        }
コード例 #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.ContentType = "text/xml";

            try
            {
                string aid     = Utils.GetParam("AnimeID");
                int    animeid = 0;
                int.TryParse(aid, out animeid);

                if (animeid <= 0)
                {
                    Response.Write(Constants.ERROR_XML);
                    return;
                }

                string uname = Utils.GetParam("uname");
                if (uname.Trim().Length == 0)
                {
                    Response.Write(Constants.ERROR_XML);
                    return;
                }

                CrossRef_AniDB_TvDBRepository repCrossRef = new CrossRef_AniDB_TvDBRepository();
                CrossRef_AniDB_TvDB           xref        = null;

                // check for admin approved
                List <CrossRef_AniDB_TvDB> recs = repCrossRef.GetByAnimeIDApproved(animeid);
                if (recs.Count > 0)
                {
                    xref = recs[0];                                 // should only be one
                }
                // check for user specific
                if (xref == null)
                {
                    recs = repCrossRef.GetByAnimeIDUser(animeid, uname);
                    if (recs.Count > 0)
                    {
                        xref = recs[0];                                     // should only be one
                    }
                }

                // check for other users (anonymous)
                if (xref == null)
                {
                    // check for other users (anonymous)
                    recs = repCrossRef.GetByAnimeID(animeid);
                    if (recs.Count == 0)
                    {
                        Response.Write(Constants.ERROR_XML);
                        return;
                    }

                    // find the most popular result

                    List <CrossRefStat> results = new List <CrossRefStat>();
                    foreach (CrossRef_AniDB_TvDB xrefloc in recs)
                    {
                        bool found = false;
                        foreach (CrossRefStat stat in results)
                        {
                            if (stat.TvDBID == xrefloc.TvDBID && stat.TvDBSeason == xrefloc.TvDBSeasonNumber)
                            {
                                found = true;
                                stat.ResultCount++;
                            }
                        }
                        if (!found)
                        {
                            CrossRefStat stat = new CrossRefStat();
                            stat.ResultCount = 1;
                            stat.TvDBID      = xrefloc.TvDBID;
                            stat.TvDBSeason  = xrefloc.TvDBSeasonNumber;
                            stat.CrossRef    = xrefloc;
                            results.Add(stat);
                        }
                    }

                    CrossRefStat mostPopular = null;
                    foreach (CrossRefStat stat in results)
                    {
                        if (mostPopular == null)
                        {
                            mostPopular = stat;
                        }
                        else
                        {
                            if (stat.ResultCount > mostPopular.ResultCount)
                            {
                                mostPopular = stat;
                            }
                        }
                    }

                    xref = mostPopular.CrossRef;
                }

                CrossRef_AniDB_TvDBResult result = new CrossRef_AniDB_TvDBResult(xref);
                string ret = Utils.ConvertToXML(result, typeof(CrossRef_AniDB_TvDBResult));
                Response.Write(ret);
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
                return;
            }
        }