async Task GenerateImageAsync(ImageProperties imageProperties)
 {
     await Task.Run(() =>
     {
         imageOrchestrator.Generate(imageProperties);
     });
 }
Esempio n. 2
0
        private void GenerateImages()
        {
            var progressMonitor = IdeApp.Workbench.ProgressMonitors.GetStatusProgressMonitor("Generating images...", Stock.StatusSolutionOperation, false, true, false);

            Loading(true);

            bool   success      = true;
            string outputFolder = _outputFolderEntry.Text;

            for (int i = 0; i < _imagesStore.RowCount; i++)
            {
                var path            = _imagesStore.GetValue(i, _imagePathField);
                var outputAssetName = _imagesStore.GetValue(i, _imageNameField);

                try
                {
                    var outputProperties = _3xRadioButton.Active ?
                                           ImageOutputPropertiesFactory.CreateForXamarin3x(Path.GetExtension(path), outputFolder) :
                                           ImageOutputPropertiesFactory.CreateForXamarin4x(Path.GetExtension(path), outputFolder);


                    var file = File.ReadAllBytes(path);

                    ImageProperties imageProperties = new ImageProperties()
                    {
                        FileName = outputAssetName,
                        Image    = file,
                        ImageOutputProperties = outputProperties
                    };

                    imageOrchestrator.Generate(imageProperties);
                }
                catch (Exception)
                {
                    success = false;
                }
            }

            progressMonitor.EndTask();
            Loading(false);

            if (success)
            {
                FinderUtils.Reveal(Path.Combine(outputFolder, "Images"));
            }
        }
Esempio n. 3
0
        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);
                }
            }
        }