public string GetPictureUrl(Media picture, int width = 0, int height = 0, bool returnDefaultIfNotFound = false) { if (picture == null) { return(returnDefaultIfNotFound ? ApplicationEngine.MapUrl(ApplicationConfig.DefaultImagePath, true) : null); } var serveFileDirectory = ServerHelper.MapPath(ApplicationConfig.MediaServeDirectory, true); //abc var fileNameWithoutExtension = _localFileProvider.GetFileNameWithoutExtension(picture.SystemName); //.jpg var extension = _localFileProvider.GetExtension(picture.SystemName); //abc_150_150.jpg var fileName = string.Format(PictureFileNameFormat, fileNameWithoutExtension, width, height, extension); //c:\\www\\abc_150_150.jpg var fileNameWithDirectory = _localFileProvider.CombinePaths(serveFileDirectory, fileName); if (_localFileProvider.FileExists(fileNameWithDirectory)) { return(ApplicationEngine.MapUrl(fileNameWithDirectory)); // /abc_150_150.jpg } //we'll need to create a file //first resize the image from actual file var mediaFileDirectory = ServerHelper.MapPath(ApplicationConfig.MediaDirectory, true); var originalFile = _localFileProvider.CombinePaths(mediaFileDirectory, picture.SystemName); //does the original file exist? if (!_localFileProvider.FileExists(originalFile)) { return(returnDefaultIfNotFound ? ApplicationEngine.MapUrl(ApplicationConfig.DefaultImagePath, true) : null); } //read original file var originalFileBytes = _localFileProvider.ReadBytes(originalFile); //resize the image var resizedBytes = _imageProcessor.ResizeImage(originalFileBytes, width, height); //write this to disk var resizedFileName = SafeWriteBytesToFile(fileName, serveFileDirectory, resizedBytes); fileNameWithDirectory = _localFileProvider.CombinePaths(serveFileDirectory, resizedFileName); //now return return(ApplicationEngine.MapUrl(fileNameWithDirectory)); // /abc_150_150.jpg }
private ThemeInfo GetThemeInfo(DirectoryInfo directoryInfo) { var themeConfigPath = _localFileProvider.CombinePaths(_themeDirectory, directoryInfo.Name, "config.json"); if (_localFileProvider.FileExists(themeConfigPath)) { var configJson = _localFileProvider.ReadAllText(themeConfigPath); var themeInfo = _dataSerializer.DeserializeAs <ThemeInfo>(configJson); var imagePath = _localFileProvider.CombinePaths(_themeDirectory, directoryInfo.Name, "Assets", "theme.jpg"); //do we have an image file? if (_localFileProvider.FileExists(imagePath)) { themeInfo.ThumbnailUrl = $"/{directoryInfo.Name}/assets/theme.jpg"; } themeInfo.DirectoryName = directoryInfo.Name; return(themeInfo); } return(null); }
public string GetThemeViewPath(string viewName, bool ignoreAdminViews = false) { viewName = ValidateViewName(viewName); return(GetViewLocations(ignoreAdminViews) .Select(x => _localFileProvider.CombinePaths(x, viewName)) .FirstOrDefault(x => _localFileProvider.FileExists(x))); }
private string GetBundle(string[] inputFiles, string type) { var bundleFileProcessor = new BundleFileProcessor(); var bundle = new BundlerMinifier.Bundle(); //we wil store the file names with date of modification to keep track whether a new bundle should be generated or not //any minor modification will cause regeneration of the bundle //we do this because it is a performance intensive operation and the we should only do it when needed var distinctFiles = inputFiles.Distinct().ToList(); var fileNamesWithDates = new List <string>(); foreach (var inputFile in distinctFiles) { //the input file can either be 1. theme-css 2. plugin-css 3. admin-css 4. common-css //check them one by one var file = ServerHelper.MapPath("~/Content/Themes" + inputFile); if (!_localFileProvider.FileExists(file)) { //plugins file = ServerHelper.MapPath("~/" + inputFile); if (!_localFileProvider.FileExists(file)) { //administration & common file = ServerHelper.MapPath("~/" + inputFile, true); if (!_localFileProvider.FileExists(file)) { continue; //can't do anything...the file doesn't exist } } } bundle.InputFiles.Add(file); var modDate = _localFileProvider.GetLastModifiedDateTime(file); fileNamesWithDates.Add($"{file}:{modDate}"); } var outputFilePart1 = GetOutputFileName(fileNamesWithDates); var outputFilePart2 = GetOutputFileName(distinctFiles); var outputFile = outputFilePart1 + "_" + outputFilePart2; var bundlesDirectory = ServerHelper.MapPath(ApplicationConfig.BundlesDirectory, true); var bundleFileName = bundlesDirectory + "/" + outputFile + $".min.{type}"; bundle.OutputFileName = bundleFileName; //do we need to generate the bundle? if (!_localFileProvider.FileExists(bundleFileName)) { //delete the existing bundles of these files try { _localFileProvider.DeleteFiles(bundlesDirectory, $"*_{outputFilePart2}.min.{type}*"); } catch { //do nothing...the file must be locked...will try next time } bundle.FileName = bundleFileName + ".json"; BundleMinifier.ErrorMinifyingFile += BundleMinifier_ErrorMinifyingFile; bundleFileProcessor.Process(bundle.FileName, new List <BundlerMinifier.Bundle>() { bundle }); } //if operation succeeded, return the url, else null if (bundle.OutputFileName == null) { return(null); } //also create a gzipped version as well using (var bundleFileStream = File.OpenRead(bundleFileName)) using (var compressedFileStream = File.Create(bundleFileName + ".gz")) { using (var compressionStream = new GZipStream(compressedFileStream, CompressionMode.Compress)) { bundleFileStream.CopyTo(compressionStream); } } return(bundle.OutputFileName == null ? null : ApplicationEngine.MapUrl(bundleFileName)); }