コード例 #1
0
ファイル: BundleManager.cs プロジェクト: eByte23/Smidge
        /// <summary>
        /// Returns the ordered collection of files for the bundle
        /// </summary>
        /// <param name="bundleName"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        public IEnumerable<IWebFile> GetFiles(string bundleName, HttpRequest request)
        {
            BundleFileCollection collection;
            if (!_bundles.TryGetValue(bundleName, out collection)) return null;

            //the file type in the bundle will always be the same
            var first = collection.Files.FirstOrDefault();
            if (first == null) return Enumerable.Empty<IWebFile>();

            var orderedSet = new OrderedFileSet(collection.Files, _fileSystemHelper, request,
                _processorFactory.GetDefault(first.DependencyType));
            var ordered = orderedSet.GetOrderedFileSet();

            //call the registered callback if any is set
            return collection.OrderingCallback == null ? ordered : collection.OrderingCallback(ordered);
        }
コード例 #2
0
ファイル: SmidgeHelper.cs プロジェクト: eByte23/Smidge
        /// <summary>
        /// Generates teh URLs for a given file set
        /// </summary>
        /// <param name="files"></param>
        /// <param name="fileType"></param>
        /// <param name="pipeline"></param>
        /// <param name="debug"></param>
        /// <returns></returns>
        private async Task<IEnumerable<string>> GenerateUrlsAsync(
            IEnumerable<IWebFile> files, 
            WebFileType fileType,            
            PreProcessPipeline pipeline = null,
            bool debug = false)
        {
            var result = new List<string>();

            var orderedSet = new OrderedFileSet(files,
                _fileSystemHelper, _request,
                pipeline ?? _processorFactory.GetDefault(fileType));
            var orderedFiles = orderedSet.GetOrderedFileSet();

            if (debug)
            {
                return orderedFiles.Select(x => x.FilePath);
            }
            else
            {
                var compression = _request.GetClientCompression();

                //Get the file collection used to create the composite URLs and the external requests
                var fileBatches = _fileBatcher.GetCompositeFileCollectionForUrlGeneration(orderedFiles);

                foreach (var batch in fileBatches)
                {
                    //if it's external, the rule is that a WebFileBatch can only contain a single external file
                    // it's path will be normalized as an external url so we just use it
                    if (batch.IsExternal)
                    {
                        result.Add(batch.Single().Original.FilePath);
                    }
                    else
                    {
                        //Get the URLs for the batch, this could be more than one resulting URL depending on how many
                        // files are in the batch and the max url length
                        var compositeUrls = _context.UrlCreator.GetUrls(batch.Select(x => x.Hashed), fileType == WebFileType.Css ? ".css" : ".js");

                        foreach (var u in compositeUrls)
                        {
                            //now we need to determine if these files have already been minified
                            var compositeFilePath = _fileSystemHelper.GetCurrentCompositeFilePath(compression, u.Key);
                            if (!File.Exists(compositeFilePath))
                            {
                                //need to process/minify these files - need to use their original paths of course
                                foreach (var file in batch.Select(x => x.Original))
                                {
                                    await _fileManager.ProcessAndCacheFileAsync(file);
                                }
                            }
                            result.Add(u.Url);
                        }
                    }
                }
            }

            return result;

        }