// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
namespace WixToolset
{
using System;
using System.Collections.Generic;
using WixToolset.Data;
using WixToolset.Extensibility;
using WixToolset.Link;
///
/// Core librarian tool.
///
public sealed class Librarian
{
///
/// Instantiate a new Librarian class.
///
public Librarian()
{
this.TableDefinitions = new TableDefinitionCollection(WindowsInstallerStandard.GetTableDefinitions());
}
///
/// Gets table definitions used by this librarian.
///
/// Table definitions.
public TableDefinitionCollection TableDefinitions { get; private set; }
///
/// Adds an extension's data.
///
/// The extension data to add.
public void AddExtensionData(IExtensionData extension)
{
if (null != extension.TableDefinitions)
{
foreach (TableDefinition tableDefinition in extension.TableDefinitions)
{
try
{
this.TableDefinitions.Add(tableDefinition);
}
catch (ArgumentException)
{
Messaging.Instance.OnMessage(WixErrors.DuplicateExtensionTable(extension.GetType().ToString(), tableDefinition.Name));
}
}
}
}
///
/// Create a library by combining several intermediates (objects).
///
/// The sections to combine into a library.
/// Returns the new library.
public Library Combine(IEnumerable sections)
{
Library library = new Library(sections);
this.Validate(library);
return (Messaging.Instance.EncounteredError ? null : library);
}
///
/// Sends a message to the message delegate if there is one.
///
/// Message event arguments.
public void OnMessage(MessageEventArgs e)
{
Messaging.Instance.OnMessage(e);
}
///
/// Validate that a library contains one entry section and no duplicate symbols.
///
/// Library to validate.
private void Validate(Library library)
{
FindEntrySectionAndLoadSymbolsCommand find = new FindEntrySectionAndLoadSymbolsCommand(library.Sections);
find.Execute();
// TODO: Consider bringing this sort of verification back.
// foreach (Section section in library.Sections)
// {
// ResolveReferencesCommand resolve = new ResolveReferencesCommand(find.EntrySection, find.Symbols);
// resolve.Execute();
//
// ReportDuplicateResolvedSymbolErrorsCommand reportDupes = new ReportDuplicateResolvedSymbolErrorsCommand(find.SymbolsWithDuplicates, resolve.ResolvedSections);
// reportDupes.Execute();
// }
}
}
}