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));
        }
        public override CacheDependency GetCacheDependency(
            string virtualPath,
            IEnumerable virtualPathDependencies,
            DateTime utcStart)
        {
            bool isLess;

            if (IsStyleSheet(virtualPath, out isLess))
            {
                if (isLess)
                {
                    // the LESS HTTP handler made the call
                    // [...]
                }
                else
                {
                    // the Bundler made the call
                    var bundle = BundleTable.Bundles.GetBundleFor(virtualPath);
                    if (bundle == null)
                    {
                        return(_previous.GetCacheDependency(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(_previous.GetCacheDependency(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   = ResolveCurrentStoreId();
                    string themeName = ResolveCurrentThemeName();
                    // invalidate the cache when variables change
                    string cacheKey        = AspNetCache.BuildKey(FrameworkCacheConsumer.BuildThemeVarsCacheKey(themeName, storeId));
                    var    cacheDependency = new CacheDependency(fileDependencies.Select(x => HostingEnvironment.MapPath(x)).ToArray(), new string[] { cacheKey }, utcStart);
                    return(cacheDependency);
                }

                return(null);
            }

            return(_previous.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart));
        }
        public override VirtualFile GetFile(string virtualPath)
        {
            if (ThemeHelper.PathIsThemeVars(virtualPath))
            {
                string themeName = ResolveCurrentThemeName();
                int    storeId   = ResolveCurrentStoreId();
                return(new ThemeVarsVirtualFile(virtualPath, themeName, storeId));
            }

            return(_previous.GetFile(virtualPath));
        }
        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);
            }
        }
        public override bool FileExists(string virtualPath)
        {
            if (ThemeHelper.PathIsThemeVars(virtualPath))
            {
                return(true);
            }

            var result = GetResolveResult(virtualPath);

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

            return(_previous.FileExists(virtualPath));
        }
 public override bool FileExists(string virtualPath)
 {
     return(ThemeHelper.PathIsThemeVars(virtualPath) || _previous.FileExists(virtualPath));
 }