fork download
  1. /// <summary>
  2. /// スレッドを開く
  3. /// </summary>
  4. /// <param name="th"></param>
  5. public override bool Open( ThreadHeader header )
  6. {
  7. if ( header == null )
  8. {
  9. throw new ArgumentNullException( "header" );
  10. }
  11. if ( IsOpen )
  12. {
  13. throw new InvalidOperationException( "既にストリームが開かれています" );
  14. }
  15.  
  16. // 差分取得かどうか
  17. aboneCheck = (header.GotByteCount > 0) ? true : false;
  18.  
  19. bool reSync = false;
  20. Retry:
  21. _res = null;
  22.  
  23. HttpWebRequest req = (HttpWebRequest)WebRequest.Create( header.DatUrl );
  24. req.Timeout = 60000;
  25. req.AllowAutoRedirect = false;
  26. req.UserAgent = UserAgent;
  27.  
  28. req.Headers.Add( "Pragma" , "no-cache" );
  29. req.Headers.Add( "Cache-Control" , "no-cache" );
  30.  
  31. if ( header.GotByteCount > 0 && !reSync )
  32. {
  33. //req.AddRange( header.GotByteCount + 10 ); あぼーんじっけん
  34. req.AddRange( header.GotByteCount - 1 );
  35. }
  36.  
  37. if ( header.ETag != String.Empty )
  38. {
  39. req.Headers.Add( "If-None-Match" , header.ETag );
  40. }
  41.  
  42. if ( !aboneCheck && getGzip )
  43. {
  44. // req.Headers.Add( "Accept-Encoding" , "gzip" );
  45. req.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
  46. }
  47.  
  48. try
  49. {
  50. _res = (HttpWebResponse)req.GetResponse();
  51. }
  52. catch ( WebException ex )
  53. {
  54. HttpWebResponse res = (HttpWebResponse)ex.Response;
  55.  
  56. // あぼーんの予感
  57. if ( res != null && res.StatusCode == HttpStatusCode.RequestedRangeNotSatisfiable )
  58. {
  59. aboneCheck = false;
  60. reSync = true;
  61. goto Retry;
  62. }
  63. else
  64. {
  65. throw ex;
  66. }
  67. }
  68.  
  69. baseStream = _res.GetResponseStream();
  70. headerInfo = header;
  71.  
  72. //bool encGzip = _res.ContentEncoding.EndsWith( "gzip" );
  73.  
  74. //if ( encGzip )
  75. //{
  76. // using ( GZipStream gzipInp = new GZipStream( baseStream , CompressionMode.Decompress ) )
  77. // {
  78. // baseStream = FileUtility.CreateMemoryStream( gzipInp );
  79. // }
  80. // length = (int)baseStream.Length;
  81. //}
  82. //else
  83. {
  84. length = aboneCheck ?
  85. (int)_res.ContentLength - 1 : (int)_res.ContentLength;
  86. }
  87.  
  88. //▼ 2014/07/12 Mizutama http://a...content-available-to-author-only...h.net/test/read.cgi/software/1382440235/654
  89. // hope鯖が突然Rangeをサポートしなくなったので暫定対策
  90. if ( aboneCheck )
  91. {
  92. if ( string.IsNullOrEmpty( _res.Headers["Accept-Ranges"] )
  93. || string.IsNullOrEmpty( _res.Headers["Content-Range"] ) // 2014/07/14 Accept-Rangesしときながら
  94. ) // 全部返すとかもうね
  95. {
  96. // Content-Lengthも返さないので全部読んで差分を取り出す
  97. for ( int i=0; i<header.GotByteCount-1; i++ )
  98. {
  99. baseStream.ReadByte();
  100. }
  101. baseStream = FileUtility.CreateMemoryStream( baseStream );
  102. length = (int)baseStream.Length;
  103. }
  104. }
  105. //▲ 2014/07/12 Mizutama
  106.  
  107. // OK
  108. if ( _res.StatusCode == HttpStatusCode.OK ||
  109. _res.StatusCode == HttpStatusCode.PartialContent )
  110. {
  111. headerInfo.LastModified = _res.LastModified;
  112. headerInfo.ETag = _res.Headers["ETag"];
  113.  
  114.  
  115. if ( aboneCheck && length > 0 )
  116. {
  117. aboneCheck = false;
  118. var c = baseStream.ReadByte();
  119. if ( c != '\n' )
  120. {
  121. headerInfo.ETag = String.Empty;
  122. headerInfo.LastModified = DateTime.MinValue;
  123.  
  124. baseStream.Close();
  125. reSync = true;
  126. goto Retry;
  127. }
  128. }
  129.  
  130.  
  131. if ( reSync )
  132. {
  133. int lines = 0;
  134. while ( lines < headerInfo.GotResCount )
  135. {
  136. var c = baseStream.ReadByte();
  137. if ( c == '\n' )
  138. {
  139. lines++;
  140. }
  141. if ( c < 0 )
  142. {
  143. break;
  144. }
  145. }
  146. }
  147.  
  148. index = header.GotResCount + 1;
  149. position = 0;
  150. isOpen = true;
  151. }
  152. // dat落ちした予感
  153. else
  154. {
  155. _res.Close();
  156.  
  157. if ( _res.StatusCode == HttpStatusCode.Found )
  158. {
  159. // 10/05 移転追尾をすると過去ログ倉庫が読めなくなってしまう事がわかったので、一時的に外してみる
  160. //if (IsServerChanged(headerInfo))
  161. //{
  162. // // サーバーが移転したら新しい板情報でリトライ。
  163. // goto Retry;
  164. //}
  165. //else
  166. {
  167. // そうでなければ dat落ちとして判断
  168. //0324 headerInfo.Pastlog = true;
  169.  
  170. PastlogEventArgs argument = new PastlogEventArgs( headerInfo );
  171. OnPastlog( argument );
  172. }
  173. }
  174.  
  175. _res = null;
  176. }
  177.  
  178. return isOpen;
  179. }
  180. //▲2015/01/13
  181.  
  182. /// <summary>
  183. /// レスを読み込む
  184. /// </summary>
  185. /// <param name="resSets"></param>
  186. /// <param name="byteParsed"></param>
  187. /// <returns></returns>
  188. public override int Read(ResSetCollection resSets)
  189. {
  190. int temp;
  191. return Read(resSets, out temp);
  192. }
  193.  
  194. /// <summary>
  195. /// レスを読み込む
  196. /// </summary>
  197. /// <param name="resSets"></param>
  198. /// <param name="byteParsed"></param>
  199. /// <returns></returns>
  200. public override int Read(ResSetCollection resSets, out int byteParsed)
  201. {
  202. if (resSets == null)
  203. {
  204. throw new ArgumentNullException("resSets");
  205. }
  206. if (!isOpen)
  207. {
  208. throw new InvalidOperationException("ストリームが開かれていません");
  209. }
  210.  
  211. // バッファにデータを読み込む
  212. int byteCount = baseStream.Read(buffer, 0, buffer.Length);
  213. var tstr = Encoding.GetEncoding( "Shift_JIS" ).GetString( buffer );
  214.  
  215. //▼2015/01/13 2ちゃんDDoS対策としてCloudFlareを試したとき差分取得が不具合い
  216. // あぼーんチェック
  217. //if (aboneCheck && byteCount > 0)
  218. //{
  219. // if (buffer[0] != '\n')
  220. // {
  221. // OnABone();
  222. // byteParsed = 0;
  223.  
  224. // headerInfo.ETag = String.Empty;
  225. // headerInfo.LastModified = DateTime.MinValue;
  226.  
  227. // return -1;
  228. // }
  229.  
  230. // buffer = RemoveHeader(buffer, byteCount, 1);
  231. // byteCount -= 1;
  232. // aboneCheck = false;
  233. //}
  234. //▲2015/01/13
  235.  
  236. // 解析してコレクションに格納
  237. ICollection collect = dataParser.Parse(buffer, byteCount, out byteParsed);
  238.  
  239. foreach (ResSet resSet in collect)
  240. {
  241. ResSet res = resSet;
  242. res.Index = index++;
  243. resSets.Add(res);
  244.  
  245. if (res.Index == 1 && res.Tag != null)
  246. headerInfo.Subject = (string)res.Tag;
  247. }
  248.  
  249. // 実際に読み込まれたバイト数を計算
  250. position += byteCount;
  251.  
  252. return byteCount;
  253. }
  254.  
  255.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(5,24): error CS1525: Unexpected symbol `bool', expecting `class', `delegate', `enum', `interface', `partial', or `struct'
Compilation failed: 1 error(s), 0 warnings
stdout
Standard output is empty