Beispiel #1
0
        /// <summary>
        /// あぼーんされたレスを見つけ出し、差分取得可能なバイトオフセットを見つけて、新しいオフセットに訂正する
        /// </summary>
        /// <param name="oldItems"></param>
        /// <param name="headerInfo"></param>
        /// <returns></returns>
        public static int Test(ResSetCollection oldItems, ThreadHeader headerInfo)
        {
            ThreadHeader     h      = new X2chThreadHeader(headerInfo as X2chThreadHeader);
            X2chThreadReader reader = new X2chThreadReader();

            try
            {
                if (reader.Open(h))
                {
                    ResSetCollection newItems = new ResSetCollection();

                    while (reader.Read(newItems) != 0)
                    {
                        ;
                    }

                    int correctlyOffset = AboneDetecting(oldItems, newItems);

                    // 訂正された新しいオフセット
                    return(correctlyOffset);
                }

                return(-1);
            }
            finally
            {
                reader.Close();
            }
        }
 public X2chThreadHeader(X2chThreadHeader source)
     : base(source.BoardInfo, source.Key, source.Subject)
 {
     //
     // TODO: コンストラクタ ロジックをここに追加してください。
     //
 }
 /// <summary>
 /// X2chKakoThreadHeaderクラスのインスタンスを初期化
 /// </summary>
 public X2chKakoThreadHeader(X2chThreadHeader source) : base(source)
 {
     base.BoardInfo.Bbs = BbsType.X2chKako;
     base.ResCount      = source.ResCount;
 }
        /// <summary>
        /// スレッドを開く
        /// </summary>
        /// <param name="th"></param>
        public override bool Open(ThreadHeader header)
        {
            if (header == null)
            {
                throw new ArgumentNullException("header");
            }
            if (IsOpen)
            {
                throw new InvalidOperationException("既にストリームが開かれています");
            }

            headerInfo = header;
            //firstRead = true;
            RokkaResponseState = X2chRokkaResponseState.None;

            if (header.Pastlog)
            {
                return(false);
            }

            X2chAuthenticator authenticator = X2chAuthenticator.GetInstance();

            if (authenticator.HasSession)
            {
                X2chThreadHeader x2chHeader = header as X2chThreadHeader;
                if (x2chHeader != null)
                {
                    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(x2chHeader.AuthenticateUrl);
                    req.Timeout           = 15000;
                    req.UserAgent         = UserAgent;
                    req.AllowAutoRedirect = false;

                    // ** 9/26 削除 **
                    // req.Headers.Add("Accept-Encoding", "gzip");

                    // ** 9/26 追加 **
                    req.AutomaticDecompression = DecompressionMethods.GZip;

                    req.Headers.Add("Pragma", "no-cache");
                    req.Headers.Add("Cache-Control", "no-cache");

                    if (x2chHeader.ETag != String.Empty)
                    {
                        req.Headers.Add("If-None-Match", x2chHeader.ETag);
                    }

                    _res = (HttpWebResponse)req.GetResponse();

                    //baseStream = _res.GetResponseStream();
                    baseStream          = FileUtility.CreateMemoryStream(_res.GetResponseStream());
                    baseStream.Position = 0;
                    length = (int)baseStream.Length;

                    RokkaResponseState = ParseRokkaFirstline(baseStream);

                    if (_res.StatusCode == HttpStatusCode.OK)
                    {
                        /* 9 26削除
                         * using (GZipStream gzipInp = new GZipStream(_res.GetResponseStream(), CompressionMode.Decompress))
                         * baseStream = FileUtility.CreateMemoryStream(gzipInp);
                         */

                        x2chHeader.ETag         = _res.Headers["ETag"];
                        x2chHeader.LastModified = _res.LastModified;

                        index    = header.GotResCount + 1;
                        position = 0;
                        isOpen   = true;
                    }
                    else
                    {
                        OnPastlog(new PastlogEventArgs(header));
                    }
                }
            }
            else
            {
                OnPastlog(new PastlogEventArgs(header));
            }

            // 過去ログなのでdat落ちに設定
            headerInfo.Pastlog = true;

            return(isOpen);
        }