Пример #1
0
        protected override IAsset TranslateAsset(IAsset asset, ITransformer transformer, bool isDebugMode)
        {
            bool validationMode = ThemeHelper.IsStyleValidationRequest();

            try
            {
                var processedAsset = TranslateAssetCore(asset, transformer, validationMode || isDebugMode);

                if (transformer == null && !validationMode)
                {
                    // BundleTransformer does NOT PostProcess when transformer instance is null,
                    // therefore we handle it ourselves, because we desperately need
                    // UrlRewrite even in debug mode.
                    return(AssetTranslorUtil.PostProcessAsset(processedAsset, isDebugMode));
                }
                else
                {
                    return(processedAsset);
                }
            }
            catch (Exception ex)
            {
                if (validationMode)
                {
                    _context.Response.Write(ex.Message);
                    _context.Response.StatusCode = 500;
                    _context.Response.End();
                }

                throw;
            }
        }
Пример #2
0
        protected override string GetCacheKey(string assetVirtualPath, string bundleVirtualPath)
        {
            string cacheKey = base.GetCacheKey(assetVirtualPath, bundleVirtualPath);

            if (IsThemeableRequest())
            {
                var httpContext = HttpContext.Current;
                if (httpContext != null && httpContext.Request != null)
                {
                    var qs = QueryString.Current;
                    if (qs.Count > 0)
                    {
                        // required for Theme editing validation: See Admin.Controllers.ThemeController.ValidateLess()
                        if (qs.Contains("theme"))
                        {
                            EngineContext.Current.Resolve <IThemeContext>().SetRequestTheme(qs["theme"]);
                        }
                        if (qs.Contains("storeId"))
                        {
                            EngineContext.Current.Resolve <IStoreContext>().SetRequestStore(qs["storeId"].ToInt());
                        }
                    }
                }

                cacheKey += "_" + EngineContext.Current.Resolve <IThemeContext>().CurrentTheme.ThemeName + "_" + EngineContext.Current.Resolve <IStoreContext>().CurrentStore.Id;

                if (ThemeHelper.IsStyleValidationRequest())
                {
                    cacheKey += "_Validation";
                }
            }

            return(cacheKey);
        }
Пример #3
0
        internal virtual ExpandoObject GetRawVariables(string themeName, int storeId)
        {
            // we need the Asp.Net cache here in order to define cacheKey dependencies
            bool validationMode = ThemeHelper.IsStyleValidationRequest();

            if (validationMode)
            {
                // Return uncached fresh data (the variables is not nuked yet)
                return(GetRawVariablesCore(themeName, storeId));
            }
            else
            {
                string cacheKey = FrameworkCacheConsumer.BuildThemeVarsCacheKey(themeName, storeId);
                return(HttpRuntime.Cache.GetOrAdd(cacheKey, () =>
                {
                    return GetRawVariablesCore(themeName, storeId);
                }));
            }
        }