/// <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> /// スレッドのデータをダウンロードしてを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); }
/// <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> /// スレッド一覧を取得し、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; } }