/// <summary> /// Pastlogイベントを発生させる /// </summary> protected void OnPastlog(PastlogEventArgs argument) { if (Pastlog != null) { Pastlog(this, argument); } }
/// <summary> /// スレッドを開く /// </summary> /// <param name="th"></param> public override bool Open(ThreadHeader header) { if (header == null) { throw new ArgumentNullException("header"); } if (IsOpen) { throw new InvalidOperationException("既にストリームが開かれています"); } // 差分取得かどうか aboneCheck = (header.GotByteCount > 0) ? true : false; // Retry: _res = null; try { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(header.DatUrl); req.Timeout = 60000; req.AllowAutoRedirect = false; req.UserAgent = UserAgent; //req.Headers.Add("Pragma", "no-cache"); //req.Headers.Add("Cache-Control", "no-cache"); if (!String.IsNullOrEmpty(header.ETag)) { req.Headers.Add("If-None-Match", header.ETag); } if (header.GotByteCount > 0) { req.AddRange(header.GotByteCount - 1); } //if (!aboneCheck && getGzip) // req.Headers.Add("Accept-Encoding", "gzip"); _res = (HttpWebResponse)req.GetResponse(); baseStream = _res.GetResponseStream(); headerInfo = header; bool encGzip = _res.ContentEncoding.EndsWith("gzip"); if (encGzip) { using (GZipStream gzipInp = new GZipStream(baseStream, CompressionMode.Decompress)) baseStream = FileUtility.CreateMemoryStream(gzipInp); length = (int)baseStream.Length; } else { length = aboneCheck ? (int)_res.ContentLength - 1 : (int)_res.ContentLength; } // OK if (_res.StatusCode == HttpStatusCode.OK || _res.StatusCode == HttpStatusCode.PartialContent) { headerInfo.LastModified = _res.LastModified; headerInfo.ETag = _res.Headers["ETag"]; index = header.GotResCount + 1; position = 0; isOpen = true; } // dat落ちした予感 else { _res.Close(); if (_res.StatusCode == HttpStatusCode.Found) { // 10/05 移転追尾をすると過去ログ倉庫が読めなくなってしまう事がわかったので、一時的に外してみる //if (IsServerChanged(headerInfo)) //{ // // サーバーが移転したら新しい板情報でリトライ。 // goto Retry; //} //else { // そうでなければ dat落ちとして判断 //0324 headerInfo.Pastlog = true; PastlogEventArgs argument = new PastlogEventArgs(headerInfo); OnPastlog(argument); } } _res = null; } } catch (WebException ex) { HttpWebResponse res = (HttpWebResponse)ex.Response; // あぼーんの予感 if (res != null && res.StatusCode == HttpStatusCode.RequestedRangeNotSatisfiable) { OnABone(); } else { throw ex; } } return(isOpen); }