コード例 #1
0
        //Método BuscarNombre que llama al método BuscarNombre
        //de la clase DCategoría de la CapaDatos

        public static DataTable Search(string textsearch)
        {
            DCategory Obj = new DCategory();

            Obj.TextSearch = textsearch;
            return(Obj.Search(Obj));
        }
コード例 #2
0
        public async Task <ActionResult <DCategory> > PostDCategory(DCategory dCategory)
        {
            _context.DCategories.Add(dCategory);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetDCategory", new { id = dCategory.id }, dCategory));
        }
コード例 #3
0
        //Método Eliminar que llama al método Eliminar de la clase DCategoría
        //de la CapaDatos
        public static string Delete(int idcategory)
        {
            DCategory Obj = new DCategory();

            Obj.Idcategory = idcategory;
            return(Obj.Delete(Obj));
        }
コード例 #4
0
        public static DataTable SearchName(string searchtext)
        {
            DCategory Obj = new DCategory();

            Obj.Textsearch = searchtext;
            return(Obj.ShowName(Obj));
        }
コード例 #5
0
        /// <summary>
        /// 获取番剧类别信息
        /// </summary>
        /// <returns></returns>
        public async Task <DCategory[]> GetDramaCategoryAsync()
        {
            List <DCategory> listCategories = new List <DCategory>();

            string url = "/topics/advanced-search";

            string html = await Common.DownloadHtmlAsync(_httpClient, url);

            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(html);
            HtmlNodeCollection categoryNodes = doc.DocumentNode.SelectNodes("//select[@name='sort_id']/option");

            if (categoryNodes == null || categoryNodes.Count <= 0)
            {
                return(null);
            }

            foreach (var category in categoryNodes)
            {
                DCategory dCategory = new DCategory()
                {
                    Id   = Convert.ToInt64(category.Attributes["value"].Value),
                    Name = category.InnerText
                };

                listCategories.Add(dCategory);
            }

            listCategories.RemoveAt(0);

            return(listCategories.ToArray());
        }
コード例 #6
0
        //Método Insertar que llama al método Insertar de la clase DCategoría
        //de la CapaDatos
        public static string Insert(string name, string description)
        {
            DCategory Obj = new DCategory();

            Obj.Name        = name;
            Obj.Description = description;
            return(Obj.Insert(Obj));
        }
コード例 #7
0
        //Método Editar que llama al método Editar de la clase DCategoría
        //de la CapaDatos
        public static string Edit(int idcategory, string name, string description)
        {
            DCategory Obj = new DCategory();

            Obj.Idcategory  = idcategory;
            Obj.Name        = name;
            Obj.Description = description;
            return(Obj.Edit(Obj));
        }
コード例 #8
0
        public async Task <IActionResult> PutDCategory(int id, DCategory dCategory)
        {
            dCategory.id = id;

            _context.Entry(dCategory).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DCategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #9
0
        private DPost[] ToModels(string html)
        {
            List <DPost> models = new List <DPost>();

            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(html);

            HtmlNodeCollection trNodes = doc.DocumentNode.SelectNodes("//tbody/tr");

            if (trNodes == null)
            {
                return(null);
            }

            foreach (var tr in trNodes)
            {
                HtmlNodeCollection tdNodes = tr.SelectNodes(".//td");

                //时间
                string time = tdNodes[0].FirstChild.InnerText.Trim();
                //string datetime = tdNodes[0].SelectSingleNode("./span").InnerText.Trim();

                //分类
                string category     = tdNodes[1].SelectSingleNode("./a//font").InnerText.Trim();
                string categoryHref = tdNodes[1].SelectSingleNode("./a").Attributes["href"].Value;
                string categoryId   = categoryHref.Substring(categoryHref.LastIndexOf("/")).Replace("/", "");

                //团队
                HtmlNode teamNode = tdNodes[2].SelectSingleNode("./span/a");
                string   team     = "";
                string   teamHref = "";
                string   teamId   = "";
                if (teamNode != null)
                {
                    team = teamNode.InnerText.Trim();

                    teamHref = teamNode.Attributes["href"].Value.Trim();
                    teamId   = teamHref.Substring(teamHref.LastIndexOf("/")).Replace("/", "");
                }

                //番剧相关
                string title  = tdNodes[2].SelectSingleNode("./a").InnerText.Trim();
                string htmlId = tdNodes[2].SelectSingleNode("./a").Attributes["href"].Value.Replace(".html", "");
                htmlId = htmlId.Substring(htmlId.LastIndexOf("/") + 1);
                string    downloadArrow = tdNodes[3].SelectSingleNode("./a").Attributes["href"].Value;
                string    size          = tdNodes[4].InnerText;
                string    userName      = tdNodes[8].InnerText;
                string    userId        = tdNodes[8].SelectSingleNode("./a").Attributes["href"].Value.Replace("/topics/list/user_id/", "");
                DCategory dCategory     = new DCategory()
                {
                    Id   = long.Parse(categoryId),
                    Name = category
                };

                DTeam dTeam = new DTeam()
                {
                    Id   = string.IsNullOrEmpty(teamId) ? null : (long?)long.Parse(teamId),
                    Name = team
                };

                models.Add(new DPost
                {
                    Id            = Guid.NewGuid().ToString(),
                    UserId        = Convert.ToInt64(userId),
                    UserName      = userName,
                    Category      = dCategory,
                    DateTime      = time,
                    DownloadArrow = downloadArrow,
                    FileSize      = size,
                    Team          = dTeam,
                    Title         = title,
                    HtmlId        = htmlId
                });
            }

            return(models.ToArray());
        }
コード例 #10
0
        private DPostDetailed ToDetailedModel(string html)
        {
            try
            {
                DPostDetailed model = new DPostDetailed();


                HtmlDocument doc = new HtmlDocument();
                doc.LoadHtml(html);

                HtmlNode contentNode = doc.DocumentNode.SelectSingleNode("//div[@class='topic-main']");

                if (contentNode == null)
                {
                    return(null);
                }

                //用户和组相关
                DPostDetailedTeam team = new DPostDetailedTeam();
                DPostDetailedUser user = new DPostDetailedUser();

                HtmlNodeCollection userSidebar  = doc.DocumentNode.SelectNodes("/html/body/div/div/div[2]/div[7]/div[1]/div[@class='avatar box ui-corner-all']");
                HtmlNode           userInfoNode = userSidebar[0];

                //发布人头像
                user.UserAvatarImg = userInfoNode.SelectSingleNode("./p[1]/img").Attributes["src"].Value;
                //发布姓名
                user.UserName = userInfoNode.SelectSingleNode("./p[2]/a").InnerText;
                //发布人Id
                user.UserId = userInfoNode.SelectSingleNode("./p[2]/a")
                              .Attributes["href"].Value.Replace("/topics/list/user_id/", "");


                if (userSidebar.Count >= 2)
                {
                    HtmlNode teamNode = userSidebar[1];
                    team.TeamLogoUrl = teamNode.SelectSingleNode("./p[1]/img").Attributes["src"].Value;
                    team.TeamName    = teamNode.SelectSingleNode("./p[2]/a").InnerText;
                    team.TeamId      = teamNode.SelectSingleNode("./p[2]/a")
                                       .Attributes["href"].Value.Replace("/topics/list/team_id/", "");
                }


                //标题相关
                HtmlNode tiltleNode = contentNode.SelectSingleNode("./div[@class]");

                string title = tiltleNode.SelectSingleNode("./h3").InnerText;

                //分类
                HtmlNode categoryNode = tiltleNode.SelectSingleNode("./div/ul/li/span/a[last()]");
                string   category     = categoryNode.InnerText.Trim();
                string   categoryHref = categoryNode.Attributes["href"].Value;
                string   categoryId   = categoryHref.Substring(categoryHref.LastIndexOf("/")).Replace("/", "");

                string datetime = tiltleNode.SelectSingleNode("./div/ul/li[2]/span").InnerText.Trim();

                //如果出现修改时间的话节点不是第四个
                HtmlNode sizeNode = tiltleNode.SelectSingleNode("./div/ul/li[4]/span");
                if (sizeNode == null)
                {
                    sizeNode = tiltleNode.SelectSingleNode("./div/ul/li[5]/span");
                }

                string size = sizeNode.InnerText.Trim();

                //文章内容
                string content = contentNode.SelectSingleNode("./div[2]").InnerHtml.Trim().Replace("<strong>簡介:&nbsp;</strong><br>", "");

                //BT链接
                //Dictionary<string, string> btDic = new Dictionary<string, string>();

                List <object> btList = new List <object>();

                var btNodes = doc.DocumentNode.SelectNodes("//div[@id='resource-tabs']/div[@id='tabs-1']//strong");

                foreach (var btNode in btNodes)
                {
                    var    aNode = btNode.SelectSingleNode("./following-sibling::a");
                    string name  = aNode.InnerText;
                    string href  = aNode.Attributes["href"].Value == "#" ? name : aNode.Attributes["href"].Value;
                    btList.Add(new { Name = name, Href = href });
                    //btDic[name] = href;
                }

                //BT 详细
                List <object> btContentDict  = new List <object>();
                var           btContentNodes = doc.DocumentNode.SelectNodes("//div[@id='resource-tabs']/div[@id='tabs-1']/div[@class]/ul/li");

                if (btContentNodes.Count() > 0)
                {
                    foreach (var btContentNode in btContentNodes)
                    {
                        string name   = btContentNode.SelectSingleNode("./img").NextSibling.InnerText.Trim();
                        string btSize = btContentNode.SelectSingleNode("./span").InnerText.Trim();
                        btContentDict.Add(new { Name = name, FileSize = btSize });
                        //btContentDict[name] = btSize;
                    }
                }


                DCategory dCategory = new DCategory()
                {
                    Id   = long.Parse(categoryId),
                    Name = category
                };

                DPost post = new DPost()
                {
                    Id       = Guid.NewGuid().ToString(),
                    Category = dCategory,
                    DateTime = datetime,
                    FileSize = size,
                    Title    = title,
                };

                model = new DPostDetailed()
                {
                    User          = user,
                    Team          = team,
                    Post          = post,
                    Content       = content,
                    BTDict        = btList.ToArray(),
                    BTContentDict = btContentDict.ToArray()
                };

                return(model);
            }
            catch (Exception e)
            {
                throw new Exception($"在分析数据时发生错误:{e.Message}");
            }
        }