Beispiel #1
0
        /* ----------------------------------------------------------------- */
        ///
        /// CreateDocument
        ///
        /// <summary>
        /// 新しい Document オブジェクトを生成します。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        public static Document CreateDocument(this Page page, string directory)
        {
            var done = page.Document as Document;

            if (done != null)
            {
                return(done);
            }

            var path = IoEx.Path.Combine(directory, page.FileName);
            var dest = DocumentHandler.Create(path, Encoding.UTF8, false);

            page.Document = dest;
            return(dest);
        }
        /* ----------------------------------------------------------------- */
        ///
        /// Import
        ///
        /// <summary>
        /// ファイルをインポートします。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        public static void Import(this PageCollection pages,
                                  Tag tag, int index, string path, int maxLength)
        {
            if (IoEx.Directory.Exists(path))
            {
                foreach (var file in IoEx.Directory.GetFiles(path))
                {
                    Import(pages, tag, index, file, maxLength);
                }
                return;
            }

            pages.NewPage(tag, index, (page) =>
            {
                var document = DocumentHandler.Create(path);
                document.Save(IoEx.Path.Combine(pages.Directory, page.FileName));
                page.Document = document;
                page.UpdateAbstract(maxLength);
            });
        }
        /* ----------------------------------------------------------------- */
        ///
        /// Recover
        ///
        /// <summary>
        /// データが格納されているフォルダから PageCollection オブジェクトを
        /// 再構築します。
        /// </summary>
        ///
        /// <remarks>
        /// NOTE: 現在の方法ではタグ情報を復旧することはできない。
        /// </remarks>
        ///
        /* ----------------------------------------------------------------- */
        public static void Recover(this PageCollection pages, string direcotry, int maxLength)
        {
            if (!IoEx.Directory.Exists(direcotry))
            {
                return;
            }
            foreach (var path in IoEx.Directory.GetFiles(direcotry))
            {
                var filename = IoEx.Path.GetFileName(path).ToLower();
                var exp      = new Regex("^[0-9a-z]{32}$");
                if (!exp.IsMatch(filename) || pages.Contains(filename))
                {
                    continue;
                }

                pages.NewPage(pages.Tags.Everyone, 0, (page) =>
                {
                    var document  = DocumentHandler.Create(path);
                    page.FileName = filename;
                    page.Document = document;
                    page.UpdateAbstract(maxLength);
                });
            }
        }