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); } } }