/// <summary> /// Create a library by combining several intermediates (objects). /// </summary> /// <param name="sections">The sections to combine into a library.</param> /// <returns>Returns the new library.</returns> public Intermediate Execute() { this.Context = new LibraryContext(this.ServiceProvider); this.Context.Messaging = this.ServiceProvider.GetService <IMessaging>(); this.Context.BindFiles = this.BindFiles; this.Context.BindPaths = this.BindPaths; this.Context.Extensions = this.ServiceProvider.GetService <IExtensionManager>().Create <ILibrarianExtension>(); this.Context.Localizations = this.Localizations; this.Context.LibraryId = Convert.ToBase64String(Guid.NewGuid().ToByteArray()).TrimEnd('=').Replace('+', '.').Replace('/', '_'); this.Context.Intermediates = this.Intermediates; foreach (var extension in this.Context.Extensions) { extension.PreCombine(this.Context); } Intermediate library = null; try { var sections = this.Context.Intermediates.SelectMany(i => i.Sections).ToList(); var collate = new CollateLocalizationsCommand(this.Context.Messaging, this.Context.Localizations); var localizationsByCulture = collate.Execute(); if (this.Context.Messaging.EncounteredError) { return(null); } var embedFilePaths = this.ResolveFilePathsToEmbed(sections); foreach (var section in sections) { section.LibraryId = this.Context.LibraryId; } library = new Intermediate(this.Context.LibraryId, sections, localizationsByCulture, embedFilePaths); this.Validate(library); } finally { foreach (var extension in this.Context.Extensions) { extension.PostCombine(library); } } return(this.Context.Messaging.EncounteredError ? null : library); }
/// <summary> /// Create a library by combining several intermediates (objects). /// </summary> /// <returns>Returns the new library.</returns> public Intermediate Combine(ILibraryContext context) { if (String.IsNullOrEmpty(context.LibraryId)) { context.LibraryId = Convert.ToBase64String(Guid.NewGuid().ToByteArray()).TrimEnd('=').Replace('+', '.').Replace('/', '_'); } foreach (var extension in context.Extensions) { extension.PreCombine(context); } Intermediate library = null; try { var sections = context.Intermediates.SelectMany(i => i.Sections).ToList(); var collate = new CollateLocalizationsCommand(this.Messaging, context.Localizations); var localizationsByCulture = collate.Execute(); if (this.Messaging.EncounteredError) { return(null); } this.ResolveFilePathsToEmbed(context, sections); foreach (var section in sections) { section.AssignToLibrary(context.LibraryId); } library = new Intermediate(context.LibraryId, IntermediateLevels.Compiled, sections, localizationsByCulture); library.UpdateLevel(IntermediateLevels.Combined); this.Validate(library); } finally { foreach (var extension in context.Extensions) { extension.PostCombine(library); } } return(this.Messaging.EncounteredError ? null : library); }