/// <summary> /// Processes the incoming HTTP request that and returns the specified stylesheets. /// </summary> /// <param name="context">An HTTPContext object that provides references to the intrinsic server objects used to service HTTP requests</param> public void ProcessRequest(HttpContext context) { // Disable debugging if (!DebugHelper.DebugResources) { // Disable the debugging RequestSettings requestSettings = RequestSettings.Current; requestSettings.DebugFiles = false; requestSettings.DebugSecurity = false; requestSettings.DebugCache = false; requestSettings.DebugOutput = false; requestSettings.DebugRequest = false; requestSettings.DebugSQLQueries = false; OutputHelper.LogCurrentOutputToFile = false; } // When no parameters are specified, simply end the response if (!context.Request.QueryString.HasKeys()) { SendNoContent(context); } if (QueryHelper.Contains(JS_FILE_ARGUMENT)) { // Process JS file request ProcessJSFileRequest(context); return; } // Transfer to newsletter CSS string newsletterTemplateName = QueryHelper.GetString(NEWSLETTERCSS_DATABASE_ARGUMENT, ""); if (!String.IsNullOrEmpty(newsletterTemplateName)) { context.Server.Transfer("~/CMSModules/Newsletters/CMSPages/GetCSS.aspx?newslettertemplatename=" + newsletterTemplateName); return; } // Load the settings CMSCssSettings settings = new CMSCssSettings(); settings.LoadFromQueryString(); // Process the request ProcessRequest(context, settings); }
/// <summary> /// Processes the given request. /// </summary> /// <param name="context">Http context</param> /// <param name="settings">CSS Settings</param> private static void ProcessRequest(HttpContext context, CMSCssSettings settings) { CMSOutputResource resource = null; // Get cache setting for physical files int cacheMinutes = PhysicalFilesCacheMinutes; int clientCacheMinutes = cacheMinutes; bool hasVirtualContent = settings.HasVirtualContent(); if (hasVirtualContent) { // Use specific cache settings if DB resources are requested cacheMinutes = CacheMinutes; clientCacheMinutes = ClientCacheMinutes; } // Try to get data from cache (or store them if not found) using (CachedSection <CMSOutputResource> cachedSection = new CachedSection <CMSOutputResource>(ref resource, cacheMinutes, true, null, "getresource", CMSContext.CurrentSiteName, context.Request.QueryString, URLHelper.IsSSL)) { // Not found in cache; load the data if (cachedSection.LoadData) { // Load the data resource = GetResource(settings, URLHelper.Url.ToString(), cachedSection.Cached); // Cache the file if ((resource != null) && (cachedSection.Cached)) { cachedSection.CacheDependency = resource.CacheDependency; cachedSection.Data = resource; } } } // Send response if there's something to send if (resource != null) { bool allowCache = (!hasVirtualContent || ClientCacheEnabled) && CacheHelper.AlwaysCacheResources; SendResponse(context, resource, MimeTypeHelper.GetMimetype(CSS_FILE_EXTENSION), allowCache, CSSHelper.StylesheetMinificationEnabled, clientCacheMinutes); } else { SendNotFoundResponse(context); } }
/// <summary> /// Processes the incoming HTTP request that and returns the specified stylesheets. /// </summary> /// <param name="context">An HTTPContext object that provides references to the intrinsic server objects used to service HTTP requests</param> public void ProcessRequest(HttpContext context) { // Disable debugging if (!DebugHelper.DebugResources) { // Disable the debugging RequestSettings requestSettings = RequestSettings.Current; requestSettings.DebugFiles = false; requestSettings.DebugSecurity = false; requestSettings.DebugCache = false; requestSettings.DebugOutput = false; requestSettings.DebugRequest = false; requestSettings.DebugSQLQueries = false; OutputHelper.LogCurrentOutputToFile = false; } // When no parameters are specified, simply end the response if (!context.Request.QueryString.HasKeys()) { SendNoContent(context); } // Process JS file request if (QueryHelper.Contains(JS_FILE_ARGUMENT)) { ProcessJSFileRequest(context); return; } // Process QR code request if (QueryHelper.Contains(QR_CODE_ARGUMENT)) { ProcessQRCodeRequest(context); return; } // Process image file request if (QueryHelper.Contains(IMAGE_FILE_ARGUMENT)) { ProcessImageFileRequest(context); return; } // Process JS file request if (QueryHelper.Contains(FILE_ARGUMENT)) { ProcessFileRequest(context); return; } // Transfer to newsletter CSS string newsletterTemplateName = QueryHelper.GetString(NEWSLETTERCSS_DATABASE_ARGUMENT, ""); if (!String.IsNullOrEmpty(newsletterTemplateName)) { context.Server.Transfer("~/CMSModules/Newsletters/CMSPages/GetCSS.aspx?newslettertemplatename=" + newsletterTemplateName); return; } // Load the settings CMSCssSettings settings = new CMSCssSettings(); settings.LoadFromQueryString(); // Process the request ProcessRequest(context, settings); }
/// <summary> /// Processes the given request. /// </summary> /// <param name="context">Http context</param> /// <param name="settings">CSS Settings</param> private static void ProcessRequest(HttpContext context, CMSCssSettings settings) { CMSOutputResource resource = null; // Get cache setting for physical files int cacheMinutes = PhysicalFilesCacheMinutes; int clientCacheMinutes = cacheMinutes; bool hasVirtualContent = settings.HasVirtualContent(); if (hasVirtualContent) { // Use specific cache settings if DB resources are requested cacheMinutes = CacheMinutes; clientCacheMinutes = ClientCacheMinutes; } // Try to get data from cache (or store them if not found) using (CachedSection<CMSOutputResource> cs = new CachedSection<CMSOutputResource>(ref resource, cacheMinutes, true, null, "getresource", CMSContext.CurrentSiteName, context.Request.QueryString, URLHelper.IsSSL)) { // Not found in cache; load the data if (cs.LoadData) { // Load the data resource = GetResource(settings, URLHelper.Url.ToString(), cs.Cached); // Cache the file if ((resource != null) && cs.Cached) { cs.CacheDependency = resource.CacheDependency; } cs.Data = resource; } } // Send response if there's something to send if (resource != null) { bool allowCache = (!hasVirtualContent || ClientCacheEnabled) && CacheHelper.AlwaysCacheResources; SendResponse(context, resource, allowCache, CSSHelper.StylesheetMinificationEnabled, clientCacheMinutes, false); } else { SendNotFoundResponse(context); } }
/// <summary> /// Retrieves the specified resources and wraps them in an data container. /// </summary> /// <param name="settings">CSS settings</param> /// <param name="name">Resource name</param> /// <param name="cached">If true, the result will be cached</param> /// <returns>The data container with the resulting stylesheet data</returns> private static CMSOutputResource GetResource(CMSCssSettings settings, string name, bool cached) { List<CMSOutputResource> resources = new List<CMSOutputResource>(); // Add files if (settings.Files != null) { foreach (CMSItem item in settings.Files) { // Get the resource CMSOutputResource resource = GetFile(item, CSS_FILE_EXTENSION, true, false); resources.Add(resource); } } // Add stylesheets if (settings.Stylesheets != null) { foreach (CMSItem item in settings.Stylesheets) { // Get the resource CMSOutputResource resource = GetStylesheet(item); resources.Add(resource); } } // Add web part containers if (settings.Containers != null) { foreach (CMSItem item in settings.Containers) { // Get the resource CMSOutputResource resource = GetContainer(item); resources.Add(resource); } } // Add web parts if (settings.WebParts != null) { foreach (CMSItem item in settings.WebParts) { // Get the resource CMSOutputResource resource = GetWebPart(item); resources.Add(resource); } } // Add templates if (settings.Templates != null) { foreach (CMSItem item in settings.Templates) { // Get the resource CMSOutputResource resource = GetTemplate(item); resources.Add(resource); } } // Add layouts if (settings.Layouts != null) { foreach (CMSItem item in settings.Layouts) { // Get the resource CMSOutputResource resource = GetLayout(item); resources.Add(resource); } } // Add device layouts if (settings.DeviceLayouts != null) { foreach (CMSItem item in settings.DeviceLayouts) { // Get the resource CMSOutputResource resource = GetDeviceLayout(item); resources.Add(resource); } } // Add transformation containers if (settings.Transformations != null) { foreach (CMSItem item in settings.Transformations) { // Get the resource CMSOutputResource resource = GetTransformation(item); resources.Add(resource); } } // Add web part layouts if (settings.WebPartLayouts != null) { foreach (CMSItem item in settings.WebPartLayouts) { // Get the resource CMSOutputResource resource = GetWebPartLayout(item); resources.Add(resource); } } // Combine to a single output CMSOutputResource result = CombineResources(resources); settings.ComponentFiles = result.ComponentFiles; result.ContentType = MimeTypeHelper.GetMimetype(CSS_FILE_EXTENSION); // Resolve the macros if (CSSHelper.ResolveMacrosInCSS) { var context = new MacroContext() { TrackCacheDependencies = cached }; if (cached) { // Add the default dependencies context.AddCacheDependencies(settings.GetCacheDependencies()); context.AddFileCacheDependencies(settings.GetFileCacheDependencies()); } result.Data = CMSContext.ResolveMacros(result.Data, context); if (cached) { // Add cache dependency result.CacheDependency = CacheHelper.GetCacheDependency(context.FileCacheDependencies, context.CacheDependencies); } } else if (cached) { // Only the cache dependency from settings result.CacheDependency = settings.GetCacheDependency(); } result.Data = HTMLHelper.ResolveCSSClientUrls(result.Data, URLHelper.GetAbsoluteUrl("~/CMSPages/GetResource.ashx")); // Minify MinifyResource(result, new CssMinifier(), CSSHelper.StylesheetMinificationEnabled && settings.EnableMinification, settings.EnableCompression); return result; }
/// <summary> /// Retrieves the specified resources and wraps them in an data container. /// </summary> /// <param name="settings">CSS settings</param> /// <param name="name">Resource name</param> /// <param name="cached">If true, the result will be cached</param> /// <returns>The data container with the resulting stylesheet data</returns> private static CMSOutputResource GetResource(CMSCssSettings settings, string name, bool cached) { List <CMSOutputResource> resources = new List <CMSOutputResource>(); // Add files if (settings.Files != null) { foreach (string item in settings.Files) { // Get the resource CMSOutputResource resource = GetFile(item, CSS_FILE_EXTENSION); resources.Add(resource); } } // Add stylesheets if (settings.Stylesheets != null) { foreach (string item in settings.Stylesheets) { // Get the resource CMSOutputResource resource = GetStylesheet(item); resources.Add(resource); } } // Add web part containers if (settings.Containers != null) { foreach (string item in settings.Containers) { // Get the resource CMSOutputResource resource = GetContainer(item); resources.Add(resource); } } // Add web parts if (settings.WebParts != null) { foreach (string item in settings.WebParts) { // Get the resource CMSOutputResource resource = GetWebPart(item); resources.Add(resource); } } // Add templates if (settings.Templates != null) { foreach (string item in settings.Templates) { // Get the resource CMSOutputResource resource = GetTemplate(item); resources.Add(resource); } } // Add layouts if (settings.Layouts != null) { foreach (string item in settings.Layouts) { // Get the resource CMSOutputResource resource = GetLayout(item); resources.Add(resource); } } // Add transformation containers if (settings.Transformations != null) { foreach (string item in settings.Transformations) { // Get the resource CMSOutputResource resource = GetTransformation(item); resources.Add(resource); } } // Add web part layouts if (settings.WebPartLayouts != null) { foreach (string item in settings.WebPartLayouts) { // Get the resource CMSOutputResource resource = GetWebPartLayout(item); resources.Add(resource); } } // Combine to a single output CMSOutputResource result = CombineResources(resources); // Resolve the macros if (CSSHelper.ResolveMacrosInCSS) { MacroContext context = new MacroContext() { TrackCacheDependencies = cached }; if (cached) { // Add the default dependencies context.AddCacheDependencies(settings.GetCacheDependencies()); context.AddFileCacheDependencies(settings.GetFileCacheDependencies()); } result.Data = CMSContext.ResolveMacros(result.Data, context); if (cached) { // Add cache dependency result.CacheDependency = CacheHelper.GetCacheDependency(context.FileCacheDependencies, context.CacheDependencies); } } else if (cached) { // Only the cache dependency from settings result.CacheDependency = settings.GetCacheDependency(); } // Minify MinifyResource(result, mCssMinifier, CSSHelper.StylesheetMinificationEnabled && settings.EnableMinification, settings.EnableMinification); return(result); }
/// <summary> /// Retrieves the specified resources and wraps them in an data container. /// </summary> /// <param name="settings">CSS settings</param> /// <param name="name">Resource name</param> /// <param name="cached">If true, the result will be cached</param> /// <returns>The data container with the resulting stylesheet data</returns> private static CMSOutputResource GetResource(CMSCssSettings settings, string name, bool cached) { List<CMSOutputResource> resources = new List<CMSOutputResource>(); // Add files if (settings.Files != null) { foreach (string item in settings.Files) { // Get the resource CMSOutputResource resource = GetFile(item, CSS_FILE_EXTENSION); resources.Add(resource); } } // Add stylesheets if (settings.Stylesheets != null) { foreach (string item in settings.Stylesheets) { // Get the resource CMSOutputResource resource = GetStylesheet(item); resources.Add(resource); } } // Add web part containers if (settings.Containers != null) { foreach (string item in settings.Containers) { // Get the resource CMSOutputResource resource = GetContainer(item); resources.Add(resource); } } // Add web parts if (settings.WebParts != null) { foreach (string item in settings.WebParts) { // Get the resource CMSOutputResource resource = GetWebPart(item); resources.Add(resource); } } // Add templates if (settings.Templates != null) { foreach (string item in settings.Templates) { // Get the resource CMSOutputResource resource = GetTemplate(item); resources.Add(resource); } } // Add layouts if (settings.Layouts != null) { foreach (string item in settings.Layouts) { // Get the resource CMSOutputResource resource = GetLayout(item); resources.Add(resource); } } // Add transformation containers if (settings.Transformations != null) { foreach (string item in settings.Transformations) { // Get the resource CMSOutputResource resource = GetTransformation(item); resources.Add(resource); } } // Add web part layouts if (settings.WebPartLayouts != null) { foreach (string item in settings.WebPartLayouts) { // Get the resource CMSOutputResource resource = GetWebPartLayout(item); resources.Add(resource); } } // Combine to a single output CMSOutputResource result = CombineResources(resources); // Resolve the macros if (CSSHelper.ResolveMacrosInCSS) { MacroContext context = new MacroContext() { TrackCacheDependencies = cached }; if (cached) { // Add the default dependencies context.AddCacheDependencies(settings.GetCacheDependencies()); context.AddFileCacheDependencies(settings.GetFileCacheDependencies()); } result.Data = CMSContext.ResolveMacros(result.Data, context); if (cached) { // Add cache dependency result.CacheDependency = CacheHelper.GetCacheDependency(context.FileCacheDependencies, context.CacheDependencies); } } else if (cached) { // Only the cache dependency from settings result.CacheDependency = settings.GetCacheDependency(); } // Minify MinifyResource(result, mCssMinifier, CSSHelper.StylesheetMinificationEnabled && settings.EnableMinification, settings.EnableMinification); return result; }
/// <summary> /// Processes the given request /// </summary> /// <param name="context">Http context</param> /// <param name="settings">CSS Settings</param> private static void ProcessRequest(HttpContext context, CMSCssSettings settings) { CMSOutputResource resource = null; int cacheMinutes = PhysicalFilesCacheMinutes; if (settings.HasVirtualContent()) { cacheMinutes = CacheMinutes; } // Try to get data from cache (or store them if not found) using (CachedSection<CMSOutputResource> cachedSection = new CachedSection<CMSOutputResource>(ref resource, cacheMinutes, true, null, "getresource", CMSContext.CurrentSiteName, context.Request.QueryString)) { // Not found in cache; load the data if (cachedSection.LoadData) { // Load the data resource = GetResource(settings, URLHelper.Url.ToString(), cachedSection.Cached); // Cache the file if ((resource != null) && (cachedSection.Cached)) { cachedSection.CacheDependency = resource.CacheDependency; cachedSection.Data = resource; } } } // Send response if there's something to send if (resource != null) { bool allowCache = ClientCacheEnabled && CacheHelper.AlwaysCacheResources; SendResponse(context, resource, MimeTypeHelper.GetMimetype(CSS_FILE_EXTENSION), allowCache, CSSHelper.StylesheetMinificationEnabled, cacheMinutes); } else { SendNotFoundResponse(context); } }