Пример #1
0
        public static IEnumerable <string> ExpandGlobs(IAsset asset, IHostingEnvironment env)
        {
            string root  = asset.GetFileProvider(env).GetFileInfo("/").PhysicalPath;
            var    dir   = new DirectoryInfoWrapper(new DirectoryInfo(root));
            var    files = new List <string>();

            foreach (string sourceFile in asset.SourceFiles)
            {
                var matcher = new Matcher();
                matcher.AddInclude(sourceFile);
                PatternMatchingResult globbingResult = matcher.Execute(dir);
                IEnumerable <string>  fileMatches    = globbingResult.Files.Select(f => f.Path.Replace(root, string.Empty));

                if (!fileMatches.Any())
                {
                    throw new FileNotFoundException($"No files found matching \"{sourceFile}\" exist in \"{dir.FullName}\"");
                }

                files.AddRange(fileMatches.Where(f => !files.Contains(f)));
            }

            asset.Items[_physicalFilesKey] = files;

            return(files);
        }
Пример #2
0
        public static IEnumerable <string> ExpandGlobs(IAsset asset, IHostingEnvironment env)
        {
            var files = new List <string>();

            foreach (string sourceFile in asset.SourceFiles)
            {
                string outSourceFile;
                var    provider = asset.GetFileProvider(env, sourceFile, out outSourceFile);

                if (provider.GetFileInfo(outSourceFile).Exists)
                {
                    if (!files.Contains(sourceFile))
                    {
                        files.Add(sourceFile);
                    }
                }
                else
                {
                    var    fileInfo = provider.GetFileInfo("/");
                    string root     = fileInfo.PhysicalPath;

                    if (root != null)
                    {
                        var dir     = new DirectoryInfoWrapper(new DirectoryInfo(root));
                        var matcher = new Matcher();

                        outSourceFile = outSourceFile.TrimStart('~', '/');

                        matcher.AddInclude(outSourceFile);
                        PatternMatchingResult globbingResult = matcher.Execute(dir);
                        IEnumerable <string>  fileMatches    = globbingResult.Files.Select(f => f.Path.Replace(root, string.Empty));

                        //if (!fileMatches.Any())
                        //{
                        //    throw new FileNotFoundException($"No files found matching \"{sourceFile}\" exist in \"{dir.FullName}\"");
                        //}

                        if (fileMatches.Any())
                        {
                            files.AddRange(fileMatches.Where(f => !files.Contains(f)));
                        }
                    }
                    else
                    {
                        if (!files.Contains(sourceFile))
                        {
                            files.Add(sourceFile);
                        }
                    }
                }
            }

            asset.Items[PhysicalFilesKey] = files;

            return(files);
        }
Пример #3
0
        /// <summary>
        /// Generates a has of the file.
        /// </summary>
        protected string AddFileVersionToPath(string fileName, IAsset asset)
        {
            if (_fileProvider == null)
            {
                _fileProvider = new FileVersionProvider(
                    asset.GetFileProvider(HostingEnvironment),
                    Cache,
                    ViewContext.HttpContext.Request.PathBase);
            }

            return(_fileProvider.AddFileVersionToPath(fileName));
        }
Пример #4
0
        private void AddToCache(string cacheKey, AssetResponse value, IAsset asset, IWebOptimizerOptions options)
        {
            if (options.EnableMemoryCache == true)
            {
                var cacheOptions = new MemoryCacheEntryOptions();
                cacheOptions.SetSlidingExpiration(TimeSpan.FromHours(24));

                foreach (string file in asset.SourceFiles)
                {
                    cacheOptions.AddExpirationToken(asset.GetFileProvider(_env).Watch(file));
                }

                _cache.Set(cacheKey, value, cacheOptions);
            }
        }