public Include(FileBundleSourceItem item, string[] excludePatterns) { AutoDetectEncoding = item.InputEncoding == null; Encoding = item.InputEncoding ?? Encoding.UTF8; ItemTransforms = item.ItemTransforms; Matcher = new Matcher().AddInclude(item.Pattern); Array.ForEach(excludePatterns, p => Matcher.AddExclude(p)); }
public Include(FileBundleSourceItem item, string[] _excludePatterns, Func <IChangeToken> changeTokenFactory, Action changeCallback) { Pattern = item.Pattern; AutoDetectEncoding = item.InputEncoding == null; Encoding = item.InputEncoding ?? Encoding.UTF8; ItemTransforms = item.ItemTransforms; Matcher = new Matcher().AddInclude(item.Pattern); Array.ForEach(_excludePatterns, p => Matcher.AddExclude(p)); _changeCallback = changeCallback; Initialize(changeTokenFactory); }
protected virtual Include CreateInclude(FileBundleSourceItem bundleSourceItem, string[] excludePatterns, bool enableChangeDetection) { Func <IChangeToken> changeTokenFactory; if (enableChangeDetection) { changeTokenFactory = () => _fileProvider.Watch(bundleSourceItem.Pattern); } else { changeTokenFactory = () => NullChangeToken.Singleton; } return(new Include(bundleSourceItem, excludePatterns, changeTokenFactory, OnChanged)); }
public BundleConfigurer Include(string pattern, Action <List <IBundleItemTransform> > transformsModification = null, Encoding inputEncoding = null) { var item = new FileBundleSourceItem(pattern, _bundleSource.Value) { InputEncoding = inputEncoding }; if (transformsModification != null) { item.ItemTransforms = item.ItemTransforms.Modify(transformsModification); } _bundleSource.Value.Items.Add(item); return(this); }
protected virtual Include CreateInclude(FileBundleSourceItem bundleSourceItem, string[] excludePatterns) { return(new Include(bundleSourceItem, excludePatterns)); }
public void Load(BundleCollection bundles, TextReader reader, ConfigFilePathMapper pathMapper) { if (bundles == null) { throw new ArgumentNullException(nameof(bundles)); } if (reader == null) { throw new ArgumentNullException(nameof(reader)); } if (bundles.SourceFileProvider == null) { throw ErrorHelper.PropertyCannotBeNull(nameof(bundles), nameof(bundles.SourceFileProvider)); } if (pathMapper == null) { pathMapper = DefaultMapPath; } var serializer = JsonSerializer.CreateDefault(); var items = SerializationHelper.Deserialize <BundleData[]>(reader); var n = items.Length; for (var i = 0; i < n; i++) { var item = items[i]; var outputPath = pathMapper(UrlUtils.NormalizePath(item.OutputFileName), bundles.PathPrefix, output: true); var extension = Path.GetExtension(outputPath); var outputConfig = _extensionMappers.Select(em => em.MapOutput(extension)).FirstOrDefault(cfg => cfg != null); if (outputConfig == null) { throw ErrorHelper.ExtensionNotRecognized(extension); } var bundle = new Bundle(outputPath, outputConfig); var bundleSource = new FileBundleSource(bundles.SourceFileProvider, bundle); bundle.Transforms = outputConfig.ConfigurationHelper.SetDefaultTransforms(bundle.Transforms); if (item.Minify.Any(kvp => "enabled".Equals(kvp.Key, StringComparison.OrdinalIgnoreCase) && kvp.Value is bool boolValue && boolValue)) { bundle.Transforms = outputConfig.ConfigurationHelper.EnableMinification(bundle.Transforms); } var m = item.InputFiles.Count; for (var j = 0; j < m; j++) { var inputFile = item.InputFiles[j]; var inputPath = pathMapper(UrlUtils.NormalizePath(inputFile), PathString.Empty, output: false); extension = Path.GetExtension(inputPath); var inputConfig = _extensionMappers.Select(em => em.MapInput(extension)).FirstOrDefault(cfg => cfg != null); if (inputConfig == null) { throw ErrorHelper.ExtensionNotRecognized(extension); } var bundleSourceItem = new FileBundleSourceItem(inputPath, bundleSource); bundleSourceItem.ItemTransforms = inputConfig.ConfigurationHelper.SetDefaultItemTransforms(bundleSourceItem.ItemTransforms); bundleSource.Items.Add(bundleSourceItem); } bundle.Sources.Add(bundleSource); bundles.Add(bundle); } }
public void Load(BundleCollection bundles, TextReader reader, ConfigFilePathMapper pathMapper) { if (bundles == null) { throw new ArgumentNullException(nameof(bundles)); } if (reader == null) { throw new ArgumentNullException(nameof(reader)); } if (bundles.SourceFileProvider == null) { throw ErrorHelper.PropertyCannotBeNull(nameof(bundles), nameof(bundles.SourceFileProvider)); } if (pathMapper == null) { pathMapper = DefaultMapPath; } BundleData[] items = SerializationHelper.Deserialize <BundleData[]>(reader); var n = items.Length; for (var i = 0; i < n; i++) { BundleData item = items[i]; PathString outputPath = pathMapper(UrlUtils.NormalizePath(item.OutputFileName), bundles.PathPrefix, output: true); if (!outputPath.HasValue) { throw ErrorHelper.PathMappingNotPossible(item.OutputFileName, nameof(pathMapper)); } var extension = Path.GetExtension(outputPath); IBundleConfiguration outputConfig = _extensionMappers.Select(em => em.MapOutput(extension)).FirstOrDefault(cfg => cfg != null); if (outputConfig == null) { throw ErrorHelper.ExtensionNotRecognized(extension); } var bundle = new Bundle(outputPath, outputConfig); var bundleSource = new FileBundleSource(bundles.SourceFileProvider, bundles.CaseSensitiveSourceFilePaths, bundle); bundle.Transforms = outputConfig.ConfigurationHelper.SetDefaultTransforms(bundle.Transforms); if (item.Minify == null || !item.Minify.Any(kvp => "enabled".Equals(kvp.Key, StringComparison.OrdinalIgnoreCase) || kvp.Value is bool boolValue && boolValue)) { bundle.Transforms = outputConfig.ConfigurationHelper.EnableMinification(bundle.Transforms); } if (item.InputFiles != null) { for (int j = 0, m = item.InputFiles.Count; j < m; j++) { var inputFile = item.InputFiles[j]; bool exclude; if (inputFile.StartsWith("!")) { inputFile = inputFile.Substring(1); exclude = true; } else { exclude = false; } PathString inputPath = pathMapper(UrlUtils.NormalizePath(inputFile), PathString.Empty, output: false); extension = Path.GetExtension(inputPath); IBundleConfiguration inputConfig = _extensionMappers.Select(em => em.MapInput(extension)).FirstOrDefault(cfg => cfg != null); if (inputConfig == null) { throw ErrorHelper.ExtensionNotRecognized(extension); } var bundleSourceItem = new FileBundleSourceItem(inputPath, bundleSource) { Exclude = exclude }; bundleSourceItem.ItemTransforms = inputConfig.ConfigurationHelper.SetDefaultItemTransforms(bundleSourceItem.ItemTransforms); bundleSource.Items.Add(bundleSourceItem); } } bundle.Sources.Add(bundleSource); bundles.Add(bundle); } }