/// <summary> /// Gets the library associated with this extension. /// </summary> /// <param name="tableDefinitions">The table definitions to use while loading the library.</param> /// <returns>The loaded library.</returns> public override Library GetLibrary(TableDefinitionCollection tableDefinitions) { if (null == _library) _library = LoadLibraryHelper(Assembly.GetExecutingAssembly(), "VisioWixExtension.Data.Visio.wixlib", tableDefinitions); return _library; }
public override Library GetLibrary(TableDefinitionCollection tableDefinitions) { if (library == null) library = LoadLibraryHelper(Assembly.GetExecutingAssembly(), "WixSTExtension.WixSTLibrary.wixlib", tableDefinitions); return library; }
/// <summary> /// Gets the library associated with this extension. /// </summary> /// <param name="tableDefinitions">The table definitions to use while loading the library.</param> /// <returns>The library for this extension.</returns> public override Library GetLibrary(TableDefinitionCollection tableDefinitions) { if (null == this.library) { this.library = LoadLibraryHelper(Assembly.GetExecutingAssembly(), "AppSecInc.Wix.Extensions.Data.DataSource.wixlib", tableDefinitions); } return this.library; }
/// <summary> /// Loads a library from a path on disk. /// </summary> /// <param name="path">Path to library file saved on disk.</param> /// <param name="tableDefinitions">Collection containing TableDefinitions to use when reconstituting the intermediates.</param> /// <param name="suppressVersionCheck">Suppresses wix.dll version mismatch check.</param> /// <returns>Returns the loaded library.</returns> /// <remarks>This method will set the Path and SourcePath properties to the appropriate values on successful load.</remarks> public static Library Load(string path, TableDefinitionCollection tableDefinitions, bool suppressVersionCheck) { Library library = new Library(); library.path = path; XmlTextReader reader = null; try { reader = new XmlTextReader(path); ParseLibrary(library, reader, tableDefinitions, suppressVersionCheck); } finally { if (null != reader) { reader.Close(); } } return library; }
/// <summary> /// Parse the root library element. /// </summary> /// <param name="reader">XmlReader with library persisted as Xml.</param> /// <param name="tableDefinitions">Collection containing TableDefinitions to use when reconstituting the intermediates.</param> /// <param name="suppressVersionCheck">Suppresses check for wix.dll version mismatch.</param> /// <returns>The parsed Library.</returns> private static Library Parse(XmlReader reader, TableDefinitionCollection tableDefinitions, bool suppressVersionCheck) { Debug.Assert("wixLibrary" == reader.LocalName); bool empty = reader.IsEmptyElement; Library library = new Library(); Version version = null; while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "version": version = new Version(reader.Value); break; default: if (!reader.NamespaceURI.StartsWith("http://www.w3.org/", StringComparison.Ordinal)) { throw new WixException(WixErrors.UnexpectedAttribute(SourceLineNumberCollection.FromUri(reader.BaseURI), "wixLibrary", reader.Name)); } break; } } if (null != version && !suppressVersionCheck) { if (0 != currentVersion.CompareTo(version)) { throw new WixException(WixErrors.VersionMismatch(SourceLineNumberCollection.FromUri(reader.BaseURI), "library", version.ToString(), currentVersion.ToString())); } } if (!empty) { bool done = false; while (!done && (XmlNodeType.Element == reader.NodeType || reader.Read())) { switch (reader.NodeType) { case XmlNodeType.Element: switch (reader.LocalName) { case "section": library.sections.Add(Section.Parse(reader, tableDefinitions)); break; case "WixLocalization": Localization localization = Localization.Parse(reader, tableDefinitions); library.localizations.Add(localization.Culture, localization); break; default: throw new WixException(WixErrors.UnexpectedElement(SourceLineNumberCollection.FromUri(reader.BaseURI), "wixLibrary", reader.Name)); } break; case XmlNodeType.EndElement: done = true; break; } } if (!done) { throw new WixException(WixErrors.ExpectedEndElement(SourceLineNumberCollection.FromUri(reader.BaseURI), "wixLibrary")); } } return library; }
/// <summary> /// Validate that a library contains one entry section and no duplicate symbols. /// </summary> /// <param name="messageHandler">Message handler for errors.</param> /// <param name="library">Library to validate.</param> private void Validate(IMessageHandler messageHandler, Library library) { Section entrySection; SymbolCollection allSymbols; ArrayList intermediates = new ArrayList(); SectionCollection sections = new SectionCollection(); StringCollection referencedSymbols = new StringCollection(); ArrayList unresolvedReferences = new ArrayList(); intermediates.AddRange(library.Intermediates); Common.FindEntrySectionAndLoadSymbols((Intermediate[])intermediates.ToArray(typeof(Intermediate)), false, this, out entrySection, out allSymbols); foreach (Intermediate intermediate in library.Intermediates) { foreach (Section section in intermediate.Sections) { Common.ResolveReferences(OutputType.Unknown, sections, section, allSymbols, referencedSymbols, unresolvedReferences, this); } } }
/// <summary> /// Create a library by combining several intermediates (objects). /// </summary> /// <param name="intermediates">Intermediates to combine.</param> /// <returns>Returns the new library.</returns> public Library Combine(Intermediate[] intermediates) { Library library = new Library(); foreach (Intermediate intermediate in intermediates) { library.Intermediates.Add(intermediate); } // check for multiple entry sections and duplicate symbols this.Validate(this, library); return (this.foundError ? null : library); }
/// <summary> /// Validate that a library contains one entry section and no duplicate symbols. /// </summary> /// <param name="library">Library to validate.</param> private void Validate(Library library) { Section entrySection; SymbolCollection allSymbols; library.Sections.FindEntrySectionAndLoadSymbols(false, this, OutputType.Unknown, out entrySection, out allSymbols); foreach (Section section in library.Sections) { section.ResolveReferences(OutputType.Unknown, allSymbols, null, null, this); } }
/// <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 Library Combine(SectionCollection sections) { Library library = new Library(); library.Sections.AddRange(sections); // check for multiple entry sections and duplicate symbols this.Validate(library); return (this.encounteredError ? null : library); }
/// <summary> /// Parse the root library element. /// </summary> /// <param name="library">Library to read from disk.</param> /// <param name="reader">XmlReader with library persisted as Xml.</param> /// <param name="tableDefinitions">Collection containing TableDefinitions to use when reconstituting the intermediates.</param> /// <param name="suppressVersionCheck">Suppresses check for wix.dll version mismatch.</param> private static void ParseLibrary(Library library, XmlReader reader, TableDefinitionCollection tableDefinitions, bool suppressVersionCheck) { // read the document root reader.MoveToContent(); if ("wixLibrary" != reader.LocalName) { throw new WixNotLibraryException(SourceLineNumberCollection.FromFileName(library.Path), String.Format("Invalid root element: '{0}', expected 'wixLibrary'", reader.LocalName)); } Version objVersion = null; while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "version": objVersion = new Version(reader.Value); break; } } if (null != objVersion && !suppressVersionCheck) { Version currentVersion = Common.LibraryFormatVersion; if (0 != currentVersion.CompareTo(objVersion)) { throw new WixVersionMismatchException(currentVersion, objVersion, "Library", library.Path); } } // loop through the rest of the xml building up the SectionCollection while (reader.Read()) { if (0 == reader.Depth) { break; } else if (1 != reader.Depth) { // throw exception since we should only be processing tables throw new WixInvalidIntermediateException(SourceLineNumberCollection.FromFileName(library.Path), "Unexpected depth while processing element: 'wixLibrary'"); } if (XmlNodeType.Element == reader.NodeType && "wixObject" == reader.LocalName) { Intermediate intermediate = Intermediate.Load(reader, library.Path, tableDefinitions, suppressVersionCheck); library.intermediates.Add(intermediate); } } }
/// <summary> /// Loads a library from a XmlReader in memory. /// </summary> /// <param name="reader">XmlReader with library persisted as Xml.</param> /// <param name="tableDefinitions">Collection containing TableDefinitions to use when reconstituting the intermediates.</param> /// <param name="suppressVersionCheck">Suppresses wix.dll version mismatch check.</param> /// <returns>Returns the loaded library.</returns> /// <remarks>This method will set the SourcePath property to the appropriate values on successful load, but will not update the Path property.</remarks> public static Library Load(XmlReader reader, TableDefinitionCollection tableDefinitions, bool suppressVersionCheck) { Library library = new Library(); ParseLibrary(library, reader, tableDefinitions, suppressVersionCheck); return library; }