コード例 #1
0
ファイル: WordpressImport.cs プロジェクト: WeTeam/WeBlog
        private ImportSummary ImportBlog()
        {
            var options = new WpImportOptions
            {
                IncludeComments = ImportComments.Checked,
                IncludeCategories = ImportCategories.Checked,
                IncludeTags = ImportTags.Checked
            };

            string fileLocation = String.Format("{0}\\{1}", ApplicationContext.PackagePath, WordpressXmlFile.Value);
            LogMessage("Reading import file");
            var importManager = new WpImportManager(db, new FileBasedProvider(fileLocation), options);

            LogMessage("Creating blog");
            Item root = db.GetItem(litSummaryPath.Text);
            if (root != null)
            {
                var templateMappingItem = root.Database.GetItem(new ID(TemplatesMapping.Value));
                var templatesMapping = new TemplatesMapping(templateMappingItem);
                var blogItem = importManager.CreateBlogRoot(root, BlogName.Value, BlogEmail.Value, templatesMapping.BlogRootTemplate);

                LogMessage("Importing posts");
                LogTotal(importManager.Posts.Count);

                return importManager.ImportPosts(blogItem, templatesMapping, (itemName, count) =>
                {
                    LogMessage("Importing entry " + itemName);
                    LogProgress(count);
                });
            }
            else
            {
                LogMessage(String.Format("Parent item for blog root could not be found ({0})", litSummaryPath.Text));
            }

            return null;
        }
コード例 #2
0
        private void ImportBlog(WordPressImportData data)
        {
            var db = Factory.GetDatabase(data.DatabaseName);
            var options = BuildWpImportOptions(data);
            var postProvider = new MediaItemBasedProvider(data.DataSourceId, db);
            var importManager = new WpImportManager(db, postProvider, options);
            string jobHandle = Context.Job.Handle.ToString();
            LogMessage("Reading import item", jobHandle);

            var templateMappingItem = db.GetItem(data.TemplateMappingItemId);
            var templatesMapping = new TemplatesMapping(templateMappingItem);

            var blogParent = db.GetItem(data.ParentId);
            if (blogParent != null)
            {
                LogMessage("Creating blog", jobHandle);
                var blogRoot = importManager.CreateBlogRoot(blogParent, data.BlogName, data.BlogEmail, templatesMapping.BlogRootTemplate);

                LogTotal(importManager.Posts.Count, jobHandle);
                LogMessage("Importing posts", jobHandle);
                importManager.ImportPosts(blogRoot, templatesMapping, (itemName, count) =>
                {
                    LogMessage("Importing entry " + itemName, jobHandle);
                    LogProgress(count, jobHandle);
                });
            }
            else
            {
                LogMessage(String.Format("Parent item for blog root could not be found ({0})", data.ParentId), jobHandle);
            }
        }