示例#1
0
        public ActionResult SearchResource(string searchText, int pageIndex)
        {
            if (pageIndex <= 1)
            {
                try
                {
                    SearchLog tmpLog = new SearchLog();
                    tmpLog.IPAddress   = Request.UserHostAddress;
                    tmpLog.LogDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    tmpLog.SearchStr   = searchText;
                    db.SearchLogs.Add(tmpLog);
                    db.SaveChanges();
                }
                catch
                {
                }
            }

            SearchResult result = new SearchResult();

            result.PageIndex = pageIndex;

            string htmlStr = HtmlReader.OpenSync(string.Format(SEARCHHTMLFORMAT, searchText, pageIndex));

            if (!string.IsNullOrEmpty(htmlStr))
            {
                HtmlAnalyser analyser             = new HtmlAnalyser(htmlStr);
                HtmlAnalyser.MagnetResult[] tmpMC = analyser.GetResult();
                result.Items = new List <ResourceItem>();
                foreach (HtmlAnalyser.MagnetResult item in tmpMC)
                {
                    ResourceItem resourceItem = new ResourceItem();
                    resourceItem.ResourceName = item.Description;
                    resourceItem.MagnetLink   = item.MargnetLink;
                    resourceItem.Date         = item.Date;
                    resourceItem.Size         = item.Size;
                    resourceItem.SeedLink     = item.SeedLink;
                    resourceItem.DetailUrl    = HOMEPAGEURL + item.DetailLink;
                    result.Items.Add(resourceItem);
                }
                result.PageCount = analyser.GetPageCount();
            }

            if (Request.IsAjaxRequest())
            {
                string jsonStr = PubFunction.BuildResult(result);
                return(Content(jsonStr));
            }
            else
            {
                return(View(result));
            }
        }