private IEnumerable <Intermediate> LoadLibraries(ITupleDefinitionCreator creator) { var libraries = new List <Intermediate>(); if (this.LibraryFiles != null) { foreach (var libraryFile in this.LibraryFiles) { try { var library = Intermediate.Load(libraryFile, creator); libraries.Add(library); } catch (WixCorruptFileException e) { this.Messaging.Write(e.Error); } catch (WixUnexpectedFileFormatException e) { this.Messaging.Write(e.Error); } } } return(libraries); }
/// <summary> /// Parse a section from the JSON data. /// </summary> internal static IntermediateSection Deserialize(ITupleDefinitionCreator creator, Uri baseUri, JsonObject jsonObject) { var codepage = jsonObject.GetValueOrDefault("codepage", 0); var id = jsonObject.GetValueOrDefault <string>("id"); var type = jsonObject.GetEnumOrDefault("type", SectionType.Unknown); if (null == id && (SectionType.Unknown != type && SectionType.Fragment != type)) { throw new ArgumentException("JSON object is not a valid section"); } if (SectionType.Unknown == type) { throw new ArgumentException("JSON object is not a valid section", nameof(type)); } var section = new IntermediateSection(id, type, codepage); var tuplesJson = jsonObject.GetValueOrDefault <JsonArray>("tuples"); foreach (JsonObject tupleJson in tuplesJson) { var tuple = IntermediateTuple.Deserialize(creator, baseUri, tupleJson); section.Tuples.Add(tuple); } return(section); }
/// <summary> /// Loads the sections and localization for the intermediate. /// </summary> /// <param name="json">Json version of intermediate.</param> /// <param name="baseUri">Path to the intermediate.</param> /// <param name="creator">ITupleDefinitionCreator to use when reconstituting the intermediate.</param> /// <returns>The finalized intermediate.</returns> private static Intermediate FinalizeLoad(JsonObject json, Uri baseUri, ITupleDefinitionCreator creator) { var id = json.GetValueOrDefault <string>("id"); var sections = new List <IntermediateSection>(); var sectionsJson = json.GetValueOrDefault <JsonArray>("sections"); foreach (JsonObject sectionJson in sectionsJson) { var section = IntermediateSection.Deserialize(creator, baseUri, sectionJson); sections.Add(section); } var localizations = new Dictionary <string, Localization>(StringComparer.OrdinalIgnoreCase); var localizationsJson = json.GetValueOrDefault <JsonArray>("localizations") ?? new JsonArray(); foreach (JsonObject localizationJson in localizationsJson) { var localization = Localization.Deserialize(localizationJson); localizations.Add(localization.Culture, localization); } return(new Intermediate(id, sections, localizations, null)); }
/// <summary> /// Loads an intermediate from a path on disk. /// </summary> /// <param name="stream">Stream to intermediate file.</param> /// <param name="baseUri">Path name of intermediate file.</param> /// <param name="creator">ITupleDefinitionCreator to use when reconstituting the intermediate.</param> /// <param name="suppressVersionCheck">Suppress checking for wix.dll version mismatches.</param> /// <returns>Returns the loaded intermediate.</returns> private static Intermediate LoadIntermediate(Stream stream, Uri baseUri, ITupleDefinitionCreator creator, bool suppressVersionCheck = false) { var json = Intermediate.LoadJson(stream, baseUri, suppressVersionCheck); Intermediate.LoadDefinitions(json, creator); return(Intermediate.FinalizeLoad(json, baseUri, creator)); }
/// <summary> /// Loads an intermediate from a path on disk. /// </summary> /// <param name="path">Path to intermediate file saved on disk.</param> /// <param name="creator">ITupleDefinitionCreator to use when reconstituting the intermediate.</param> /// <param name="suppressVersionCheck">Suppress checking for wix.dll version mismatches.</param> /// <returns>Returns the loaded intermediate.</returns> public static Intermediate Load(string path, ITupleDefinitionCreator creator, bool suppressVersionCheck = false) { using (var stream = File.OpenRead(path)) { var uri = new Uri(Path.GetFullPath(path)); return(Intermediate.LoadIntermediate(stream, uri, creator, suppressVersionCheck)); } }
/// <summary> /// Loads an intermediate from a stream. /// </summary> /// <param name="assembly">Assembly with intermediate embedded in resource stream.</param> /// <param name="resourceName">Name of resource stream.</param> /// <param name="creator">ITupleDefinitionCreator to use when reconstituting the intermediate.</param> /// <param name="suppressVersionCheck">Suppress checking for wix.dll version mismatches.</param> /// <returns>Returns the loaded intermediate.</returns> public static Intermediate Load(Assembly assembly, string resourceName, ITupleDefinitionCreator creator, bool suppressVersionCheck = false) { using (var resourceStream = assembly.GetManifestResourceStream(resourceName)) { var uriBuilder = new UriBuilder(assembly.CodeBase); uriBuilder.Scheme = "embeddedresource"; uriBuilder.Fragment = resourceName; return(Intermediate.LoadIntermediate(resourceStream, uriBuilder.Uri, creator, suppressVersionCheck)); } }
/// <summary> /// Loads custom definitions in intermediate json into the creator. /// </summary> /// <param name="json">Json version of intermediate.</param> /// <param name="creator">ITupleDefinitionCreator to use when reconstituting the intermediate.</param> private static void LoadDefinitions(JsonObject json, ITupleDefinitionCreator creator) { var definitionsJson = json.GetValueOrDefault <JsonArray>("definitions"); if (definitionsJson != null) { foreach (JsonObject definitionJson in definitionsJson) { var definition = IntermediateTupleDefinition.Deserialize(definitionJson); creator.AddCustomTupleDefinition(definition); } } }
internal static IntermediateTuple Deserialize(ITupleDefinitionCreator creator, Uri baseUri, JsonObject jsonObject) { var definitionName = jsonObject.GetValueOrDefault <string>("type"); var idJson = jsonObject.GetValueOrDefault <JsonObject>("id"); var sourceLineNumbersJson = jsonObject.GetValueOrDefault <JsonObject>("ln"); var fieldsJson = jsonObject.GetValueOrDefault <JsonArray>("fields"); var id = (idJson == null) ? null : Identifier.Deserialize(idJson); var sourceLineNumbers = (sourceLineNumbersJson == null) ? null : SourceLineNumber.Deserialize(sourceLineNumbersJson); creator.TryGetTupleDefinitionByName(definitionName, out var definition); // TODO: this isn't sufficient. var tuple = definition.CreateTuple(sourceLineNumbers, id); for (var i = 0; i < fieldsJson.Count; ++i) { if (tuple.Fields.Length > i && fieldsJson[i] is JsonObject fieldJson) { tuple.Fields[i] = IntermediateField.Deserialize(tuple.Definition.FieldDefinitions[i], baseUri, fieldJson); } } return(tuple); }
private void EvaluateSourceFiles(IEnumerable <SourceFile> sourceFiles, ITupleDefinitionCreator creator, out List <SourceFile> codeFiles, out Intermediate wixipl) { codeFiles = new List <SourceFile>(); wixipl = null; foreach (var sourceFile in sourceFiles) { var extension = Path.GetExtension(sourceFile.SourcePath); if (wixipl != null || ".wxs".Equals(extension, StringComparison.OrdinalIgnoreCase)) { codeFiles.Add(sourceFile); } else { try { wixipl = Intermediate.Load(sourceFile.SourcePath, creator); } catch (WixException) { // We'll assume anything that isn't a valid intermediate is source code to compile. codeFiles.Add(sourceFile); } } } if (wixipl == null && codeFiles.Count == 0) { this.Messaging.Write(ErrorMessages.NoSourceFiles()); } else if (wixipl != null && codeFiles.Count != 0) { this.Messaging.Write(ErrorMessages.WixiplSourceFileIsExclusive()); } }
public override Intermediate GetLibrary(ITupleDefinitionCreator tupleDefinitions) { return(Intermediate.Load(typeof(SqlExtensionData).Assembly, "WixToolset.Sql.sql.wixlib", tupleDefinitions)); }
public override Intermediate GetLibrary(ITupleDefinitionCreator tupleDefinitions) { return(Intermediate.Load(typeof(VSExtensionData).Assembly, "WixToolset.VisualStudio.vs.wixlib", tupleDefinitions)); }
private void CreateTupleDefinitionCreator() { this.Creator = (ITupleDefinitionCreator)this.ServiceProvider.GetService(typeof(ITupleDefinitionCreator)); }
public virtual Intermediate GetLibrary(ITupleDefinitionCreator tupleDefinitions) { return(null); }
private IEnumerable <Intermediate> LoadLibraries(IEnumerable <string> libraryFiles, ITupleDefinitionCreator creator) { try { return(Intermediate.Load(libraryFiles, creator)); } catch (WixCorruptFileException e) { this.Messaging.Write(e.Error); } catch (WixUnexpectedFileFormatException e) { this.Messaging.Write(e.Error); } return(Array.Empty <Intermediate>()); }
public Intermediate GetLibrary(ITupleDefinitionCreator tupleDefinitions) { return(Intermediate.Load(typeof(ExampleExtensionData).Assembly, "Example.Extension.Data.Example.wir", tupleDefinitions)); }
private Intermediate LinkPhase(IEnumerable <Intermediate> intermediates, IEnumerable <string> libraryFiles, ITupleDefinitionCreator creator) { var libraries = this.LoadLibraries(libraryFiles, creator); if (this.Messaging.EncounteredError) { return(null); } var context = this.ServiceProvider.GetService <ILinkContext>(); context.Extensions = this.ExtensionManager.Create <ILinkerExtension>(); context.ExtensionData = this.ExtensionManager.Create <IExtensionData>(); context.ExpectedOutputType = this.OutputType; context.Intermediates = intermediates.Concat(libraries).ToList(); context.TupleDefinitionCreator = creator; var linker = this.ServiceProvider.GetService <ILinker>(); return(linker.Link(context)); }
/// <summary> /// Loads several intermediates from paths on disk using the same definitions. /// </summary> /// <param name="intermediateFiles">Paths to intermediate files saved on disk.</param> /// <param name="creator">ITupleDefinitionCreator to use when reconstituting the intermediates.</param> /// <param name="suppressVersionCheck">Suppress checking for wix.dll version mismatches.</param> /// <returns>Returns the loaded intermediates</returns> public static IEnumerable <Intermediate> Load(IEnumerable <string> intermediateFiles, ITupleDefinitionCreator creator, bool suppressVersionCheck = false) { var jsons = new Queue <JsonWithPath>(); var intermediates = new List <Intermediate>(); foreach (var path in intermediateFiles) { using (var stream = File.OpenRead(path)) { var uri = new Uri(Path.GetFullPath(path)); var json = Intermediate.LoadJson(stream, uri, suppressVersionCheck); Intermediate.LoadDefinitions(json, creator); jsons.Enqueue(new JsonWithPath { Json = json, Path = uri }); } } while (jsons.Count > 0) { var jsonWithPath = jsons.Dequeue(); var intermediate = Intermediate.FinalizeLoad(jsonWithPath.Json, jsonWithPath.Path, creator); intermediates.Add(intermediate); } return(intermediates); }