public List<Show> Load() { var showDictionary = new Dictionary<string, Show>(); Dictionary<string, Show> pageShows; int pageNumber = 0; do { pageShows = LoadPage(GetPageUrlByNumber(pageNumber)); foreach (var show in pageShows) { if (showDictionary.ContainsKey(show.Key)) { // Remove duplicates from series list var episodes = show.Value.Episodes.Except(showDictionary[show.Key].Episodes); foreach (var episode in episodes) { showDictionary[show.Key].Episodes.Add(episode); } } else { showDictionary.Add(show.Key, show.Value); } } pageNumber++; } while (pageShows.Count != 0); var result = showDictionary.Values.ToList(); UpdateLastLoadedEpisodeId(result); return result; }
public List<Show> Load() { bool stop; Dictionary<string, Show> showDictionary = new Dictionary<string, Show>(); int pageNumber = 0; do { Dictionary<string, Show> shows; stop = LoadPage(GetPageUrlByNumber(pageNumber), out shows); foreach (var show in shows) { if (showDictionary.ContainsKey(show.Key)) { //Remove duplicates from series list var seriesList = show.Value.Episodes.Except(showDictionary[show.Key].Episodes); showDictionary[show.Key].Episodes.AddRange(seriesList); } else { showDictionary.Add(show.Key, show.Value); } } pageNumber++; } while (!stop); List<Show> result = showDictionary.Select(s => s.Value).ToList(); if (result.Count != 0) { LastId = result.Aggregate( new List<Episode>(), (list, show) => { list.AddRange(show.Episodes); return list; } ).OrderByDescending(s => s.SiteId).First().SiteId; } return result; }
protected override Dictionary<string, Show> LoadPage(string url) { var doc = DownloadDocument(url).Result; string[] showTitles; string[] episodesTitles; string[] episodesIds; Tuple<int, int>[] episodesNumbers; bool success = GetEpiodesData(doc, out showTitles, out episodesTitles, out episodesIds, out episodesNumbers); if (!success) { throw new ArgumentException("Invalid web page", nameof(doc)); } var dateList = doc.DocumentNode.SelectNodes(@"//div[@class='mid']//div[@class='content_body']").First()?.InnerHtml; var dates = dateList != null ? DateRegex.Matches(dateList).Cast<Match>().Select(m => m.Groups[1].Value).ToArray() : null; var showDictionary = new Dictionary<string, Show>(); for (int i = 0; i < showTitles.Length; i++) { var episode = CreateEpisode(episodesIds[i], episodesTitles[i], dates?[i], episodesNumbers[i]); if (episode == null) { break; } if (!showDictionary.ContainsKey(showTitles[i])) { showDictionary.Add(showTitles[i], new Show { Title = showTitles[i], SiteTypeId = ShowsSiteType.Id }); } showDictionary[showTitles[i]].Episodes.Add(episode); } return showDictionary; }
private bool ParseDacl(RawAcl acl, Dictionary<string, AccessRightInfo> list, StringBuilder buffer, StringBuilder domainBuffer, StringBuilder userBuffer) { try { foreach (var ace in acl) { var k = ace as KnownAce; if (k == null || k.SecurityIdentifier == null) continue; var username = UserWithDomain(k.SecurityIdentifier, buffer, domainBuffer, userBuffer); var aceType = k.AceType.ToString(); var aceFlags = k.AceFlags.ToString(); foreach (var key in AccessMasks.Keys) { if ((key & k.AccessMask) == key) { var dKey = username + "-" + aceType + "-" + AccessMasks[key]; if (!list.ContainsKey(dKey)) { list[dKey] = new AccessRightInfo() { AceFlags = aceFlags, AceType = aceType, Right = AccessMasks[key], Trustee = username }; } } } } return true; } catch { } return false; }
private bool Parse(HtmlDocument document, out Dictionary<string, Show> result) { if (document == null) { throw new ArgumentNullException(nameof(document)); } var showTitles = document.DocumentNode.SelectNodes(@"//div[@class='mid']//div[@class='content_body']//a//img") ?.Select(s => s?.Attributes["title"]?.Value?.Trim()) .ToArray(); var seriesTitles = document.DocumentNode.SelectNodes(@"//div[@class='mid']//div[@class='content_body']//span[@class='torrent_title']//b") ?.Select(s => s?.InnerText?.Trim()) .ToArray(); var episodesIds = document.DocumentNode.SelectNodes(@"//div[@class='mid']//div[@class='content_body']//a[@class='a_details']") ?.Select( s => s?.Attributes["href"] != null ? IdRegex.Match(s.Attributes["href"].Value).Groups[1].Value : null) .ToArray(); if (showTitles == null || seriesTitles == null || episodesIds == null) { throw new ArgumentException("Invalid web page", nameof(document)); } var dateList = document.DocumentNode.SelectNodes(@"//div[@class='mid']//div[@class='content_body']") ?.First()?.InnerHtml; var dates = dateList != null ? DateRegex.Matches(dateList) : null; Dictionary<string, Show> showDictionary = new Dictionary<string, Show>(); bool stop = false; for (int i = 0; i < showTitles.Length; i++) { int episodeId; try { episodeId = int.Parse(episodesIds[i]); } catch (Exception e) { Program.Logger.Error(e, $"An error occurred while converting EpisodeId: {episodesIds[i]}"); continue; } if (episodeId <= LastId) { stop = true; break; } DateTimeOffset? date = null; if (dates != null) { DateTime tempDateTime; if (DateTime.TryParse(dates[i].Groups[1].Value, out tempDateTime)) { date = new DateTimeOffset(tempDateTime, SiteTimeZoneInfo.BaseUtcOffset); } } if (!showDictionary.ContainsKey(showTitles[i])) { showDictionary.Add(showTitles[i], new Show { Title = showTitles[i] }); } showDictionary[showTitles[i]].Episodes.Add( new Episode { SiteId = episodeId, Title = seriesTitles[i], Date = date } ); } result = showDictionary; return stop; }
/// <summary> /// ����ֵ��� /// </summary> /// <param name="tableName"></param> /// <param name="keyName"></param> /// <param name="valueName"></param> /// <param name="hasNull"></param> /// <param name="wheresql"></param> /// <returns></returns> public Dictionary<string, int?> GetParentDirectionary(string tableName, string keyName, string valueName, bool hasNull, string wheresql) { Dictionary<string, int?> directionary = new Dictionary<string, int?>(); if (hasNull) { directionary.Add("", null); } StringBuilder strSql = new StringBuilder(string.Format("SELECT {0},{1} FROM {2} {3} {4}", keyName, valueName, tableName, wheresql, " ORDER BY " + valueName)); using (DbDataReader dr = dbHelper.ExecuteReader(CommandType.Text, strSql.ToString(), null)) { while (dr.Read()) { string key = GetString(dr[keyName]); int? value = GetInt(dr[valueName]); if (!directionary.ContainsKey(key)) { directionary.Add(key, value); } } } return directionary; }
protected override Dictionary<string, Show> LoadPage(string url) { var doc = DownloadDocument(url).Result; var episodeNodes = doc.DocumentNode.SelectNodes(@"//table[@class='table well well-small']//a[@class='genmed']"); var dateNodes = doc.DocumentNode.SelectNodes(@"//table[@class='table well well-small']//td[@class='row4 small']"); var episodes = new HashSet<Tuple<string, int, int>>(); var showDictionary = new Dictionary<string, Show>(); for (int i = 0; i < episodeNodes.Count; i++) { var currentNode = episodeNodes[i]; var detailsUrl = SiteUrl + currentNode.Attributes["href"].Value; var showTitle = GetShowTitle(currentNode); if (IsAlreadyAdded(currentNode, showTitle, ref episodes)) { continue; } var episode = CreateEpisode(currentNode, detailsUrl, dateNodes[i]); if (episode == null) { break; } if (!showDictionary.ContainsKey(showTitle)) { showDictionary.Add(showTitle, new Show { Title = showTitle, SiteTypeId = ShowsSiteType.Id }); } showDictionary[showTitle].Episodes.Add(episode); } return showDictionary; }