/// <summary> /// Determines whether the specified file exists /// </summary> /// <param name="path">The file to check</param> /// <returns>true if the caller has the required permissions and path contains /// the name of an existing file; otherwise, false</returns> public bool FileExists(string path) { if (path == null) { throw new ArgumentNullException("path", string.Format(CoreStrings.Common_ArgumentIsNull, "path")); } bool result = _virtualFileSystemWrapper.FileExists(path); return(result); }
/// <summary> /// Gets a appropriate version of asset virtual file path based /// on list of file extensions /// </summary> /// <param name="assetVirtualPath">Asset virtual file path</param> /// <param name="extensions">List of file extensions</param> /// <returns>Asset virtual file path with modified extension</returns> protected string ProbeAssetFilePath(string assetVirtualPath, string[] extensions) { string changedVirtualPath = string.Empty; foreach (string extension in extensions) { changedVirtualPath = Path.ChangeExtension(assetVirtualPath, extension); if (_virtualFileSystemWrapper.FileExists(changedVirtualPath)) { return(changedVirtualPath); } } throw new FileNotFoundException(string.Format(Strings.Common_FileNotExist, changedVirtualPath)); }
/// <summary> /// Gets a custom statistics from specified file /// </summary> /// <param name="path">Virtual path to file, that contains custom statistics</param> /// <returns>Custom statistics in JSON format</returns> private string GetCustomStatisticsFromFile(string path) { if (string.IsNullOrWhiteSpace(path)) { return(null); } if (!_virtualFileSystemWrapper.FileExists(path)) { throw new FileNotFoundException(string.Format(CoreStrings.Common_FileNotExist, path)); } string statistics = _virtualFileSystemWrapper.GetFileTextContent(path); return(statistics); }
/// <summary> /// Determines whether the specified file exists /// </summary> /// <param name="path">The file to check</param> /// <returns>true if the caller has the required permissions and path contains /// the name of an existing file; otherwise, false</returns> public bool FileExists(string path) { if (path == null) { throw new ArgumentNullException( nameof(path), string.Format(CoreStrings.Common_ArgumentIsNull, nameof(path)) ); } if (DefaultLibraryExists(path)) { return(true); } bool result = _virtualFileSystemWrapper.FileExists(path); return(result); }
/// <summary> /// Loads a JS externs dependencies from virtual file system /// </summary> /// <param name="externsFilePaths">List of JS externs file paths</param> /// <returns>List of JS externs dependencies</returns> private DependencyCollection LoadExternsDependenciesFromVirtualFileSystem(IList <string> externsFilePaths) { var externsDependencies = new DependencyCollection(); foreach (string externsFilePath in externsFilePaths) { if (_virtualFileSystemWrapper.FileExists(externsFilePath)) { string content = _virtualFileSystemWrapper.GetFileTextContent(externsFilePath); externsDependencies.Add(new Dependency(externsFilePath, content, true)); } else { throw new FileNotFoundException( string.Format(CoreStrings.Common_FileNotExist, externsFilePath)); } } return(externsDependencies); }
public void ProcessRequest(HttpContextBase context) { _context = context; var request = context.Request; var response = context.Response; Uri assetUri = request.Url; if (assetUri == null) { throw new HttpException(500, Strings.Common_ValueIsNull); } string assetVirtualPath = assetUri.LocalPath; if (string.IsNullOrWhiteSpace(assetVirtualPath)) { throw new HttpException(500, Strings.Common_ValueIsEmpty); } if (!_virtualFileSystemWrapper.FileExists(assetVirtualPath)) { throw new HttpException(404, string.Format(Strings.Common_FileNotExist, assetVirtualPath)); } string bundleVirtualPath = request.QueryString[Constants.Common.BundleVirtualPathQueryStringParameterName]; if (string.IsNullOrWhiteSpace(bundleVirtualPath) && IsStaticAsset) { // Delegate a processing of asset to the instance of `System.Web.StaticFileHandler` type ProcessStaticAssetRequest(context); return; } string content; try { content = GetProcessedAssetContent(assetVirtualPath, bundleVirtualPath); } catch (HttpException) { throw; } catch (AssetTranslationException e) { throw new HttpException(500, e.Message, e); } catch (AssetPostProcessingException e) { throw new HttpException(500, e.Message, e); } catch (FileNotFoundException e) { throw new HttpException(500, string.Format(Strings.AssetHandler_DependencyNotFound, e.Message, e)); } catch (Exception e) { throw new HttpException(500, string.Format(Strings.AssetHandler_UnknownError, e.Message, e)); } var clientCache = response.Cache; if (_assetHandlerConfig.DisableClientCache) { response.StatusCode = 200; response.StatusDescription = "OK"; // Configure browser cache clientCache.SetCacheability(HttpCacheability.NoCache); clientCache.SetExpires(DateTime.UtcNow.AddYears(-1)); clientCache.SetValidUntilExpires(false); clientCache.SetNoStore(); clientCache.SetNoServerCaching(); // Output text content of asset response.ContentType = ContentType; response.Write(content); } else { // Generate a ETag value and check it string eTag = GenerateAssetETag(content); bool eTagChanged = IsETagHeaderChanged(request, eTag); // Add a special HTTP headers to ensure that // asset caching in browsers if (eTagChanged) { response.StatusCode = 200; response.StatusDescription = "OK"; } else { response.StatusCode = 304; response.StatusDescription = "Not Modified"; // Set to 0 to prevent client waiting for data response.AddHeader("Content-Length", "0"); } // Add a Bundle Transformer's copyright HTTP header response.AddHeader("X-Asset-Transformation-Powered-By", "Bundle Transformer"); clientCache.SetCacheability(HttpCacheability.Public); clientCache.SetExpires(DateTime.UtcNow.AddYears(-1)); clientCache.SetValidUntilExpires(true); clientCache.AppendCacheExtension("must-revalidate"); clientCache.SetNoServerCaching(); clientCache.VaryByHeaders["If-None-Match"] = true; clientCache.SetETag(eTag); if (eTagChanged) { // Output text content of asset response.ContentType = ContentType; response.Write(content); } } context.ApplicationInstance.CompleteRequest(); }