public ThreadFlipModel(FlipView MainFlip, Ita Ita) { this.MainFlip = MainFlip; this.Ita = Ita; this.Role = ItaListPageViewModel.FlipRole.ThreadList; ThreadList = new ObservableCollection <Thread>(); ReloadThreadList(); }
public async Task <ObservableCollection <Thread> > GetThreadList(Ita ita, ObservableCollection <Thread> ThreadList) { var uri = ita.GetThreadListUri(); var html = await GetHtmlFromUri(uri); var doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(html); var smalls = doc.DocumentNode.Descendants("small"); var small = (from item in smalls where (from innerItem in item.Attributes where innerItem.Name == "id" select innerItem.Value).FirstOrDefault() == "trad" select item).FirstOrDefault(); if (small != null) { var atags = small.InnerHtml.Replace("<a", "|<a").Split('|'); foreach (var atag in atags) { var regex = new Regex("<a href=\"(?<url>.*?)\".*?>(?<number>\\d*?): (?<text>.*?) \\((?<count>\\d*?)\\)</a>"); var match = regex.Match(atag); var url = match.Groups["url"].Value; var number = match.Groups["number"].Value; var text = match.Groups["text"].Value; var count = match.Groups["count"].Value; if (!string.IsNullOrEmpty(url)) { var newThread = new Thread(WebUtility.HtmlDecode(text), url.Replace("/l50", ""), int.Parse(number), ita, int.Parse(count)); newThread.Ita = ita; newThread.ItaId = ita.ItaId; ThreadList.Add(newThread); } } return(ThreadList); } throw new Exception("スレッド一覧のパースに失敗しました。"); }