예제 #1
0
        private void ReadCache(ResSetCollection buff)
        {
            // 新規に開く場合のみキャッシュを読み込む
            if (modeOpen)
            {
                if (ThreadIndexer.Exists(Cache, headerInfo))
                {
                    ThreadIndexer.Read(Cache, headerInfo);

                    try
                    {
                        storage            = new LocalThreadStorage(Cache, headerInfo, StorageMode.Read);
                        storage.BufferSize = bufferSize;

                        // すべてのレスを読み込み表示
                        while (storage.Read(buff) != 0)
                        {
                            ;
                        }
                    }
                    finally
                    {
                        if (storage != null)
                        {
                            storage.Close();
                            storage = null;
                        }
                    }

                    buff.IsNew = false;
                }
            }
        }
예제 #2
0
 /// <summary>
 /// ReadOnlyResSetCollectionクラスのインスタンスを初期化
 /// </summary>
 /// <param name="items"></param>
 public ReadOnlyResSetCollection(ResSetCollection items)
 {
     //
     // TODO: コンストラクタ ロジックをここに追加してください。
     //
     collection = items;
     //list = ArrayList.ReadOnly(list);
 }
예제 #3
0
        /// <summary>
        /// ResSetEventArgsクラスのインスタンスを初期化
        /// </summary>
        /// <param name="items"></param>
        public ResSetEventArgs(ResSetCollection items)
        {
            if (items == null)
            {
                throw new ArgumentNullException("items");
            }

            this.resSets = items;
        }
예제 #4
0
        public void Indexing(BoardInfo bi, string[] datFiles, DatIndexingCallback callback)
        {
            LocalThreadReader reader = new LocalThreadReader(new X2chThreadParser());
            float             length = datFiles.Length, current = 0;

            if (length == 0)
            {
                return;
            }

            foreach (string path in datFiles)
            {
                ThreadHeader header = new X2chThreadHeader();
                header.BoardInfo = bi;
                header.Key       = Path.GetFileNameWithoutExtension(path);
                int parsed;

                try
                {
                    if (!reader.__Open(path))
                    {
                        continue;
                    }

                    ResSetCollection buffer = new ResSetCollection();
                    int byteCount           = 0;

                    while (reader.Read(buffer, out parsed) != 0)
                    {
                        byteCount += parsed;
                    }

                    if (buffer.Count > 0)
                    {
                        header.GotByteCount = byteCount;
                        header.ResCount     = buffer.Count;
                        header.GotResCount  = buffer.Count;
                        header.LastModified = File.GetLastWriteTime(path);
                        header.UseGzip      = false;
                        header.Subject      = buffer[0].Tag as String;

                        ThreadIndexer.Write(
                            Path.ChangeExtension(path, ".idx"), header);
                    }

                    if (callback != null)
                    {
                        callback(++current / length * 100f);
                    }
                }
                finally
                {
                    reader.Close();
                }
            }
        }
예제 #5
0
        /// <summary>
        /// レスをあぼーん
        /// </summary>
        /// <param name="header">あぼーんするスレッド情報</param>
        /// <param name="indices">あぼーんするレス番号の配列</param>
        /// <param name="visible">透明あぼーんの場合はfalse、そうでない場合はtrue</param>
        public virtual void ResABone(ThreadHeader header, int[] indices, bool visible)
        {
            if (header == null)
            {
                throw new ArgumentNullException("header");
            }
            if (indices == null)
            {
                throw new ArgumentNullException("indices");
            }

            ResSetCollection resSets = new ResSetCollection();
            ThreadStorage    storage = null;

            try {
                storage = new LocalThreadStorage(this);

                // スレッドを読み込む
                if (storage.Open(header, StorageMode.Read))
                {
                    while (storage.Read(resSets) != 0)
                    {
                        ;
                    }
                    storage.Close();
                }

                // レスの削除
                foreach (int index in indices)
                {
                    resSets.ABone(index, visible, visible ? ABoneType.Normal : ABoneType.Tomei, "");
                }

                // ログを一端削除
                string dat = GetDatPath(header);
                File.Delete(dat);

                // 書き込む
                if (storage.Open(header, StorageMode.Write))
                {
                    storage.Write(resSets);
                    storage.Close();
                }
                storage = null;
            }
            finally {
                if (storage != null)
                {
                    storage.Close();
                }
            }
        }
예제 #6
0
 /// <summary>
 /// ThreadControlクラスのインスタンスを初期化
 /// </summary>
 /// <param name="cache"></param>
 protected ThreadControl(Cache cache)
     : base(cache)
 {
     //
     // TODO: コンストラクタ ロジックをここに追加してください。
     //
     resCollection      = new ResSetCollection();
     indicesValues      = new SortedValueCollection <int>();
     bbsType            = BbsType.None;
     bufferSize         = 4096;
     useGzip            = false;
     isPackageReception = false;
 }
예제 #7
0
        /// <summary>
        /// 1 から始まるレス番号の指定した範囲を取得。
        /// このメソッドは、コレクションの順序とレス番号の順序が一致している場合のみに使用。
        /// そうでない場合は、beginIndex と endIndex で指定しても、返されるコレクションのレス番号と一致している保証は無い。
        /// 指定したレス番号のデータが欲しい場合は、GetRangeOfNumber メソッドを使用する。
        /// </summary>
        /// <param name="beginIndex"></param>
        /// <param name="endIndex"></param>
        /// <returns></returns>
        public ResSetCollection GetRange(int beginIndex, int endIndex)
        {
            if (beginIndex < 1 || endIndex < 1 || beginIndex > endIndex)
            {
                throw new ArgumentOutOfRangeException();
            }

            var result = new ResSetCollection();

            for (int i = beginIndex; i <= endIndex; i++)
            {
                result.Add(this[i - 1]);
            }

            return(result);
        }
예제 #8
0
        public ResSetCollection GetRangeOfNumber(int[] resNumbers)
        {
            var result = new ResSetCollection();

            foreach (ResSet res in List)
            {
                foreach (int n in resNumbers)
                {
                    if (res.Index == n)
                    {
                        result.Add(res);
                    }
                }
            }

            return(result);
        }
예제 #9
0
        /// <summary>
        /// 指定した 1 から始まるレス番号を指定してレスを取得。
        /// このメソッドは、コレクションの順序とレス番号の順序が一致している場合のみに使用。
        /// そうでない場合は、indices で指定しても、返されるコレクションのレス番号と一致している保証は無い。
        /// 指定したレス番号のデータが欲しい場合は、GetRangeOfNumber メソッドを使用する。
        /// </summary>
        /// <param name="indices"></param>
        /// <returns></returns>
        public ResSetCollection GetRange(int[] indices)
        {
            if (indices == null)
            {
                throw new ArgumentNullException("indices");
            }

            ResSetCollection result =
                new ResSetCollection();

            foreach (int index in indices)
            {
                if (index > 0 && index <= Count)
                {
                    result.Add(this[index - 1]);
                }
            }

            return(result);
        }
예제 #10
0
        /// <summary>
        /// 指定したResSetコレクションを
        /// 設定されているスキンを使用して文字列形式に変換
        /// </summary>
        /// <param name="resSetCollection"></param>
        /// <returns></returns>
        public override string Convert(ResSetCollection resSetCollection)
        {
            if (resSetCollection == null)
            {
                throw new ArgumentNullException("resSetCollection");
            }

            // 指定したレス分の初期配列を割り当てる
            StringBuilder sb = new StringBuilder(512 * resSetCollection.Count);

            foreach (ResSet resSet in resSetCollection)
            {
                if (resSet.Visible)
                {
                    string result = Convert(resSet);
                    sb.Append(result);
                }
            }

            return(sb.ToString());
        }
예제 #11
0
        /*
         * /// <summary>
         * /// 指定したスレッドの状態を確認
         * /// </summary>
         * /// <param name="header"></param>
         * /// <returns></returns>
         * public static ThreadState CheckState(ThreadHeader header)
         * {
         *      if (header == null)
         *              throw new ArgumentNullException("header");
         *
         *      HttpWebRequest req = (HttpWebRequest)WebRequest.Create(header.Url);
         *      req.UserAgent = TwinDll.IEUserAgent;
         *      HttpWebResponse res = (HttpWebResponse)req.GetResponse();
         *
         *      byte[] data = FileUtility.ReadBytes(res.GetResponseStream());
         *      string html = Encoding.GetEncoding("Shift_Jis").GetString(data);
         *
         *      if (html.IndexOf("そんな板orスレッドないです") >= 0)
         *      {
         *              if (html.IndexOf("隊長! 過去ログ倉庫で") >= 0)
         *                      return ThreadState.Kakolog;
         *
         *              if (html.IndexOf("過去ログ倉庫にもありませんでした") >= 0)
         *                      return ThreadState.NotExists;
         *      }
         *      else if (html.IndexOf("このスレッドは過去ログ倉庫に格納されています") >= 0 ||
         *                      html.IndexOf("もうずっと人大杉") >= 0)
         *      {
         *              return ThreadState.Pastlog;
         *      }
         *
         *      return ThreadState.None;
         * }*/

        /// <summary>
        /// 指定したスレッドのresStartからresEndまでの範囲を取得。
        /// 既得ログに存在すればローカルから読み込む。
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="header"></param>
        /// <param name="resStart"></param>
        /// <param name="resEnd"></param>
        /// <returns></returns>
        public static ResSetCollection GetRange(Cache cache, ThreadHeader header, int resStart, int resEnd)
        {
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }

            if (header == null)
            {
                throw new ArgumentNullException("header");
            }

            if (resStart > resEnd)
            {
                throw new ArgumentException("resStartはresEnd以下にしてください", "resStart");
            }

            string address = header.Url + ((resStart == resEnd) ?
                                           resStart.ToString() : String.Format("{0}-{1}", resStart, resEnd));

            // サーバーからデータをダウンロード
            WebClient webClient = new WebClient();

            webClient.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT; DigExt)");

            byte[] data = webClient.DownloadData(address);
            int    byteParsed;

            // ResSet[]型に解析
            ThreadParser parser = new X2chHtmlThreadParser(BbsType.X2ch, Encoding.GetEncoding("Shift_Jis"));

            ResSet[] array = parser.Parse(data, data.Length, out byteParsed);

            ResSetCollection items = new ResSetCollection();

            items.AddRange(array);

            return(items);
        }
예제 #12
0
        /// <summary>
        /// データを読み込む&書き込む
        /// </summary>
        private void Reading()
        {
            ResSetCollection items = new ResSetCollection(),
                             buffer = new ResSetCollection();
            int read = -1, byteParsed, totalByteCount = 0;

            while (read != 0)
            {
                if (canceled)
                {
                    return;
                }

                read = reader.Read(buffer, out byteParsed);

                // あぼーんを検知した場合、処理を中止。
                if (read == -1)
                {
                    aboneDetected = true;
                    return;
                }

                totalByteCount += byteParsed;

                items.AddRange(buffer);

                // 逐次受信の場合はビューアに書き込む
                if (!isPackageReception)
                {
                    if (canceled)
                    {
                        return;
                    }

                    Invoke(new WriteResMethodInvoker(WriteInternal), new object[] { buffer });
                }
                buffer.Clear();

                OnReceive(new ReceiveEventArgs(
                              reader.Length, reader.Position, read));

                OnStatusTextChanged(
                    String.Format("{0} 受信中 ({1}/{2})",
                                  headerInfo.Subject, reader.Position, reader.Length));
            }

            // 一括受信の場合はここで一気にフラッシュ
            if (isPackageReception)
            {
                if (canceled)
                {
                    return;
                }

                Invoke(new WriteResMethodInvoker(WriteInternal), new object[] { items });
            }

            try
            {
                // スレッドのインデックス情報を保存
                storage            = new LocalThreadStorage(Cache, headerInfo, StorageMode.Write);
                storage.BufferSize = bufferSize;
                storage.Write(items);

                headerInfo.GotByteCount += totalByteCount;
                headerInfo.GotResCount  += items.Count;
                headerInfo.NewResCount   = items.Count;
                ThreadIndexer.Write(Cache, headerInfo);
            }
            catch (Exception ex)
            {
                TwinDll.Output(ex);
            }
            finally
            {
                storage.Close();
            }

            SaveThreadListIndices();
        }
예제 #13
0
 public ResSetEventArgs(ResSet res)
 {
     this.resSets = new ResSetCollection();
     this.resSets.Add(res);
 }
예제 #14
0
 private void WriteInternal(ResSetCollection items)
 {
     resCollection.AddRange(items);
     Write(items);
 }
예제 #15
0
 /// <summary>
 /// itemsを書き込む
 /// </summary>
 /// <param name="items"></param>
 protected abstract void Write(ResSetCollection items);
예제 #16
0
 /// <summary>
 /// ResSetコレクションをコレクションに追加
 /// </summary>
 public void AddRange(ResSetCollection resCollection)
 {
     InnerList.AddRange(resCollection);
 }
예제 #17
0
 public ResSetCollection(ResSetCollection coll)
 {
     InnerList.Capacity = coll.Count;
     AddRange(coll);
 }
예제 #18
0
 /// <summary>
 /// 指定したレスコレクションをポップアップで表示
 /// </summary>
 /// <param name="resSets"></param>
 public abstract void Popup(ResSetCollection resSets);
예제 #19
0
 /// <summary>
 /// ResSetを一度に変換
 /// </summary>
 /// <param name="resSetCollection"></param>
 /// <returns></returns>
 public abstract string Convert(ResSetCollection resSetCollection);
예제 #20
0
 /// <summary>
 /// 表示を一端クリアして指定したitemsを書き込む
 /// </summary>
 /// <param name="items"></param>
 public abstract void WriteResColl(ResSetCollection items);