public string GetPath(string file, ITransformFiles transformer = null)
        {
            var basePath = ConfigurationManager.AppSettings["Files.BasePath"];

            var original = $"{_fubuApplicationFiles.GetApplicationPath()}/{basePath}/{file}";

            if (transformer == null)
            {
                return($"{basePath}/{file}");
            }

            var settings = transformer.GetTransformationSettings().ToList();

            var maxWidth  = settings.OfType <MaxWidthTransformationSetting>().Select(x => x.MaxWidth).FirstOrDefault();
            var maxHeight = settings.OfType <MaxHeightTransformationSetting>().Select(x => x.MaxHeight).FirstOrDefault();

            var fileName = file;

            var extension = Path.GetExtension(file);

            if (!string.IsNullOrEmpty(extension))
            {
                fileName = fileName.Replace(extension, "");
            }

            if (maxWidth > 0)
            {
                fileName = string.Concat(fileName, maxWidth, "x");
            }

            if (maxHeight > 0)
            {
                fileName = string.Concat(fileName, maxHeight);
            }

            var filePath =
                $"{_fubuApplicationFiles.GetApplicationPath()}/{basePath}/{fileName}{Path.GetExtension(file)}";

            if (File.Exists(filePath))
            {
                return($"{basePath}/{fileName}{Path.GetExtension(file)}");
            }

            if (!File.Exists(original))
            {
                return($"{basePath}/{fileName}{Path.GetExtension(file)}");
            }

            using (var fileOnDisk = File.Create(filePath))
            {
                Transform(File.Open(original, FileMode.Open), new Size(maxWidth, maxHeight)).CopyTo(fileOnDisk);
                fileOnDisk.Flush();
            }

            return($"{basePath}/{fileName}{Path.GetExtension(file)}");
        }
        public string GetPath(string file, ITransformFiles transformer = null)
        {
            var basePath = ConfigurationManager.AppSettings["Files.BasePath"];

            var original = string.Format("{0}/{1}/{2}", _fubuApplicationFiles.GetApplicationPath(), basePath, file);

            if (transformer != null)
            {
                var settings = transformer.GetTransformationSettings().ToList();

                var maxWidth = settings.OfType<MaxWidthTransformationSetting>().Select(x => x.MaxWidth).FirstOrDefault();
                var maxHeight = settings.OfType<MaxHeightTransformationSetting>().Select(x => x.MaxHeight).FirstOrDefault();

                var fileName = file.Replace(Path.GetExtension(file), "");

                if (maxWidth > 0)
                    fileName = string.Concat(fileName, maxWidth, "x");

                if (maxHeight > 0)
                    fileName = string.Concat(fileName, maxHeight);

                var filePath = string.Format("{0}/{1}/{2}{3}", _fubuApplicationFiles.GetApplicationPath(), basePath, fileName, Path.GetExtension(file));

                if (File.Exists(filePath))
                    return string.Format("{0}/{1}{2}", basePath, fileName, Path.GetExtension(file));

                if (File.Exists(original))
                {
                    using (var fileOnDisk = File.Create(filePath))
                    {
                        Transform(File.Open(original, FileMode.Open), new Size(maxWidth, maxHeight)).CopyTo(fileOnDisk);
                        fileOnDisk.Flush();
                    }
                }

                return string.Format("{0}/{1}{2}", basePath, fileName, Path.GetExtension(file));
            }

            return string.Format("{0}/{1}", basePath, file);
        }
 public FileGeneratorWithTransformer(ITransformFiles transformFiles)
 {
     _fileTransformer = transformFiles;
 }
Example #4
0
 public FileGeneratorWithTransformer(ITransformFiles transformFiles)
 {
     _fileTransformer = transformFiles;
 }