/// <summary> /// 検索メソッドコア /// </summary> /// <returns>結果を列挙したListViewItem[]</returns> private async Task <ListViewItem[]> SearchCore(string searchAddress) { return(await AwaitSet.Awaitable <ListViewItem[]> .Run(() => { Common.HttpClient hc = new Common.HttpClient(searchAddress); hc.Encoding = "UTF-8"; hc.IsOtherSiteRequest = true; ListViewItem[] liCollection = null; int i = 0; HtmlAgilityPack.HtmlDocument hdc = new HtmlAgilityPack.HtmlDocument(); string data = hc.GetStringSync(); hdc.LoadHtml(data); HtmlAgilityPack.HtmlNodeCollection nodes = hdc.DocumentNode.SelectNodes("/html[1]/body[1]/ul[1]/li"); liCollection = new ListViewItem[nodes.Count]; foreach (var item in nodes) { HtmlAgilityPack.HtmlDocument hd = new HtmlAgilityPack.HtmlDocument(); hd.LoadHtml(item.InnerHtml); var title = hd.DocumentNode.SelectSingleNode("/a[1]").InnerText; var resCount = Re.Replace(hd.DocumentNode.SelectSingleNode("/span[1]").InnerText, "\\D", ""); var readUrl = hd.DocumentNode.SelectSingleNode("/a[1]").Attributes["href"].Value; var url = VIPBrowserLibrary.Common.URLParse.ReadcgiToDat(readUrl, VIPBrowserLibrary.Common.TypeJudgment.BBSTypeJudg(readUrl)); var ma = Re.Match(url, @"(http://\w+[.]\w+[.]\w+/\w+/dat/(?<num>\d{9,10}).dat|http://.+?/\w+?/.+?/\w+?/(?<num>\d{9,10})/)", System.Text.RegularExpressions.RegexOptions.Compiled).Groups["num"].Value; var standtime = Chron.Calture.UnixTimeToDateTime(ma); ulong speed = Chron.Calture.ThreadAuthority(standtime, resCount); var lvi = new ListViewItem(new string[] { (i + 1).ToString(), title, resCount, standtime.ToString(), speed.ToString() }); lvi.ImageKey = url; liCollection[i] = lvi; i++; } //Mc mc = Re.Matches(data, @"<dt><a\shref=""(?<readurl>http://\w+[.]\w+[.]\w+/test/read.cgi/\w+/\d{9,10}/)\d{1,3}-\d{1,3}"">(?<threadName>.{1,50})</a>\s[(](?<resCount>\d+)[)]\s-\s<font\ssize=-1><a\shref=http://\w+.\w+.\w+/\w+/>.+</a>.+</font></dt>", System.Text.RegularExpressions.RegexOptions.Compiled); //foreach (System.Text.RegularExpressions.Match m in mc) //{ // //string ma = Re.Match(m.Groups["readurl"].Value, @"http://\w+[.]\w+[.]\w+/test/read.cgi/\w+/(?<num>\d{9,10})/", System.Text.RegularExpressions.RegexOptions.Compiled).Groups["num"].Value; // //DateTime standtime = Chron.Calture.UnixTimeToDateTime(ma); // //ulong speed = Chron.Calture.ThreadAuthority(standtime,m.Groups["resCount"].Value); // //ListViewItem lvi = new ListViewItem(new string[] { (i + 1).ToString(),m.Groups["threadName"].Value,m.Groups["resCount"].Value ,standtime.ToString(),speed.ToString()}); // //lvi.ImageKey = VIPBrowserLibrary.Common.URLParse.ReadcgiToDat(m.Groups["readurl"].Value, VIPBrowserLibrary.Common.BBSType._2ch); // //liCollection[i] = lvi; // i++; //} return liCollection; })); }
private void GetSecretKey() { BBS.Common.HttpClient hc = new Common.HttpClient(String.Format(FormatRequestAddress, this.User, this.Password)); hc.IsOtherSiteRequest = true; string data = hc.GetStringSync(); this.SecretKey = data.Replace("SESSION-ID=", ""); var str = File.Create(Ronin.RoninSettingPath); Chron.Serializer.Serialize <RoninUserData>(new RoninUserData() { LastGetSecretKeyTime = DateTime.Now.ToString(), SecretKey = this.SecretKey, Password = this.Password, UserName = this.User }, str, Chron.SerializeType.BinarySerialize); str.Dispose(); }
private string GetResponses() { //int time = 0; System.Diagnostics.Stopwatch t = new System.Diagnostics.Stopwatch(); //Console.WriteLine("Start Response Analysis"); strb.Append("\""); strb.Append(readCgiUrl); strb.Append("\">\n</head>"); if (GetUrl == null) { return(null); } //strb.Clear(); id.Clear(); int IDdebugCount = 0; int DatadebugCount = 0; VIPBrowserLibrary.BBS.Common.HttpClient hc = new Common.HttpClient(GetUrl); string getData = hc.GetStringSync(); if (!System.IO.Directory.Exists(gs.DatFilePath + "\\" + datFolder)) { System.IO.Directory.CreateDirectory(gs.DatFilePath + "\\" + datFolder); } Utility.TextUtility.Write(gs.DatFilePath + "\\" + datFolder + "\\" + datKey + ".dat", getData, false); //Utility.TextUtility.Write(gs.DatFilePath + "\\" + datFolder + "\\" + datKey + ".idx", getData, false); t.Start(); MatchCollection threadDataCollection = new Regex(@"(?<name>.*)<>(?<mail>.*)<>(?<date>.*?)((?<ID>ID:.*?|発信元:.*?|))(?<BE>BE:.*?)?<>(?<sentence>.*)<>(?<threadName>.*)\n", RegexOptions.Compiled).Matches(getData); foreach (Match ids in threadDataCollection) { IDdebugCount++; if (id[ids.Groups["ID"].Value] == null) { id.Add(ids.Groups["ID"].Value, new int[] { 0, 1 }); } else { ((int[])id[ids.Groups["ID"].Value])[1] = ((int[])id[ids.Groups["ID"].Value])[1] + 1; } } foreach (Match item in threadDataCollection) { DatadebugCount++; resCount++; if (!String.IsNullOrEmpty(item.Groups["threadName"].Value)) { threadName = item.Groups["threadName"].Value; } ((int[])id[item.Groups["ID"].Value])[0] = ((int[])id[item.Groups["ID"].Value])[0] + 1; string idString; if (((int[])id[item.Groups["ID"].Value])[1] > 1) { idString = "<span style='color:#00F; text-decoration:underline;'>" + item.Groups["ID"].Value + "</span>" + " [" + ((int[])id[item.Groups["ID"].Value])[0] + "/" + ((int[])id[item.Groups["ID"].Value])[1] + "]"; } else if (((int[])id[item.Groups["ID"].Value])[1] > 3) { idString = "<span style='color:#F00; text-decoration:underline;'>" + item.Groups["ID"].Value + "</span>" + " [" + ((int[])id[item.Groups["ID"].Value])[0] + "/" + ((int[])id[item.Groups["ID"].Value])[1] + "]"; } else if (((int[])id[item.Groups["ID"].Value])[1] == 1) { idString = "<span style='color:#000; text-decoration:underline;'>" + item.Groups["ID"].Value + "</span>" + " [" + ((int[])id[item.Groups["ID"].Value])[0] + "/" + ((int[])id[item.Groups["ID"].Value])[1] + "]"; } else { idString = "<span style='color:#000; text-decoration:underline;'>" + item.Groups["ID"].Value + "</span>"; } if (item.Groups["ID"].Value.Length <= 8) { idString = "<span style='color:#000; text-decoration:underline;'>" + item.Groups["ID"].Value + "</span>"; } strb.Append(" <body bgcolor='#efefef'><font face='MS Pゴシック'>\n"); strb.Append(" <div style='margin-left:10px;'><span style='color:#00F; text-decoration:underline'>"); strb.Append(resCount.ToString()); strb.Append("</span>"); strb.Append(" :<font color=#008800><b>"); strb.Append(item.Groups["name"].Value); strb.Append("</b></font>["); string mail; Match mmm = new Regex(@"(?<date>.*)", RegexOptions.Compiled).Match(item.Groups["mail"].Value); if (mmm.Success) { mail = mmm.Groups["date"].Value; mail = mail.Replace("sage", "↓"); } else { mail = item.Groups["mail"].Value; } strb.Append((mail == "↓" ? "<span style='color:#F00;'>" + mail + "</span>" : mail)); strb.Append("]"); strb.Append(item.Groups["date"].Value); strb.Append(" "); //strb.Append("<span style='text-decoration:underline;'>ID:</span>"); strb.Append(idString); strb.Append("</div><div style='margin-left:25px;'>"); strb.Append(item.Groups["BE"].Value); strb.Append("<br>"); strb.Append(item.Groups["sentence"].Value); strb.Append("<br><br></div>\n"); //Console.WriteLine("ResCount : "+resCount.ToString()); } strb.Append("</font></body></html>"); t.Stop(); Console.WriteLine(t.ElapsedMilliseconds); resCount = 0; string datFile = strb.ToString(); strb.Clear(); Console.WriteLine("End the Res Analysis"); return(datFile); }
private string GetResponses(Regex re) { resCount++; Console.WriteLine("Start Response Analysis"); if (Url == null) { throw new ArgumentNullException("取得先のURLが指定されていません"); } if (Url == String.Empty) { throw new ArgumentException("取得先のURLは無効です"); } //strb.Clear(); id.Clear(); VIPBrowserLibrary.BBS.Common.HttpClient hc = new Common.HttpClient(Url); string getData = GetData = hc.GetStringSync(); if (!System.IO.Directory.Exists(gs.DatFilePath + "\\" + DatFolder)) { System.IO.Directory.CreateDirectory(gs.DatFilePath + "\\" + DatFolder); } Utility.TextUtility.Write(gs.DatFilePath + "\\" + DatFolder + "\\" + DatKey + ".dat", getData, false); //Utility.TextUtility.Write(gs.DatFilePath + "\\" + datFolder + "\\" + datKey + ".idx", getData, false); getData = Regex.Replace(getData, @"[<]a href.{1,100}\starget=""_blank""[>]", "", RegexOptions.Compiled).Replace("</a>", ""); MatchCollection mc = re.Matches(getData); StringBuilder sb = new StringBuilder("<html><head></head><body><font face=\"MS Pゴシック\">\n<dl>\n"); foreach (Match ids in mc) { string idData = ids.Groups["ID"].Value; if (id[idData] == null) { id.Add(idData, new int[] { 0, 1 }); } else { ((int[])id[idData])[1] = ((int[])id[idData])[1] + 1; } } threadName = mc[0].Groups["threadName"].Value; r = new Chron.ThreadOrResData.Res[mc.Count]; foreach (Match m in mc) { string idData = m.Groups["ID"].Value; ((int[])id[idData])[0] = ((int[])id[idData])[0] + 1; string idString; string data = ((int[])id[idData])[0] + "/" + ((int[])id[idData])[1]; if (((int[])id[idData])[1] > 1) { //idString = "<span style='color:#00F; text-decoration:underline;'>" + idData + "</span>" + " [" + ((int[])id[idData])[0] + "/" + ((int[])id[idData])[1] + "]"; idString = String.Format(@"<a href=""method:Extract($3,{0})"" style=""color:black;"" target=""_blank"">{0}</a>({1})", idData, data); } else if (((int[])id[idData])[1] > 3) { // idString = "<span style='color:#F00; text-decoration:underline;'>" + idData + "</span>" + " [" + ((int[])id[idData])[0] + "/" + ((int[])id[idData])[1] + "]"; idString = String.Format(@"<a href=""method:Extract($3,{0})"" style=""color:black;"" target=""_blank"">{0}</a>({1})", idData, data); } else if (((int[])id[idData])[1] == 1) { // idString = "<span style='color:#000; text-decoration:underline;'>" + idData + "</span>" + " [" + ((int[])id[idData])[0] + "/" + ((int[])id[idData])[1] + "]"; idString = String.Format(@"<a href=""method:Extract($3,{0})"" style=""color:black;"" target=""_blank"">{0}</a>({1})", idData, data); } else { idString = "<span style='color:#000; text-decoration:underline;'>" + idData + "</span>"; } //if (idData.Length <= 8) //{ // idString = "<span style='color:#000; text-decoration:underline;'>" + idData + "</span>"; //} string mail; Match mmm = new Regex(@"(?<date>.*)", RegexOptions.Compiled).Match(m.Groups["mail"].Value); if (mmm.Success) { mail = mmm.Groups["date"].Value; mail = mail.Replace("sage", "↓"); } else { mail = m.Groups["mail"].Value; } string sentenceData = m.Groups["sentence"].Value; sentenceData = Regex.Replace(sentenceData, @">>(?<res>\d+)", (d) => { return("<a href=\"#\">>>" + d.Groups["res"].Value + "</a>"); }); r[resCount - 1] = new Chron.ThreadOrResData.Res(resCount, m.Groups["name"].Value, m.Groups["mail"].Value, m.Groups["sentence"].Value, m.Groups["ID"].Value.Replace("ID:", "").Replace("発信元", ""), m.Groups["date"].Value, String.Empty, true); sb.Append("<dt id=\"s").Append(resCount).Append("\" class=\"\">"); sb.Append("<indices id=\"").Append(resCount).Append("\"></indices>"); sb.AppendFormat(@"<b><a href=""menu:{0}"" name=""{0}"" target=""_blank"">{0}</a></b>", resCount); sb.AppendFormat(@" 名前:<font color=""green""><b>{0}</b></font>", m.Groups["name"].Value); sb.AppendFormat(@" [{0}] ", mail); sb.AppendFormat(@"投稿日:{0} ", m.Groups["date"].Value); sb.Append(/*@"<a href=""method:Extract($3,{0})"" style=""color:black;"" target=""_blank"">{1}</a>", idData, */ idString); sb.AppendFormat(@" <a href=""method:Extract($5,)"" style=""color:black;"" target=""_blank""></a> </dt><dd>{0}<br><br></dd>", sentenceData); sb.AppendLine(); resCount++; } sb.Append("</html>"); resCount = 0; string datFile = sb.ToString(); sb.Clear(); Console.WriteLine("End the Res Analysis"); return(datFile); }