public void CreateImageFormat_FromJson() { string imageFormatJson = "{\"ImageFormat\":{\"Format\":\"Png\"}}"; var imageOutputProperties = ImageOutputPropertiesFactory.CreateFromJson(imageFormatJson); Assert.Equal(ImageFormat.Png, imageOutputProperties.ImageFormat.Format); }
private IList <ImageOutputProperties> CreateFromJson(string json, string extension, string rootPath) { var imagesOutputProperties = ImageOutputPropertiesFactory.CreateListFromJson(json); ImageFormat imageFormat = new ImageFormat(extension); foreach (var imageOutputProperties in imagesOutputProperties) { imageOutputProperties.FolderPath.IsAbsolute = true; imageOutputProperties.FolderPath.Path = string.Concat(rootPath, "\\", imageOutputProperties.FolderPath.Path); imageOutputProperties.ImageFormat = imageFormat; } return(imagesOutputProperties); }
private IEnumerable <ImageProperties> CreateImageProperties() { var imagesProperties = new List <ImageProperties>(); foreach (string path in ListBoxFiles.Items) { imagesProperties.Add(new ImageProperties() { FileName = Path.GetFileNameWithoutExtension(path), Image = File.ReadAllBytes(path), ImageOutputProperties = this.CheckBoxCustomFormat.IsChecked.GetValueOrDefault()? ImageOutputPropertiesFactory.CreateListFromJson(File.ReadAllText(this.TextBoxCustomFormat.Text)): ImageOutputPropertiesFactory.CreateForXamarin(Path.GetExtension(path), this.TextBoxOutput.Text) }); } return(imagesProperties); }
public ActionResult GenerateImages(IList <HttpPostedFileBase> files, string json) { var rootPath = Server.MapPath(string.Concat("~/App_Data/", Guid.NewGuid().ToString())); var zipFilePath = string.Concat(rootPath, ".zip"); try { foreach (var file in files) { var imageOutputProperties = string.IsNullOrEmpty(json) ? ImageOutputPropertiesFactory.CreateForXamarin(Path.GetExtension(file.FileName), rootPath) : this.CreateFromJson(json, Path.GetExtension(file.FileName), rootPath); ImageProperties imageProperties = new ImageProperties() { FileName = Path.GetFileNameWithoutExtension(file.FileName), Image = file.ToArray(), ImageOutputProperties = imageOutputProperties }; imageOrchestrator.Generate(imageProperties); } ZipFile.CreateFromDirectory(rootPath, zipFilePath, CompressionLevel.Fastest, true); return(File(zipFilePath, "application/zip", "Xamarin_Images.zip")); } catch (Exception ex) { return(View("Index", (object)$"Ups... algo ha ocurrido{ex.StackTrace}")); } finally { if (Directory.Exists(rootPath)) { Directory.Delete(rootPath, true); } } }