コード例 #1
0
 /// <summary>
 /// Loads an intermediate from a path on disk.
 /// </summary>
 /// <param name="path">Path to intermediate file saved on disk.</param>
 /// <param name="creator">ISymbolDefinitionCreator 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, ISymbolDefinitionCreator creator, bool suppressVersionCheck = false)
 {
     using (var wixout = WixOutput.Read(path))
     {
         return(Intermediate.LoadIntermediate(wixout, creator, suppressVersionCheck));
     }
 }
コード例 #2
0
        /// <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">ISymbolDefinitionCreator to use when reconstituting the intermediate.</param>
        /// <returns>The finalized intermediate.</returns>
        private static Intermediate FinalizeLoad(JsonObject json, Uri baseUri, ISymbolDefinitionCreator creator)
        {
            var id    = json.GetValueOrDefault <string>("id");
            var level = json.GetValueOrDefault <string>("level");

            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, level, sections, localizations));
        }
コード例 #3
0
 /// <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">ISymbolDefinitionCreator 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, ISymbolDefinitionCreator creator, bool suppressVersionCheck = false)
 {
     using (var wixout = WixOutput.Read(assembly, resourceName))
     {
         return(Intermediate.LoadIntermediate(wixout, creator, suppressVersionCheck));
     }
 }
コード例 #4
0
        /// <summary>
        /// Loads an intermediate from a WixOutput.
        /// </summary>
        /// <param name="wixout">Source to load from.</param>
        /// <param name="creator">ISymbolDefinitionCreator 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(WixOutput wixout, ISymbolDefinitionCreator creator, bool suppressVersionCheck = false)
        {
            var data = wixout.GetData(WixOutputStreamName);
            var json = Intermediate.LoadJson(data, wixout.Uri, suppressVersionCheck);

            Intermediate.LoadDefinitions(json, creator);

            return(Intermediate.FinalizeLoad(json, wixout.Uri, creator));
        }
コード例 #5
0
        /// <summary>
        /// Loads custom definitions in intermediate json into the creator.
        /// </summary>
        /// <param name="json">Json version of intermediate.</param>
        /// <param name="creator">ISymbolDefinitionCreator to use when reconstituting the intermediate.</param>
        private static void LoadDefinitions(JsonObject json, ISymbolDefinitionCreator creator)
        {
            var definitionsJson = json.GetValueOrDefault <JsonArray>("definitions");

            if (definitionsJson != null)
            {
                foreach (JsonObject definitionJson in definitionsJson)
                {
                    var definition = IntermediateSymbolDefinition.Deserialize(definitionJson);
                    creator.AddCustomSymbolDefinition(definition);
                }
            }
        }
コード例 #6
0
        internal static IntermediateSymbol Deserialize(ISymbolDefinitionCreator 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 tagsJson              = jsonObject.GetValueOrDefault <JsonArray>("tags");

            var id = (idJson == null) ? null : Identifier.Deserialize(idJson);
            var sourceLineNumbers = (sourceLineNumbersJson == null) ? null : SourceLineNumber.Deserialize(sourceLineNumbersJson);

            // TODO: this isn't sufficient.
            if (!creator.TryGetSymbolDefinitionByName(definitionName, out var definition))
            {
                throw new WixException(ErrorMessages.UnknownSymbolType(definitionName));
            }

            var symbol = definition.CreateSymbol(sourceLineNumbers, id);

            for (var i = 0; i < fieldsJson.Count && i < symbol.Fields.Length; ++i)
            {
                if (fieldsJson[i] is JsonObject fieldJson)
                {
                    symbol.Fields[i] = IntermediateField.Deserialize(symbol.Definition.FieldDefinitions[i], baseUri, fieldJson);
                }
            }

            if (tagsJson == null || tagsJson.Count == 0)
            {
            }
            else if (tagsJson.Count == 1)
            {
                symbol.tags = (string)tagsJson[0];
            }
            else
            {
                var tags = new string[tagsJson.Count];

                for (var i = 0; i < tagsJson.Count; ++i)
                {
                    tags[i] = (string)tagsJson[i];
                }

                symbol.tags = tags;
            }

            return(symbol);
        }
コード例 #7
0
        /// <summary>
        /// Parse a section from the JSON data.
        /// </summary>
        internal static IntermediateSection Deserialize(ISymbolDefinitionCreator creator, Uri baseUri, JsonObject jsonObject)
        {
            var id   = jsonObject.GetValueOrDefault <string>("id");
            var type = jsonObject.GetEnumOrDefault("type", SectionType.Unknown);

            if (SectionType.Unknown == type)
            {
                throw new ArgumentException("JSON object is not a valid section, unknown section type", nameof(type));
            }

            var section = new IntermediateSection(id, type);

            var symbolsJson = jsonObject.GetValueOrDefault <JsonArray>("symbols");

            foreach (JsonObject symbolJson in symbolsJson)
            {
                var symbol = IntermediateSymbol.Deserialize(creator, baseUri, symbolJson);
                section.symbols.Add(symbol);
            }

            return(section);
        }
コード例 #8
0
        private void EvaluateSourceFiles(IEnumerable <SourceFile> sourceFiles, ISymbolDefinitionCreator 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());
            }
        }
コード例 #9
0
ファイル: ParseHelper.cs プロジェクト: BMurri/Core
 private void CreateSymbolDefinitionCreator()
 {
     this.Creator = this.ServiceProvider.GetService <ISymbolDefinitionCreator>();
 }
コード例 #10
0
 public override Intermediate GetLibrary(ISymbolDefinitionCreator symbolDefinitions)
 {
     return(Intermediate.Load(typeof(BalExtensionData).Assembly, "WixToolset.Bal.bal.wixlib", symbolDefinitions));
 }
コード例 #11
0
 public Intermediate GetLibrary(ISymbolDefinitionCreator symbolDefinitions)
 {
     return(Intermediate.Load(typeof(ExampleExtensionData).Assembly, "Example.Extension.Example.wixlib", symbolDefinitions));
 }
コード例 #12
0
        /// <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">ISymbolDefinitionCreator 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, ISymbolDefinitionCreator creator, bool suppressVersionCheck = false)
        {
            var jsons         = new Queue <JsonWithPath>();
            var intermediates = new List <Intermediate>();

            foreach (var path in intermediateFiles)
            {
                using (var wixout = WixOutput.Read(path))
                {
                    var data = wixout.GetData(WixOutputStreamName);
                    var json = Intermediate.LoadJson(data, wixout.Uri, suppressVersionCheck);

                    Intermediate.LoadDefinitions(json, creator);

                    jsons.Enqueue(new JsonWithPath {
                        Json = json, Path = wixout.Uri
                    });
                }
            }

            while (jsons.Count > 0)
            {
                var jsonWithPath = jsons.Dequeue();

                var intermediate = Intermediate.FinalizeLoad(jsonWithPath.Json, jsonWithPath.Path, creator);

                intermediates.Add(intermediate);
            }

            return(intermediates);
        }
コード例 #13
0
 /// <summary>
 /// Loads an intermediate from a WixOutput object.
 /// </summary>
 /// <param name="wixOutput">WixOutput object.</param>
 /// <param name="creator">ISymbolDefinitionCreator 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(WixOutput wixOutput, ISymbolDefinitionCreator creator, bool suppressVersionCheck = false)
 {
     return(Intermediate.LoadIntermediate(wixOutput, creator, suppressVersionCheck));
 }
コード例 #14
0
        private IEnumerable <Intermediate> LoadLibraries(IEnumerable <string> libraryFiles, ISymbolDefinitionCreator 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>());
        }
コード例 #15
0
        private Intermediate LinkPhase(IEnumerable <Intermediate> intermediates, IEnumerable <string> libraryFiles, ISymbolDefinitionCreator creator, CancellationToken cancellationToken)
        {
            var libraries = this.LoadLibraries(libraryFiles, creator);

            if (this.Messaging.EncounteredError)
            {
                return(null);
            }

            var context = this.ServiceProvider.GetService <ILinkContext>();

            context.Extensions              = this.ExtensionManager.GetServices <ILinkerExtension>();
            context.ExtensionData           = this.ExtensionManager.GetServices <IExtensionData>();
            context.ExpectedOutputType      = this.OutputType;
            context.Intermediates           = intermediates.Concat(libraries).ToList();
            context.SymbolDefinitionCreator = creator;
            context.CancellationToken       = cancellationToken;

            var linker = this.ServiceProvider.GetService <ILinker>();

            return(linker.Link(context));
        }
コード例 #16
0
 /// <summary>
 /// See <see cref="IExtensionData.GetLibrary"/>
 /// </summary>
 public virtual Intermediate GetLibrary(ISymbolDefinitionCreator symbolDefinitions)
 {
     return(null);
 }