public static BundleCollectionConfigurer LoadFromConfigFile(this BundleCollectionConfigurer @this, TextReader reader, ConfigFilePathMapper pathMapper = null) { var configFileManager = @this.AppServices.GetRequiredService <IConfigFileManager>(); configFileManager.Load(@this.Bundles, reader, pathMapper); return(@this); }
public static BundleCollectionConfigurer LoadFromConfigFile(this BundleCollectionConfigurer @this, IFileInfo fileInfo, ConfigFilePathMapper pathMapper = null) { if (fileInfo == null) { throw new ArgumentNullException(nameof(fileInfo)); } using (var stream = fileInfo.CreateReadStream()) using (var reader = new StreamReader(stream)) return(@this.LoadFromConfigFile(reader, pathMapper)); }
public static BundleCollectionConfigurer LoadFromConfigFile(this BundleCollectionConfigurer configurer, TextReader reader, ConfigFilePathMapper pathMapper = null) { if (configurer == null) { throw new ArgumentNullException(nameof(configurer)); } IConfigFileManager configFileManager = configurer.AppServices.GetRequiredService <IConfigFileManager>(); configFileManager.Load(configurer.Bundles, reader, pathMapper); return(configurer); }
public static BundleCollectionConfigurer LoadFromConfigFile(this BundleCollectionConfigurer @this, string path, IFileProvider fileProvider, ConfigFilePathMapper pathMapper = null) { if (path == null) { throw new ArgumentNullException(nameof(path)); } if (fileProvider == null) { throw new ArgumentNullException(nameof(fileProvider)); } return(@this.LoadFromConfigFile(fileProvider.GetFileInfo(path), pathMapper)); }
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); } }