public void Process(BaseData data) { BRData bd = data as BRData; string txt; if (!HtmlDecode(bd.Html, out txt)) { return; } var xml = new XmlHelper(txt); var cdataFlag = "//c"; var cdata = xml.GetValue(cdataFlag); if (string.IsNullOrEmpty(cdata)) { return; } var root = GetHtmlRoot(cdata); var jd2 = root.SelectSingleNode("//li[@class='topelem sport-1']/ul[@class=' jdlvl_2']"); List <HtmlNode> needNodes = new List <HtmlNode>(); foreach (var c2 in jd2.ChildNodes) { needNodes.Clear(); var cs = c2.ChildNodes[0]; var cc = cs.Attributes["href"]; // 大洲的信息 string continentId; string continentName; if (cc == null) { continentId = "7"; continentName = cs.InnerText; } else { continentId = RegexGetStr(cs.Attributes["href"].Value, "22_", "',"); continentName = cs.InnerText; } var jd3 = c2.SelectSingleNode("ul[contains(@class,'jdlvl_3')]"); if (jd3 == null) { continue; } #region 国际,俱乐部 // 处理国际和俱乐部组织的联赛 Dictionary <string, List <string> > dic = new Dictionary <string, List <string> >() { { "4", new List <string>() }, { "393", new List <string>() } }; for (int i = 0; i < jd3.ChildNodes.Count; i++) { if (i % 3 == 2) { // 第二列国际 var n2 = jd3.ChildNodes[i - 1]; // 第三列俱乐部 var n3 = jd3.ChildNodes[i]; OrganizerEntity oe; if (i == 2) // 标题行的处理 { var key = "393"; oe = OrganizerEntityManager.AddOrGetCacheEntity <OrganizerEntity>(key); oe.OrganizerId = key; oe.OrganizerName = n3.ChildNodes[0].InnerText; oe.ContinentId = continentId; oe.ContinentName = continentName; key = "4"; oe = OrganizerEntityManager.AddOrGetCacheEntity <OrganizerEntity>(key); oe.OrganizerId = key; oe.OrganizerName = n2.ChildNodes[0].InnerText; oe.ContinentId = continentId; oe.ContinentName = continentName; continue; } // 各行数据的处理 // 解析第二列所有联赛Id var a2 = n2.ChildNodes[0].Attributes["href"]; if (a2 != null) { var seasonId = RegexGetStr(a2.Value, "seasonid','", "',"); if (string.IsNullOrEmpty(seasonId)) { continue; } LeagueEntity le = LeagueEntityManager.AddOrGetCacheEntity <LeagueEntity>(seasonId); le.LeagueName = n2.InnerText; le.AddSeasonId(seasonId, true); if (!string.IsNullOrEmpty(seasonId)) { dic["4"].Add(seasonId); } } // 解析第三列所有联赛Id var a3 = n3.ChildNodes[0].Attributes["href"]; if (a3 != null) { var seasonId = RegexGetStr(a3.Value, "seasonid','", "',"); if (string.IsNullOrEmpty(seasonId)) { continue; } LeagueEntity le = LeagueEntityManager.AddOrGetCacheEntity <LeagueEntity>(seasonId); le.LeagueName = n3.InnerText; le.AddSeasonId(seasonId, true); if (!string.IsNullOrEmpty(seasonId)) { dic["393"].Add(seasonId); } } } } foreach (var kv in dic) { var oe = OrganizerEntityManager.AddOrGetCacheEntity <OrganizerEntity>(kv.Key); var cpDic = oe.CompareSetSeasonIds(kv.Value); NextAssignTask(oe, cpDic); } #endregion #region 所有其他国家的数据 var ff3 = jd3.SelectNodes("li[@class='floater ']"); // 根节点中显示的组织数据,需要进一步循环获取组织数据 if (ff3 != null) { foreach (var l3 in ff3) { var jd4 = l3.SelectSingleNode("ul[@class=' jdlvl_4']"); if (jd4 == null) { // 其他组织的联赛上一步已经处理 continue; } needNodes.AddRange(jd4.ChildNodes); } } // 需要进一步处理的Organizers数据 for (int i = 0; i < needNodes.Count; i++) { var node = needNodes[i]; var a = node.ChildNodes[0]; var organizerId = RegexGetStr(a.Attributes["href"].Value, "3_", ","); var organizerName = a.InnerText; OrganizerEntity ent = OrganizerEntityManager.AddOrGetCacheEntity <OrganizerEntity>(organizerId); ent.ContinentId = continentId; ent.ContinentName = continentName; if (node.ChildNodes.Count < 3) { // 青年 continue; } ent.OrganizerId = organizerId; ent.OrganizerName = organizerName; var lis = node.ChildNodes[2].ChildNodes; var seasonIdlist = new List <string>(); var moreLis = new List <HtmlNode>(); // 更多业余的联赛 foreach (var li in lis) { var s = li.ChildNodes[0].Attributes["href"].Value; var seasonId = RegexGetStr(s, "seasonid','", "',"); if (string.IsNullOrEmpty(seasonId)) { moreLis.Add(li); needNodes.AddRange(moreLis); continue; } LeagueEntity le = LeagueEntityManager.AddOrGetCacheEntity <LeagueEntity>(seasonId); le.LeagueName = li.InnerText; le.AddSeasonId(seasonId, true); seasonIdlist.Add(seasonId); } var cpDic = ent.CompareSetSeasonIds(seasonIdlist); NextAssignTask(ent, cpDic); } #endregion } }
public override void InitCacheManager() { var organizerEntityManager = new OrganizerEntityManager(); IocUnity.RegisterInstance <ICacheManager>(typeof(OrganizerEntityManager).Name, organizerEntityManager); DicCacheManagers.Add(typeof(OrganizerEntityManager).Name, (ICacheManager)organizerEntityManager); var leagueEntityManager = new LeagueEntityManager(); IocUnity.RegisterInstance <ICacheManager>(typeof(LeagueEntityManager).Name, leagueEntityManager); DicCacheManagers.Add(typeof(LeagueEntityManager).Name, (ICacheManager)leagueEntityManager); var matchEntityManager = new MatchEntityManager(); IocUnity.RegisterInstance <ICacheManager>(typeof(MatchEntityManager).Name, matchEntityManager); DicCacheManagers.Add(typeof(MatchEntityManager).Name, (ICacheManager)matchEntityManager); var playerEntityManager = new PlayerEntityManager(); IocUnity.RegisterInstance <ICacheManager>(typeof(PlayerEntityManager).Name, playerEntityManager); DicCacheManagers.Add(typeof(PlayerEntityManager).Name, (ICacheManager)playerEntityManager); var playerPenaltiesManager = new PlayerPenaltiesManager(); IocUnity.RegisterInstance <ICacheManager>(typeof(PlayerPenaltiesManager).Name, playerPenaltiesManager); DicCacheManagers.Add(typeof(PlayerPenaltiesManager).Name, (ICacheManager)playerPenaltiesManager); var PlayerStatisticsRecordManager = new PlayerStatisticsRecordManager(); IocUnity.RegisterInstance <ICacheManager>(typeof(PlayerStatisticsRecordManager).Name, PlayerStatisticsRecordManager); DicCacheManagers.Add(typeof(PlayerStatisticsRecordManager).Name, (ICacheManager)PlayerStatisticsRecordManager); var playerTimeRecordManager = new PlayerTimeRecordManager(); IocUnity.RegisterInstance <ICacheManager>(typeof(PlayerTimeRecordManager).Name, playerTimeRecordManager); DicCacheManagers.Add(typeof(PlayerTimeRecordManager).Name, (ICacheManager)playerTimeRecordManager); var seasonEntityManager = new SeasonEntityManager(); IocUnity.RegisterInstance <ICacheManager>(typeof(SeasonEntityManager).Name, seasonEntityManager); DicCacheManagers.Add(typeof(SeasonEntityManager).Name, (ICacheManager)seasonEntityManager); var seasonTypeInfoManager = new SeasonTypeInfoManager(); IocUnity.RegisterInstance <ICacheManager>(typeof(SeasonTypeInfoManager).Name, seasonTypeInfoManager); DicCacheManagers.Add(typeof(SeasonTypeInfoManager).Name, (ICacheManager)seasonTypeInfoManager); var seasonTableInfoManager = new SeasonTableInfoManager(); IocUnity.RegisterInstance <ICacheManager>(typeof(SeasonTableInfoManager).Name, seasonTableInfoManager); DicCacheManagers.Add(typeof(SeasonTableInfoManager).Name, (ICacheManager)seasonTableInfoManager); var seasonTeamsManager = new SeasonTeamsManager(); IocUnity.RegisterInstance <ICacheManager>(typeof(SeasonTeamsManager).Name, seasonTeamsManager); DicCacheManagers.Add(typeof(SeasonTeamsManager).Name, (ICacheManager)seasonTeamsManager); var teamEntityManager = new TeamEntityManager(); IocUnity.RegisterInstance <ICacheManager>(typeof(TeamEntityManager).Name, teamEntityManager); DicCacheManagers.Add(typeof(TeamEntityManager).Name, (ICacheManager)teamEntityManager); var teamPlayersManager = new TeamPlayersManager(); IocUnity.RegisterInstance <ICacheManager>(typeof(TeamPlayersManager).Name, teamPlayersManager); DicCacheManagers.Add(typeof(TeamPlayersManager).Name, (ICacheManager)teamPlayersManager); }
public void Process(ITakerReptile.Dto.BaseData data) { BRData bd = data as BRData; MatchParam param = bd.Param as MatchParam; CheckSetHistoryParam(param); string txt; if (!HtmlDecode(bd.Html, out txt)) { return; } var xml = new XmlHelper(txt); // 解析成各个数据块 var cdataFlag = "//c"; var cdata = xml.GetValues(cdataFlag); // 获取历史赛季Id,添加到联赛任务,只抓取一次 var historySeasonIdData = GetDataLikeKey(cdata, "sb-wrapper", "lang-1"); var seasonIdList = new List <string>(); if (historySeasonIdData != null) { var rootHistory = GetHtmlRoot(historySeasonIdData); var ul = rootHistory.SelectSingleNode("//div[@class='sb-scrollbox']/ul"); foreach (var li in ul.ChildNodes) { var id = RegexGetStr(li.OuterHtml, "'5_", ","); seasonIdList.Add(id); var sp = param.CopyCreateParam <SeasonParam>(); sp.IsHistoryParam = true; sp.SeasonId = id; LeagueManager.AddOrUpdateParam(sp); } } if (!param.IsHistoryParam && seasonIdList.Any()) { var le = LeagueEntityManager.AddOrGetCacheEntity <LeagueEntity>(param.SeasonId); le.CompareSetSeasonIds(seasonIdList); } // 解析比赛 var matchData = GetDataLikeKey(cdata, "normaltable fixtures"); if (string.IsNullOrEmpty(matchData)) { return; } var root = GetHtmlRoot(matchData); bool isTitle = true; string round = ""; foreach (var node in root.ChildNodes) { switch (node.Name) { case "#text": continue; case "h2": if (isTitle) { isTitle = false; } else { round = node.InnerText; } continue; case "table": ParseMatch(round, node, param); continue; } } }