public async Task<ImportModel> PostImportBlogMl(ImportBlogMlModel model) { if (!ModelState.IsValid) { throw new HttpResponseException(Request.CreateValidationErrorResponse(ModelState)); } //save to Temp folder (base path) var fs = new PhysicalFileSystem(IOHelper.MapPath("~/App_Data/Temp")); //there should only be one file so we'll just use the first one var importer = new BlogMlImporter(ApplicationContext, fs); await importer.Import(Security.CurrentUser.Id, model.TempFile, model.ArticulateNodeId, model.Overwrite, model.RegexMatch, model.RegexReplace, model.Publish, model.ExportDisqusXml); //cleanup File.Delete(model.TempFile); if (importer.HasErrors) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Importing failed, see umbraco log for details")); } var mvcUrlHelper = new UrlHelper(new RequestContext()); return new ImportModel { DownloadUrl = mvcUrlHelper.SurfaceAction<ArticulateBlogImportDataController>("DownloadDisqusExport") }; }
public async Task<JObject> PostInitialize(HttpRequestMessage request) { if (!request.Content.IsMimeMultipartContent()) throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); var dir = IOHelper.MapPath("~/App_Data/TEMP/FileUploads"); Directory.CreateDirectory(dir); var provider = new MultipartFormDataStreamProvider(dir); var result = await request.Content.ReadAsMultipartAsync(provider); if (result.FileData.Any()) { if (!Path.GetExtension(result.FileData[0].Headers.ContentDisposition.FileName.Trim('\"')).InvariantEquals(".xml")) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } //save to Temp folder (base path) var fs = new PhysicalFileSystem("~/App_Data/Temp/Articulate"); //there should only be one file so we'll just use the first one var importer = new BlogMlImporter(ApplicationContext, fs); var count = importer.GetPostCount(result.FileData[0].LocalFileName); return JObject.FromObject(new { count = count, tempFile = result.FileData[0].LocalFileName }); } else { throw new InvalidOperationException("Not blogml file was found in the request"); } }
public ImportModel PostExportBlogMl(ExportBlogMlModel model) { var fs = new PhysicalFileSystem("~/App_Data/Temp/Articulate"); var exporter = new BlogMlExporter(UmbracoContext, fs); exporter.Export("BlogMlExport.xml", model.ArticulateNodeId); return new ImportModel { DownloadUrl = Url.GetUmbracoApiService<ArticulateBlogImportController>("GetBlogMlExport") }; }
public HttpResponseMessage GetBlogMlExport() { //save to Temp folder (base path) var fs = new PhysicalFileSystem("~/App_Data/Temp/Articulate"); var fileStream = fs.OpenFile("BlogMlExport.xml"); var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(fileStream) }; result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "BlogMlExport.xml" }; result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); return result; }
public void Can_Write_Serialized_Macro_To_Disc() { // Arrange var serviceStackSerializer = new ServiceStackJsonSerializer(); var serializationService = new SerializationService(serviceStackSerializer); var fileSystem = new PhysicalFileSystem("~/App_Data/Macros"); var macro = new Macro { Alias = "test", CacheByPage = false, CacheByMember = false, DontRender = true, Name = "Test", Xslt = "/xslt/testMacro.xslt", UseInEditor = false }; macro.Properties = new List<IMacroProperty>(); macro.Properties.Add(new MacroProperty { Alias = "level", Name = "Level", SortOrder = 0, PropertyType = new Umbraco.Core.Macros.PropertyTypes.Number() }); macro.Properties.Add(new MacroProperty { Alias = "fixedTitle", Name = "Fixed Title", SortOrder = 1, PropertyType = new Umbraco.Core.Macros.PropertyTypes.Text() }); // Act var json = serializationService.ToStream(macro); string jsonString = json.ResultStream.ToJsonString(); fileSystem.AddFile("test-serialized-Macro.macro", json.ResultStream, true); // Assert Assert.That(json.Success, Is.True); Assert.That(jsonString, Is.Not.Empty); Assert.That(fileSystem.FileExists("test-serialized-Macro.macro"), Is.True); }
public void TearDown() { _fileSystem = null; //Delete all files var fs = new PhysicalFileSystem(SystemDirectories.Scripts); var files = fs.GetFiles("", "*.js"); foreach (var file in files) { fs.DeleteFile(file); } }
public override void TearDown() { base.TearDown(); _masterPageFileSystem = null; _viewsFileSystem = null; //Delete all files var fsMaster = new PhysicalFileSystem(SystemDirectories.Masterpages); var masterPages = fsMaster.GetFiles("", "*.master"); foreach (var file in masterPages) { fsMaster.DeleteFile(file); } var fsViews = new PhysicalFileSystem(SystemDirectories.MvcViews); var views = fsMaster.GetFiles("", "*.cshtml"); foreach (var file in views) { fsMaster.DeleteFile(file); } }