From 1d6ff8af3c423ee4622185edc986ae5caad6b122 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Tue, 26 Dec 2017 15:11:40 -0800 Subject: Standardize creation of public objects in move towards interfaces --- src/WixToolset.Core/Compiler.cs | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'src/WixToolset.Core/Compiler.cs') diff --git a/src/WixToolset.Core/Compiler.cs b/src/WixToolset.Core/Compiler.cs index 2dd7da4d..587c24fe 100644 --- a/src/WixToolset.Core/Compiler.cs +++ b/src/WixToolset.Core/Compiler.cs @@ -68,10 +68,25 @@ namespace WixToolset.Core Icon, } + public Compiler(IServiceProvider serviceProvider) + { + this.ServiceProvider = serviceProvider; + } + + private IServiceProvider ServiceProvider { get; } + private ICompileContext Context { get; set; } private CompilerCore Core { get; set; } + public string CompliationId { get; set; } + + public string OutputPath { get; set; } + + public Platform Platform { get; set; } + + public XDocument SourceDocument { get; set; } + /// /// Gets or sets the platform which the compiler will use when defaulting 64-bit attributes and elements. /// @@ -87,17 +102,21 @@ namespace WixToolset.Core /// /// Compiles the provided Xml document into an intermediate object /// - /// Context for the compile. The BaseURI property - /// should be properly set to get messages containing source line information. /// Intermediate object representing compiled source document. /// This method is not thread-safe. - public Intermediate Compile(ICompileContext context) + public Intermediate Execute() { - this.Context = context ?? throw new ArgumentNullException(nameof(context)); + this.Context = this.ServiceProvider.GetService(); + this.Context.Messaging = this.ServiceProvider.GetService(); + this.Context.Extensions = this.ServiceProvider.GetService().Create(); + this.Context.CompilationId = this.CompliationId; + this.Context.OutputPath = this.OutputPath; + this.Context.Platform = this.Platform; + this.Context.Source = this.SourceDocument; var target = new Intermediate(); - if (String.IsNullOrEmpty(context.CompilationId)) + if (String.IsNullOrEmpty(this.Context.CompilationId)) { this.Context.CompilationId = target.Id; } @@ -115,20 +134,20 @@ namespace WixToolset.Core this.Context.Messaging.Write(ErrorMessages.DuplicateExtensionXmlSchemaNamespace(extension.GetType().ToString(), extension.Namespace.NamespaceName, collidingExtension.GetType().ToString())); } - extension.PreCompile(context); + extension.PreCompile(this.Context); } // Try to compile it. try { - var parseHelper = context.ServiceProvider.GetService(); + var parseHelper = this.Context.ServiceProvider.GetService(); this.Core = new CompilerCore(target, this.Context.Messaging, parseHelper, extensionsByNamespace); this.Core.ShowPedanticMessages = this.ShowPedanticMessages; this.componentIdPlaceholdersResolver = new WixVariableResolver(this.Context.Messaging); // parse the document - var source = context.Source; + var source = this.Context.Source; var sourceLineNumbers = Preprocessor.GetSourceLineNumbers(source.Root); if ("Wix" == source.Root.Name.LocalName) { @@ -158,7 +177,7 @@ namespace WixToolset.Core } finally { - foreach (var extension in context.Extensions) + foreach (var extension in this.Context.Extensions) { extension.PostCompile(target); } -- cgit v1.2.3-55-g6feb