public async Task Import( int userId, string fileName, int blogRootNode, bool overwrite, string regexMatch, string regexReplace, bool publishAll, bool exportDisqusXml = false, bool importFirstImage = false) { try { if (!File.Exists(fileName)) { throw new FileNotFoundException("File not found: " + fileName); } var root = _applicationContext.Services.ContentService.GetById(blogRootNode); if (root == null) { throw new InvalidOperationException("No node found with id " + blogRootNode); } if (!root.ContentType.Alias.InvariantEquals("Articulate")) { throw new InvalidOperationException("The node with id " + blogRootNode + " is not an Articulate root node"); } using (var stream = File.OpenRead(fileName)) { var document = new BlogMLDocument(); document.Load(stream); stream.Position = 0; var xdoc = XDocument.Load(stream); var authorIdsToName = ImportAuthors(userId, root, document.Authors); var imported = await ImportPosts(userId, xdoc, root, document.Posts, document.Authors.ToArray(), document.Categories.ToArray(), authorIdsToName, overwrite, regexMatch, regexReplace, publishAll, importFirstImage); if (exportDisqusXml) { var exporter = new DisqusXmlExporter(); var xDoc = exporter.Export(imported, document); using (var memStream = new MemoryStream()) { xDoc.Save(memStream); _fileSystem.AddFile("DisqusXmlExport.xml", memStream, true); } } } } catch (Exception ex) { HasErrors = true; LogHelper.Error <BlogMlImporter>("Importing failed with errors", ex); } }
public async Task Import( int userId, string fileName, int blogRootNode, bool overwrite, string regexMatch, string regexReplace, bool publishAll, bool exportDisqusXml = false) { try { if (!File.Exists(fileName)) { throw new FileNotFoundException("File not found: " + fileName); } var root = _applicationContext.Services.ContentService.GetById(blogRootNode); if (root == null) { throw new InvalidOperationException("No node found with id " + blogRootNode); } if (!root.ContentType.Alias.InvariantEquals("Articulate")) { throw new InvalidOperationException("The node with id " + blogRootNode + " is not an Articulate root node"); } using (var stream = File.OpenRead(fileName)) { var document = new BlogMLDocument(); document.Load(stream); stream.Position = 0; var xdoc = XDocument.Load(stream); var authorIdsToName = ImportAuthors(userId, root, document.Authors); var imported = await ImportPosts(userId, xdoc, root, document.Posts, document.Authors.ToArray(), document.Categories.ToArray(), authorIdsToName, overwrite, regexMatch, regexReplace, publishAll); if (exportDisqusXml) { var exporter = new DisqusXmlExporter(); var xDoc = exporter.Export(imported, document); using (var memStream = new MemoryStream()) { xDoc.Save(memStream); _fileSystem.AddFile("DisqusXmlExport.xml", memStream, true); } } } } catch (Exception ex) { HasErrors = true; LogHelper.Error<BlogMlImporter>("Importing failed with errors", ex); } }