コード例 #1
0
        /// <summary>
        /// URLを解析しThreadHeaderクラスのインスタンスを初期化
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static ThreadHeader ParseThread(string url)
        {
            foreach (Regex regex in ParseThreadRegexArray)
            {
                Match m = regex.Match(url);
                if (m.Success)
                {
                    BoardInfo board = new BoardInfo();
                    board.Server = m.Groups["host"].Value;
                    board.Path   = m.Groups["path"].Value;

                    if (board.Bbs == BbsType.None)
                    {
                        board.Bbs = BbsType.Dat;
                    }

                    // 過去ログ倉庫のURLの場合
                    if (ParseThreadRegexArray[2].Equals(regex))
                    {
                        board.Bbs = BbsType.X2chKako;
                    }

                    ThreadHeader h = TypeCreator.CreateThreadHeader(board.Bbs);
                    h.Key       = m.Groups["key"].Value;
                    h.BoardInfo = board;

                    return(h);
                }
            }
            return(null);
        }
コード例 #2
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);
        }
コード例 #3
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);
        }