コード例 #1
0
        public override VirtualFile GetFile(string virtualPath)
        {
            if (ThemeHelper.PathIsThemeVars(virtualPath))
            {
                var theme   = ThemeHelper.ResolveCurrentTheme();
                int storeId = ThemeHelper.ResolveCurrentStoreId();
                return(new ThemeVarsVirtualFile(virtualPath, theme.ThemeName, storeId));
            }

            var result = GetResolveResult(virtualPath);

            if (result != null)
            {
                if (!result.IsExplicit)
                {
                    return(new InheritedVirtualThemeFile(result));
                }
                else
                {
                    virtualPath = result.OriginalVirtualPath;
                }
            }

            return(_previous.GetFile(virtualPath));
        }
コード例 #2
0
        public override VirtualFile GetFile(string virtualPath)
        {
            var styleResult = ThemeHelper.IsStyleSheet(virtualPath);

            if (styleResult != null)
            {
                if (styleResult.IsThemeVars)
                {
                    var theme   = ThemeHelper.ResolveCurrentTheme();
                    int storeId = ThemeHelper.ResolveCurrentStoreId();
                    return(new ThemeVarsVirtualFile(virtualPath, styleResult.Extension, theme.ThemeName, storeId));
                }
                else if (styleResult.IsModuleImports)
                {
                    return(new ModuleImportsVirtualFile(virtualPath, ThemeHelper.IsAdminArea()));
                }
            }

            var result = GetResolveResult(virtualPath);

            if (result != null)
            {
                if (!result.IsExplicit)
                {
                    return(new InheritedVirtualThemeFile(result));
                }
                else
                {
                    virtualPath = result.OriginalVirtualPath;
                }
            }

            return(_previous.GetFile(virtualPath));
        }
コード例 #3
0
        public override CacheDependency GetCacheDependency(string virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart)
        {
            bool isLess;
            bool isBundle;

            if (!ThemeHelper.IsStyleSheet(virtualPath, out isLess, out isBundle))
            {
                return(GetCacheDependencyInternal(virtualPath, virtualPathDependencies, utcStart));
            }
            else
            {
                if (!isLess && !isBundle)
                {
                    // it's a static css file (no bundle, no less)
                    return(GetCacheDependencyInternal(virtualPath, virtualPathDependencies, utcStart));
                }

                var arrPathDependencies = virtualPathDependencies.Cast <string>().ToArray();

                // determine the virtual themevars.less import reference
                var themeVarsFile = arrPathDependencies.Where(x => ThemeHelper.PathIsThemeVars(x)).FirstOrDefault();

                if (themeVarsFile.IsEmpty())
                {
                    // no themevars import... so no special considerations here
                    return(GetCacheDependencyInternal(virtualPath, virtualPathDependencies, utcStart));
                }

                // exclude the themevars import from the file dependencies list,
                // 'cause this one cannot be monitored by the physical file system
                var fileDependencies = arrPathDependencies.Except(new string[] { themeVarsFile });

                if (arrPathDependencies.Any())
                {
                    int storeId = ThemeHelper.ResolveCurrentStoreId();
                    var theme   = ThemeHelper.ResolveCurrentTheme();
                    // invalidate the cache when variables change
                    string cacheKey        = AspNetCache.BuildKey(FrameworkCacheConsumer.BuildThemeVarsCacheKey(theme.ThemeName, storeId));
                    var    cacheDependency = new CacheDependency(MapDependencyPaths(fileDependencies), new string[] { cacheKey }, utcStart);
                    return(cacheDependency);
                }

                return(null);
            }
        }