Exemple #1
0
        /// <summary>
        /// 指定した板のインデックスを作成
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="board"></param>
        /// <param name="items"></param>
        public static void Write(Cache cache, BoardInfo board, List <ThreadHeader> items)
        {
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }
            if (board == null)
            {
                throw new ArgumentNullException("board");
            }
            if (items == null)
            {
                throw new ArgumentNullException("items");
            }

            string indicesPath =
                GetIndicesPath(cache, board);

            // ヘッダ情報を書式化してファイルに保存
            ThreadListFormatter formatter = new GotThreadListFormatter();

            lock (typeof(GotThreadListIndexer))
            {
                FileUtility.Write(indicesPath, formatter.Format(items), false, TwinDll.DefaultEncoding);
            }
        }
Exemple #2
0
        /// <summary>
        /// 指定したスレッドのインデックスを作成
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="header"></param>
        public static void Write(Cache cache, ThreadHeader header)
        {
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }
            if (header == null)
            {
                throw new ArgumentNullException("header");
            }

            XmlDocument document    = new XmlDocument();
            string      indicesPath = GetIndicesPath(cache, header.BoardInfo);
            bool        overwrite   = false;

            lock (typeof(GotThreadListIndexer))
            {
                if (File.Exists(indicesPath))
                {
                    document.Load(indicesPath);
                    XmlNode node = document.SelectSingleNode("indices/item[@key=\"" + header.Key + "\"]");
                    if (node != null)
                    {
                        // レス数を更新
                        node.SelectSingleNode("resCount").InnerText = header.ResCount.ToString();
                        overwrite = true;
                    }
                }
                else
                {
                    // ルートを作成
                    document.AppendChild(
                        document.CreateElement("indices"));
                }

                // 存在しなければ新しく作成
                if (!overwrite)
                {
                    GotThreadListFormatter formatter = new GotThreadListFormatter();
                    formatter.AppendChild(document, document.DocumentElement, header);
                }

                // ドキュメントを保存
                XmlTextWriter writer = new XmlTextWriter(indicesPath, TwinDll.DefaultEncoding);
                writer.Formatting = Formatting.Indented;

                document.Save(writer);
                writer.Close();
            }
        }