public async Task <string> GetVocsPopularityAndSort(string[] lines) { List <Voc> listVoc = new List <Voc>(); for (int i = 0; i < lines.Length; i++) { ChangeProgress(new Progress(i, lines.Length)); int id = int.Parse(Regex.Match(lines[i], "(?<=/vocs/)\\d+(?=/?)").Value); try { string page = await NetworkClient.DownloadstringAsync("http://klavogonki.ru/vocs/" + id + "/history/"); var mtch = Regex.Match(page, "<title>(.+) - Словари - Клавогонки(?:.|\n)+rating_cnt\">(\\d+)<(?:.|\n)+fav_cnt'>(\\d+)<"); string name = mtch.Groups[1].ToString(); int marks = int.Parse(mtch.Groups[2].ToString()); int inuse = int.Parse(mtch.Groups[3].ToString()); Voc voc = new Voc() { Text = lines[i], Id = id, Name = name, InUseCnt = inuse, MarksCnt = marks }; listVoc.Add(voc); } catch (Exception) { } } listVoc.Sort(); StringBuilder sb = new StringBuilder(); foreach (Voc voc in listVoc) { sb.Append(voc.Text); sb.Append("\r\n"); } ChangeProgress(new Progress(lines.Length, lines.Length)); return(sb.ToString()); }
public async Task UpdateList() { ChangeProgress(new Progress(0)); List <Voc> Vocs = new List <Voc>(); int counter = 1; for (var pageCnt = 1; pageCnt < 1500; pageCnt++) { ChangeProgress(new Progress(pageCnt, 0, Vocs.Count)); string page = await NetworkClient.DownloadstringAsync("http://klavogonki.ru/vocs/top/" + pageCnt); if (page.Contains("<p>Совпадений не найдено.</p>")) { break; } HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(page); var table = doc.DocumentNode.SelectSingleNode("//div[@class='content-col']/table"); if (table == null) { break; } var _vocs = table.SelectNodes("tr"); //// foreach (var v in _vocs) { Voc voc = new Voc(); voc.Position = counter++; var tdTitle = v.SelectSingleNode("td[@class='title']"); var _name = tdTitle.SelectSingleNode("a"); voc.Name = _name.InnerText.Replace("\t", " "); if (voc.Name.Length > 0 && voc.Name[0] == '"') { voc.Name = " " + voc.Name; } voc.Id = int.Parse(Regex.Match(_name.Attributes["href"].Value, "\\d+").Value); voc.Description = tdTitle.SelectSingleNode("div[@class='desc']").InnerText.Replace("\r", " ").Replace("\n", " ").Replace("\t", " "); if (voc.Description.Length > 0 && voc.Description[0] == '"') { voc.Description = " " + voc.Description; } var _author = tdTitle.SelectSingleNode("div[@class='author']/a"); voc.AuthorId = int.Parse(Regex.Match(_author.Attributes["href"].Value, "\\d+").Value); voc.AuthorNick = _author.InnerText; voc.MarksCnt = int.Parse(Regex.Match(tdTitle.SelectSingleNode("span").InnerText, "\\d+").Value); var tdSymbols = v.SelectSingleNode("td[@class='symbols']"); voc.Type = tdSymbols.SelectSingleNode("strong").InnerText.Trim(); string _symbols = tdSymbols.InnerText; int.TryParse(Regex.Match(_symbols, "\\d+(?= отрыв)").Value, out int snippets); int.TryParse(Regex.Match(_symbols, "\\d+(?= текст)").Value, out int texts); int.TryParse(Regex.Match(_symbols, "\\d+(?= фраз)").Value, out int phrases); int.TryParse(Regex.Match(_symbols, "\\d+(?= слов)").Value, out int words); if (int.TryParse(Regex.Match(_symbols, "\\d+(?= символ)").Value, out int symbolsCnt)) { voc.SymbolsCnt = symbolsCnt; } int first = snippets; if (first == 0) { first = texts; } if (first == 0) { first = phrases; } if (first == 0) { first = words; } voc.SnippetsCnt = first; Vocs.Add(voc); } VocsDB = Vocs; dataProvider.Save(VocsDB); ChangeProgress(new Progress(pageCnt, pageCnt, Vocs.Count)); } }
public Voc GetVocByName(string vocName) { Voc voc = VocsDB.Find(z => string.Equals(z.Name, vocName, StringComparison.OrdinalIgnoreCase)); return(voc); }
public Voc GetVocById(int vocId) { Voc voc = VocsDB.Find(z => z.Id == vocId); return(voc); }