/// <summary> /// Beにログインします /// </summary> /// <param name="mail">メールアドレス</param> /// <param name="password">パスワード</param> public async Task <bool> Login(string mail, string password) { string postData = String.Format("m={0}&p={1}&submit=%C5%D0%CF%BF", mail, password); CookieCollection cc = BBS.Common.HttpClient.CookieManagement.ReadCookieFromDisk(); Common.HttpClient hc = new Common.HttpClient("http://be.2ch.net/test/login.php"); hc.Cookies = new CookieCollection(); string data = await hc.PostStringAsync(postData); if (data.Contains("パスワードかメールアドレスが正しくないようです。")) { return(false); } int i = 0; foreach (Cookie item in hc.Cookies) { i++; } if (i == 0) { return(false); } cc.Add(hc.Cookies); Common.HttpClient.CookieManagement.WriteCookieToDisk(cc); Common.HttpClient.CookieManagement.RearrangeCookie(); return(true); }
/// <summary> /// まちBBSの板のアドレスを使用してMachiBBSThreadListReaderクラスの新しいインスタンスを初期化します /// </summary> /// <param name="boardAddress">取得する板のアドレス</param> public MachiBBSThreadListReader(string boardAddress) { Match m = Regex.Match(boardAddress, @"http://(?<host>\w+)[.]machi[.]to/(?<folder>\w+)/?", RegexOptions.Compiled); requestAddress = boardAddress; hc = new Common.HttpClient("http://" + m.Groups["host"].Value + ".machi.to" + "/bbs/offlaw.cgi/" + m.Groups["folder"].Value + "/"); }
/// <summary> /// レスを取得します /// </summary> /// <returns>取得し変換したHTML</returns> public async Task <string> GetResponse() { Common.HttpClient hc = new Common.HttpClient(GetUrl.Replace("read.cgi", "offlaw.cgi")); hc.Encoding = "Shift-JIS"; string data = await hc.GetStringAsync(); string fileDirectory = gs.DatFilePath + "\\" + datFolder; if (!Directory.Exists(fileDirectory)) { Directory.CreateDirectory(fileDirectory); } string filePath = fileDirectory + "\\" + datKey; Utility.TextUtility.Write(filePath + ".cgi", data, false); //FileInfo fi = new FileInfo(filePath + ".cgi"); long size = Encoding.GetEncoding("Shift-JIS").GetByteCount(data); string byteCount = Chron.Calture.DatSizeFormat(size, 1); string result = await AwaitSet.Awaitable <string> .Run(() => { return(base.GetResponse(data, new Regex(@"\d+<>(?<name>.*)<>(?<mail>.*)<>(?<date>.*?)((?<ID>ID:.*?|発信元:.*?|))<>(?<sentence>.*)<>(?<threadName>.*)\n", RegexOptions.Compiled), readCgiUrl, this.IsOutHtml)); }); this.resSets = base.ResSets; Chron.ThreadOrResData.ThreadData td = new Chron.ThreadOrResData.ThreadData(); td.ThisBBS = VIPBrowserLibrary.Common.BBSType.machibbs; if (File.Exists(filePath + ".xml")) { td = Chron.ThreadOrResData.ThreadDataWriterAndReader.Read(filePath + ".xml"); td.ThreadKey = datKey; td.ThreadAddress = GetUrl; td.DatSize = byteCount; td.ThreadName = threadName = base.ThreadName; td.GetRescount = base.ResCount; td.ThisFilePath = filePath; this.threadInfo = td; } else { td.ThreadKey = datKey; td.ThreadAddress = GetUrl; td.DatSize = byteCount; td.ThreadName = threadName = base.ThreadName; td.GetRescount = base.ResCount; td.ThisFilePath = filePath; this.threadInfo = td; } td.LastModified = hc.Headers["Last-Modified"]; Chron.ThreadOrResData.ThreadDataWriterAndReader.Write(td, filePath + ".xml"); return(result); //throw new NotImplementedException(); }
/// <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(); }
/// <summary> /// レスをしたらばに送信します /// </summary> /// <param name="postData">送信するデータを収めたDictionary<string,string></param> /// <param name="isThread">スレッドである場合はtrue,レスである場合はfalse</param> /// <param name="td">スレッドの情報</param> /// <returns>成功の可否</returns> public async Task <bool> PostJbbs(Dictionary <string, string> postData, bool isThread, Chron.ThreadOrResData.ThreadData td) { hc = new Common.HttpClient(hostAddress); bool isCan = false; hc.Encoding = "EUC-JP"; hc.Host = "jbbs.livedoor.jp"; hc.IsReadCookieFromHost = true; if (!isThread) { hc.Referer = "http://jbbs.shitaraba.net/bbs/read.cgi/" + postData["DIR"] + "/" + postData["BBS"] + "/" + postData["KEY"] + "/"; } else { hc.Referer = "http://jbbs.shitaraba.net/" + postData["DIR"] + "/" + postData["BBS"] + "/"; } StringBuilder sb = new StringBuilder(); foreach (KeyValuePair <string, string> item in postData) { sb.Append(item.Key); sb.Append("="); sb.Append(item.Value); sb.Append("&"); } if (isThread) { sb.Append("submit=新規スレッド作成"); } else { sb.Append("submit=書き込む"); } string postString = sb.ToString().TrimEnd('&'); string data = await hc.PostStringAsync(postString); if (data.Contains("書きこみました。")) { base.WriteRecords(postData, td); return(isCan = true); } return(isCan); }
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); }
/// <summary> /// スレッドのデータをダウンロードしてをHTML形式に変換します /// </summary> /// <returns>変換されたスレッドのHTML</returns> public async Task <string> GetResponse() { string fileDirectory = gs.DatFilePath + "\\" + datFolder; if (!System.IO.Directory.Exists(fileDirectory)) { System.IO.Directory.CreateDirectory(fileDirectory); } string filePath = fileDirectory + "\\" + datKey; string data = String.Empty; if (!GetUrl.Contains(gs.DatFilePath)) { Common.HttpClient hc = new Common.HttpClient(GetUrl); hc.Encoding = "EUC-JP"; data = await hc.GetStringAsync(); Utility.TextUtility.Write(filePath + ".cgi", data, false); //System.IO.FileInfo fi = new System.IO.FileInfo(filePath + ".cgi"); } else { data = System.IO.File.ReadAllText(GetUrl, Encoding.GetEncoding("Shift-JIS")); } long size = Encoding.GetEncoding("EUC-JP").GetByteCount(data); string byteCount = Chron.Calture.DatSizeFormat(size, 1); var result = await AwaitSet.Awaitable <string> .Run(() => { return(base.GetResponse(data, new Regex(@"\d{1,6}<>(?<name>.*)<>(?<mail>.*)<>(?<date>.*)<>(?<sentence>.+)<>(?<threadName>.*)<>(?<ID>.*)\n", RegexOptions.Compiled), readCgiUrl, this.IsOutHtml)); }); this.resSets = base.ResSets; Chron.ThreadOrResData.ThreadData td = new Chron.ThreadOrResData.ThreadData(); td.ThisBBS = VIPBrowserLibrary.Common.BBSType.jbbs; if (System.IO.File.Exists(filePath + ".xml")) { td = Chron.ThreadOrResData.ThreadDataWriterAndReader.Read(filePath + ".xml"); td.ThreadKey = datKey; td.ThreadAddress = GetUrl; td.DatSize = byteCount; td.ThreadName = threadName = base.ThreadName; td.GetRescount = base.ResCount; td.ThisFilePath = filePath; this.threadInfo = td; } else { td.ThreadKey = datKey; td.ThreadAddress = GetUrl; td.DatSize = byteCount; td.ThreadName = threadName = base.ThreadName; td.GetRescount = base.ResCount; td.ThisFilePath = filePath; this.threadInfo = td; } Chron.ThreadOrResData.ThreadDataWriterAndReader.Write(td, filePath + ".xml"); return(result); }
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); }
/// <summary> /// スレッドリストを取得する板のURLを指定してこのクラスの新しいインスタンスを初期化します /// </summary> /// <param name="boardAddress">板のアドレス</param> public X2chThreadListReader(string boardAddress) { hc = new Common.HttpClient(new Uri(boardAddress + "subject.txt")); requestAddress = boardAddress; }
/// <summary> /// このスレッドを取得して変換します /// </summary> /// <returns>変換したスレッドのUrl</returns> public async Task <string> GetResponse() { int range = 0; string fileDirectory = gs.DatFilePath + "\\" + datFolder; if (!System.IO.Directory.Exists(fileDirectory)) { System.IO.Directory.CreateDirectory(fileDirectory); } string filePath = fileDirectory + "\\" + datKey; bool isRefresh = System.IO.File.Exists(filePath + ".dat"); if (isRefresh) { Chron.ThreadOrResData.ThreadData tdd = Chron.ThreadOrResData.ThreadDataWriterAndReader.Read(filePath + ".xml"); if (!tdd.IsNullObject()) { range = tdd.DatByte; } } Common.HttpClient hc = null; long size = 0; string data = String.Empty; string etag = String.Empty; if (!GetUrl.Contains(gs.DatFilePath)) { hc = new Common.HttpClient(GetUrl); hc.UserAgent = "Monazilla/1.00(VIPBrowser ver 0.0.0.3)"; if (!isRefresh) { data = await hc.GetStringAsync(); } else { data = Utility.TextUtility.Read(filePath + ".dat", Encoding.GetEncoding("Shift-JIS")); hc.Range = range - 1; size = range; string get = await hc.GetStringAsync(); System.Net.HttpStatusCode hsc = hc.RequestStatusCode; switch (hsc) { case System.Net.HttpStatusCode.PartialContent: data += get; isRefresh = false; break; case System.Net.HttpStatusCode.NotModified: //size += 10; break; case System.Net.HttpStatusCode.RequestedRangeNotSatisfiable: hc.Range = 0; size = 0; data = await hc.GetStringAsync(); isRefresh = false; break; default: break; } etag = hc.Headers["ETag"]; } } else { data = System.IO.File.ReadAllText(GetUrl, Encoding.GetEncoding("Shift-JIS")); } Regex re = new Regex(@"(?<name>.*)<>(?<mail>.*)<>(?<date>.*?)((?<ID>ID:.*?|発信元:.*?|HOST:.*?|))(?<BE>BE:.*?)?<>(?<sentence>.*)<>(?<threadName>.*)\n", RegexOptions.Compiled); Utility.TextUtility.Write(filePath + ".dat", data, false); //System.IO.FileInfo fi = new System.IO.FileInfo(filePath + ".dat"); if (!isRefresh) { size = Encoding.GetEncoding("Shift-JIS").GetByteCount(data); } string byteCount = Chron.Calture.DatSizeFormat(size, 1); var result = await AwaitSet.Awaitable <string> .Run(() => { return(base.GetResponse(data, re, readCgiUrl, this.IsOutHtml)); }); if (result == null && (GetUrl.Contains(".2ch.net") || GetUrl.Contains(".bbspink.com")) && !GetUrl.Contains(gs.DatFilePath)) { //offlaw2.soによる過去ログスレ取得予定 hc = new Common.HttpClient(VIPBrowserLibrary.Common.URLParse.ReadcgiToOfflaw2(readCgiUrl)); hc.Referer = readCgiUrl; data = await hc.GetStringAsync(); result = await AwaitSet.Awaitable <string> .Run(() => { return(base.GetResponse(data, re, readCgiUrl)); }); result += "<br><center>---このスレは過去ログ化されています---</center>"; } this.resSets = base.ResSets; Chron.ThreadOrResData.ThreadData td = new Chron.ThreadOrResData.ThreadData(); td.ThisBBS = VIPBrowserLibrary.Common.BBSType._2ch; if (System.IO.File.Exists(filePath + ".xml")) { td = Chron.ThreadOrResData.ThreadDataWriterAndReader.Read(filePath + ".xml"); td.ThreadKey = datKey; td.ThreadAddress = GetUrl; td.DatSize = byteCount; td.ThreadName = threadName = base.ThreadName; td.GetRescount = base.ResCount; td.ThisFilePath = filePath; td.DatByte = (int)size; this.threadInfo = td; } else { td.ThreadKey = datKey; td.ThreadAddress = GetUrl; td.DatSize = byteCount; td.ThreadName = threadName = base.ThreadName; td.GetRescount = base.ResCount; td.ThisFilePath = filePath; this.threadInfo = td; td.DatByte = (int)size; } td.ETag = etag; Chron.ThreadOrResData.ThreadDataWriterAndReader.Write(td, filePath + ".xml"); return(result); }
/// <summary> /// 指定したURLを使用してJbbsThreadListReaderクラスの新しいインスタンスを初期化します /// </summary> /// <param name="url">初期化に使用する板名のURL</param> public JbbsThreadListReader(string url) { hc = new Common.HttpClient(url + "subject.txt"); Url = url; }
/// <summary> /// スレッド一覧を取得し、ListViewItem[]形式に変換します。 /// </summary> /// <param name="re">変換に用いるRegex</param> /// <param name="url">取得先のURL</param> /// <param name="hc">取得に用いる、HttpClientクラス</param> /// <returns>スレッド一覧を格納したListViewItem[]</returns> protected virtual async Task <System.Windows.Forms.ListViewItem[]> ParseThreadList(Regex re, string url, Common.HttpClient hc) { VIPBrowserLibrary.Common.BBSType bt; string datNameBase = String.Empty; Chron.ThreadOrResData.Abone.ThreadListAbone tla = new Chron.ThreadOrResData.Abone.ThreadListAbone(); tla.InstLoad(); Encoding enc; Setting.GeneralSetting gs = new Setting.GeneralSetting(); ListViewItem[] liCollection = null; try { string folder = String.Empty; string address = url.Replace("http://", "").TrimEnd('/'); if (address.IndexOf("jbbs.livedoor.jp") == -1 && address.IndexOf("jbbs.shitaraba.net") == -1) { string[] filePath = address.Split('/'); folder = gs.DatFilePath + "\\" + filePath[0] + "-" + filePath[1]; enc = Encoding.GetEncoding("Shift-JIS"); if (!address.Contains("machi.to")) { bt = VIPBrowserLibrary.Common.BBSType._2ch; datNameBase = url + "dat/"; } else { bt = VIPBrowserLibrary.Common.BBSType.machibbs; Match m = Regex.Match(url, @"http://(?<host>\w+)[.]machi[.]to/(?<folder>\w+)/?", RegexOptions.Compiled); datNameBase = "http://" + m.Groups["host"].Value + ".machi.to/bbs/offlaw.cgi/" + m.Groups["folder"].Value + "/"; hc.Host = m.Groups["host"].Value + ".machi.to"; } } else { address = address.Replace("jbbs.livedoor.jp", "").Replace("jbbs.shitaraba.net", "").TrimStart('/').Replace('/', '-'); folder = gs.DatFilePath + "\\" + "jbbs-" + address; enc = Encoding.GetEncoding("EUC-JP"); bt = VIPBrowserLibrary.Common.BBSType.jbbs; Match m = new Regex(@"http://jbbs.(shitaraba.net|livedoor.jp)/(?<category>.+)/(?<number>\d+)/").Match(url); datNameBase = String.Concat("http://jbbs.shitaraba.net/bbs/rawmode.cgi/", m.Groups["category"].Value, "/", m.Groups["number"].Value, "/"); } string getData = await hc.GetStringAsync(); if (!System.IO.Directory.Exists(folder)) { System.IO.Directory.CreateDirectory(folder); } MatchCollection mc = re.Matches(getData); liCollection = new ListViewItem[mc.Count]; int i = 1; Chron.ThreadOrResData.ThreadListItemColorRing cl = new Chron.ThreadOrResData.ThreadListItemColorRing(folder + "\\subject.txt"); bool isColorring = cl.IsNull; foreach (Match item in mc) { Chron.ThreadOrResData.ThreadData td = Chron.ThreadOrResData.ThreadDataWriterAndReader.Read(folder + "\\" + item.Groups["datName"].Value + ".xml"); //Console.WriteLine(item.Groups["threadTitle"].Value); Console.WriteLine(item.Groups["datName"].Value); Console.WriteLine(item.Groups["resCount"].Value); ListViewItem li = null; DateTime dt = Chron.Calture.UnixTimeToDateTime(item.Groups["datName"].Value); string resCount = item.Groups["resCount"].Value; if (td == null) { //li = new ListViewItem(new string[] //{ // " ", // (i++).ToString(), // Utility.StringUtility.HTMLDecode(item.Groups["threadTitle"].Value), // resCount, // dt.ToString(), // Chron.Calture.ThreadAuthority(dt,resCount).ToString(), // "0", // "0", // "0" //}); #region やっつけで書いた、後悔はしていない Sub read = new Sub(); read.Text = " "; read.Name = "IsRead"; Sub count = new Sub(); count.Text = i.ToString(); count.Name = "Count"; Sub name = new Sub(); name.Text = Utility.StringUtility.HTMLDecode(item.Groups["threadTitle"].Value); name.Name = "Name"; Sub res = new Sub(); res.Text = resCount.ToString(); res.Name = "ResCount"; Sub time = new Sub(); time.Text = dt.ToString(); time.Name = "Time"; Sub speed = new Sub(); speed.Text = Chron.Calture.ThreadAuthority(dt, resCount).ToString(); speed.Name = "Speed"; Sub size = new Sub(); size.Text = ""; size.Name = "Size"; Sub oldRes = new Sub(); oldRes.Text = ""; oldRes.Name = "OldResCount"; Sub newRes = new Sub(); newRes.Text = ""; newRes.Name = "NewResCount"; li = new ListViewItem(new Sub[] { read, count, name, res, time, speed, size, oldRes, newRes }, ""); #endregion } else { int newRes = (resCount.Parse() - (td.GetRescount - 1)); string isNewState = String.Empty; if (newRes == 0) { isNewState = "○"; } else { isNewState = "●"; } //li = new ListViewItem(new string[] //{ // isNewState, // (i++).ToString(), // Utility.StringUtility.HTMLDecode(item.Groups["threadTitle"].Value), // resCount, // dt.ToString(), // Chron.Calture.ThreadAuthority(dt,resCount).ToString(), // td.DatSize, // (td.GetRescount - 1).ToString(), // newRes.ToString() //}); #region やっつけで書いた、後悔はしていない Sub read = new Sub(); read.Text = isNewState; read.Name = "IsRead"; Sub count = new Sub(); count.Text = i.ToString(); count.Name = "Count"; Sub name = new Sub(); name.Text = Utility.StringUtility.HTMLDecode(item.Groups["threadTitle"].Value); name.Name = "Name"; Sub res = new Sub(); res.Text = resCount.ToString(); res.Name = "ResCount"; Sub time = new Sub(); time.Text = dt.ToString(); time.Name = "Time"; Sub speed = new Sub(); speed.Text = Chron.Calture.ThreadAuthority(dt, resCount).ToString(); speed.Name = "Speed"; Sub size = new Sub(); size.Text = td.DatSize; size.Name = "Size"; Sub oldRes = new Sub(); oldRes.Text = (td.GetRescount - 1).ToString(); oldRes.Name = "OldResCount"; Sub newRess = new Sub(); newRess.Text = newRes.ToString(); newRess.Name = "NewResCount"; li = new ListViewItem(new Sub[] { read, count, name, res, time, speed, size, oldRes, newRess }, ""); #endregion } if (!isColorring) { li = cl.ChangeColor(li); } if (tla.IsVisible(li.SubItems["Name"].Text)) { string datName = item.Groups["datName"].Value; li = cl.ChangeAlreadyListColor(li, datName); liCollection[i - 1] = li; if (bt == VIPBrowserLibrary.Common.BBSType._2ch) { liCollection[i - 1].ImageKey = datNameBase + datName + ".dat"; } else { liCollection[i - 1].ImageKey = datNameBase + datName; } } i++; } await Utility.TextUtility.WriteAsync(folder + "\\subject.txt", getData, enc, false); Chron.ThreadColumn tc = new Chron.ThreadColumn(); tc.ReadColumnData(gs.NotNecessarySettingDataPath + "\\column.dat"); return(tc.ConvertToColumnBaseItem(liCollection)); //return liCollection; } catch (ArgumentNullException) { return(null); } catch (IndexOutOfRangeException e) { throw new System.Net.WebException("配列の対象外:CommonThreadReader行231", e); } catch (Exception) { throw; } }