private Bundle CreateBundle() { var bundle = new Bundle() { Includes = new List<Include>() { CreateLessInclude(), CreateCssInclude(), } }; return bundle; }
/// <summary> /// Serializes the <c>bundle</c> into a <c>file</c>. /// </summary> /// <param name="bundle">The bundle to serialize.</param> /// <param name="file">The file to store the serialized <c>bundle</c>.</param> internal static void Serialize(Bundle bundle, string file) { using (var writer = System.IO.File.Create(file)) { Serializer.Serialize(writer, bundle); } }
private BundleState CreateBundleState(Bundle bundle) { var includes = GetIncludeStates(bundle).ToList(); return new BundleState() { Bundle = bundle, BundleFile = new FileInfo(bundle.File), BundleOutputFile = new FileInfo(bundle.GetOutputFile()), Includes = includes, }; }
/// <summary> /// Gets the underlying files included in this bundle. /// </summary> /// <returns>The files from the bundle and any inner bundles.</returns> private List<IncludeState> GetIncludeStates(Bundle bundle) { var includeStatesByFile = new Dictionary<string, IncludeState>(StringComparer.InvariantCultureIgnoreCase); var includes = bundle.Includes; if (includes != null) { string bundleFileDirectory = Path.GetDirectoryName(Path.GetFullPath(bundle.File)); foreach (var include in includes) { if (include is BundleInclude) { // IF this include is another bundle // THEN we need to get all it's files var bundleInclude = (BundleInclude)include; var includeBundleFile = EnsureFileRooted(bundleFileDirectory, bundleInclude.File); var includeBundleState = GetOrCreateBundleState(includeBundleFile); foreach (var includeBundleInclude in includeBundleState.Includes) { if (!includeStatesByFile.ContainsKey(includeBundleInclude.File.FullName)) { includeStatesByFile.Add(includeBundleInclude.File.FullName, includeBundleInclude); } } } else { // ELSE just add this include var includeFile = EnsureFileRooted(bundleFileDirectory, include.File); if (!includeStatesByFile.ContainsKey(includeFile)) { includeStatesByFile.Add(includeFile, CreateIncludeState(bundleFileDirectory, include)); } } } } return includeStatesByFile.Values.ToList(); }
private void Bundle(Bundle bundle) { if (bundle == null) { throw new System.ArgumentNullException("bundle"); } try { // put the bundle into the state var bundleState = CreateBundleState(bundle); if (!bundleState.Bundled) { // transform all includes foreach (var include in bundleState.Includes) { Transform(include); } // transform the bundle Transform(bundleState); // mark the bundle as bundled bundleState.Bundled = true; } } catch (Exception ex) { throw new ApplicationException(string.Format("An error occurred while bundling a bundle file. Bundle File: {0}", bundle.File), ex); } }