示例#1
0
        /// <summary>
        /// 指定した板の既得インデックスを読み込む
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="board"></param>
        /// <returns></returns>
        public static List <ThreadHeader> Read(Cache cache, BoardInfo board)
        {
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }
            if (board == null)
            {
                throw new ArgumentNullException("board");
            }

            List <ThreadHeader> items = new List <ThreadHeader>();
            string indicesPath        = GetIndicesPath(cache, board);

            if (File.Exists(indicesPath))
            {
                XmlDocument document = new XmlDocument();

                lock (typeof(GotThreadListIndexer))
                {
                    document.Load(indicesPath);
                }

                XmlElement  root     = document.DocumentElement;
                XmlNodeList children = root.ChildNodes;

                foreach (XmlNode node in children)
                {
                    try
                    {
                        ThreadHeader header = TypeCreator.CreateThreadHeader(board.Bbs);
                        header.BoardInfo = board;
                        header.Key       = node.Attributes.GetNamedItem("key").Value;
                        header.Subject   = node.SelectSingleNode("subject").InnerText;

                        int resCount;
                        if (Int32.TryParse(node.SelectSingleNode("resCount").InnerText, out resCount))
                        {
                            header.ResCount = resCount;
                        }

                        items.Add(header);
                    }
                    catch (Exception ex)
                    {
                        TwinDll.Output(ex);
                    }
                }
            }

            return(items);
        }
示例#2
0
 static TwinDll()
 {
     TypeCreator.Regist(BbsType.None, typeof(X2chThreadHeader), typeof(X2chThreadReader), typeof(X2chThreadListReader), typeof(X2chPost));
     TypeCreator.Regist(BbsType.Dat, typeof(X2chThreadHeader), typeof(X2chThreadReader), typeof(X2chThreadListReader), typeof(X2chPost));
     TypeCreator.Regist(BbsType.X2chKako, typeof(X2chKakoThreadHeader), typeof(X2chKakoThreadReader), typeof(X2chThreadListReader), typeof(X2chKakoPost));
     TypeCreator.Regist(BbsType.X2chAuthenticate, typeof(X2chThreadHeader), typeof(X2chAuthenticateThreadReader), typeof(X2chThreadListReader), typeof(X2chPost));
     TypeCreator.Regist(BbsType.X2ch, typeof(X2chThreadHeader), typeof(X2chThreadReader), typeof(X2chThreadListReader), typeof(X2chPost));
     TypeCreator.Regist(BbsType.Be2ch, typeof(X2chThreadHeader), typeof(Be2chThreadReader), typeof(Be2chThreadListReader), typeof(Be2chPost));
     TypeCreator.Regist(BbsType.Zeta, typeof(ZetaThreadHeader), typeof(ZetaThreadReader), typeof(ZetaThreadListReader), typeof(ZetaPost));
     TypeCreator.Regist(BbsType.Machi, typeof(MachiThreadHeader), typeof(MachiThreadReader), typeof(MachiThreadListReader), typeof(MachiPost));
     TypeCreator.Regist(BbsType.Jbbs, typeof(JbbsThreadHeader), typeof(JbbsThreadReader), typeof(JbbsThreadListReader), typeof(JbbsPost));
     TypeCreator.Regist(BbsType.MilkCafe, typeof(X2chThreadHeader), typeof(X2chThreadReader), typeof(X2chThreadListReader), typeof(MilkcafePost));
 }
        /// <summary>
        /// newbbsに対応したリーダーを作成
        /// (既に作成済みであれば何もしない)
        /// </summary>
        /// <param name="newbbs"></param>
        private ThreadReader CreateBaseReader(BbsType newbbs)
        {
            if (newbbs != bbsType)
            {
                bbsType = newbbs;

                reader = TypeCreator.CreateThreadReader(newbbs);

                if (reader is X2chKakoThreadReader)
                {
                    X2chKakoThreadReader kako = (X2chKakoThreadReader)reader;
                    kako.RetryServers = new BoardInfo[] { retryServer };
                }

                reader.ABone   += new EventHandler(OnABoneInternal);
                reader.Pastlog += new EventHandler <PastlogEventArgs>(OnPastlogInternal);
            }
            return(reader);
        }
        /// <summary>
        /// 指定した板に対応するリーダーを作成し、開きます。
        /// </summary>
        /// <param name="board"></param>
        /// <returns></returns>
        private bool OpenReader(BoardInfo board)
        {
            if (board.Bbs != bbsType && online)
            {
                bbsType       = board.Bbs;
                networkReader = TypeCreator.CreateThreadListReader(bbsType);
                networkReader.ServerChange += new EventHandler <ServerChangeEventArgs>(OnServerChange);
            }

            baseReader = online ?
                         new ThreadListReaderRelay(Cache, networkReader) : offlineReader;

            baseReader.BufferSize   = bufferSize;
            baseReader.AutoRedirect = true;
            baseReader.Open(board);

            if (online)
            {
                oldItems = ((ThreadListReaderRelay)baseReader).CacheItems.ToArray();
            }

            return(baseReader.IsOpen);
        }
示例#5
0
        /// <summary>
        /// インデックスを読み込む
        /// </summary>
        /// <param name="filePath">インデックスファイルへのファイルパス</param>
        /// <returns>読み込みに成功すればThreadHeaderのインスタンス、失敗すればnull</returns>
        public static ThreadHeader Read(string filePath)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException("filePath");
            }

            ThreadHeader result = null;

            lock (typeof(ThreadIndexer))
            {
                // インデックスファイルへのパス

                if (File.Exists(filePath))
                {
                    try
                    {
                        CSPrivateProfile profile = new CSPrivateProfile();
                        profile.Read(filePath);

                        // 重要なセクションがなければエラー
                        if (!profile.Sections.ContainsSection("Board") ||
                            !profile.Sections.ContainsSection("Thread"))
                        {
                            return(null);
                        }

                        BbsType bbs = (BbsType)Enum.Parse(typeof(BbsType), profile.GetString("Board", "BBS", "X2ch"));

                        // 板情報
                        result = TypeCreator.CreateThreadHeader(bbs);
                        result.BoardInfo.Server = profile.GetString("Board", "Server", "Error");
                        result.BoardInfo.Path   = profile.GetString("Board", "Path", "Error");
                        result.BoardInfo.Name   = profile.GetString("Board", "Name", "Error");
                        result.BoardInfo.Bbs    = bbs;

                        // スレッド情報
                        result.ETag         = profile.GetString("Thread", "ETag", String.Empty);
                        result.LastWritten  = profile.GetDateTime("Thread", "LastWritten");
                        result.LastModified = profile.GetDateTime("Thread", "LastModified");
                        result.Subject      = profile.GetString("Thread", "Subject", "Error");
                        result.ResCount     = profile.GetInt("Thread", "ResCount", 0);
                        result.GotResCount  = profile.GetInt("Thread", "GotResCount", 0);
                        result.GotByteCount = profile.GetInt("Thread", "GotByteCount", 0);
                        result.NewResCount  = profile.GetInt("Thread", "NewResCount", 0);
                        result.Key          = profile.GetString("Thread", "Key", "Error");

                        // そのほかの情報
                        result.Position = profile.GetFloat("Option", "Position", 0);
                        result.Pastlog  = profile.GetBool("Option", "Pastlog", false);
                        result.UseGzip  = profile.GetBool("Option", "UseGzip", false);
                        result.Shiori   = profile.GetInt("Option", "Shiori", 0);
                        result.RefCount = profile.GetInt("Option", "RefCount", 0);
                        result.Sirusi.FromArrayString(profile.GetString("Option", "Sirusi", ""));
                    }
                    catch (Exception ex)
                    {
                        TwinDll.Output(ex);
                    }
                }
            }

            return(result);
        }