public void Import(Id entryCollectionId, Id pagesCollectionId, Id mediaCollectionId, ImportMode mode, BlogMLBlog blog) { progress = new Progress(); LogProgress("Import started, mode={0}", mode); LogProgress("Blog found with title of '{0}'", blog.Title); try { AppService appSvc = AppServiceRepository.GetService(); if (mode == ImportMode.New) { var ws = appSvc.GetWorkspace(); //clean out old collections CleanOutCollection(ws.GetCollection("blog").Id, appSvc); CleanOutCollection(ws.GetCollection("pages").Id, appSvc); CleanOutCollection(ws.GetCollection("media").Id, appSvc); ws.Title = new AtomTitle() { Text = entryCollectionId.Owner }; //change old id's to new id's ChangeCollectionId(appSvc, ws.GetCollection("blog").Id, entryCollectionId); ChangeCollectionId(appSvc, ws.GetCollection("pages").Id, pagesCollectionId); ChangeCollectionId(appSvc, ws.GetCollection("media").Id, mediaCollectionId); } else if (mode == ImportMode.Overwrite) { CleanOutCollection(entryCollectionId, appSvc); CleanOutCollection(pagesCollectionId, appSvc); CleanOutCollection(mediaCollectionId, appSvc); } TurnOffTrackbacks(entryCollectionId, appSvc); TurnOffTrackbacks(pagesCollectionId, appSvc); TurnOffTrackbacks(mediaCollectionId, appSvc); var coll = appSvc.GetCollection(entryCollectionId); if (mode != ImportMode.Merge) { coll.Title = new AtomTitle() { Text = blog.Title }; //this is workspace subtitle, not collection appSvc.GetWorkspace().Subtitle = new AtomSubtitle() { Text = blog.SubTitle }; } var users = ImportUsers(blog, appSvc); if (users.FirstOrDefault() != null && mode == ImportMode.New) { //user is likely not authenticated when new, so auth them System.Threading.Thread.CurrentPrincipal = new GenericPrincipal(users[0], null); } ImportCategories(blog, coll); AtomPubService.UpdateService(appSvc); ImportPosts(entryCollectionId, pagesCollectionId, mediaCollectionId, mode, blog); //make sure there is an About and Blogroll pages if (mode == ImportMode.New && pagesCollectionId != null) { var entries = AtomPubService.GetEntries(new EntryCriteria() { EntryId = pagesCollectionId.AddPath("About"), Approved = true }, 0, 1); if (entries.Count() == 0) { AtomPubService.CreateEntry(pagesCollectionId, new AtomEntry() { Title = new AtomTitle() { Text = "About Me" }, Content = new AtomContent() { Text = "This is a temporary placeholder until I can update this entry." }, }, "About"); } entries = AtomPubService.GetEntries(new EntryCriteria() { EntryId = pagesCollectionId.AddPath("Blogroll"), Approved = true }, 0, 1); if (entries.Count() == 0) { AtomPubService.CreateEntry(pagesCollectionId, new AtomEntry() { Title = new AtomTitle() { Text = "Blog Roll" }, Content = new AtomContent() { Type = "html", Text = "<ul><li><a href='http://atomsite.net'>AtomSite.net</a></li></ul>" }, }, "Blogroll"); } } ResetTrackbacks(entryCollectionId, appSvc); ResetTrackbacks(pagesCollectionId, appSvc); ResetTrackbacks(mediaCollectionId, appSvc); LogProgress("Finished!", 100); } catch (Exception ex) { LogService.Error(ex); LogProgress(System.Web.HttpUtility.HtmlEncode(ex.Message), 100); } }