From 0d3d54992104288e9ee0c834d0b96e8502fd2d42 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Thu, 11 Jan 2024 18:26:20 -0800 Subject: Move the BootstrapperApplication out of proc --- .../WixToolset.Mba.Core/BootstrapperApplication.cs | 149 ++++++++++----------- 1 file changed, 74 insertions(+), 75 deletions(-) (limited to 'src/api/burn/WixToolset.Mba.Core/BootstrapperApplication.cs') diff --git a/src/api/burn/WixToolset.Mba.Core/BootstrapperApplication.cs b/src/api/burn/WixToolset.Mba.Core/BootstrapperApplication.cs index a0ec6ab9..98b34217 100644 --- a/src/api/burn/WixToolset.Mba.Core/BootstrapperApplication.cs +++ b/src/api/burn/WixToolset.Mba.Core/BootstrapperApplication.cs @@ -12,24 +12,16 @@ namespace WixToolset.Mba.Core [ClassInterface(ClassInterfaceType.None)] public abstract class BootstrapperApplication : MarshalByRefObject, IDefaultBootstrapperApplication { - /// - /// Specifies whether this bootstrapper should run asynchronously. The default is true. - /// - protected readonly bool asyncExecution; - /// /// Gets the for interaction with the engine. /// - protected readonly IEngine engine; + protected IEngine engine; - /// - /// Creates a new instance of the class. - /// - protected BootstrapperApplication(IEngine engine) - { - this.engine = engine; - this.asyncExecution = true; - } + /// + public event EventHandler Create; + + /// + public event EventHandler Destroy; /// public event EventHandler Startup; @@ -265,12 +257,6 @@ namespace WixToolset.Mba.Core /// public event EventHandler CachePayloadExtractComplete; - /// - public event EventHandler SetUpdateBegin; - - /// - public event EventHandler SetUpdateComplete; - /// public event EventHandler PlanRestoreRelatedBundle; @@ -283,36 +269,74 @@ namespace WixToolset.Mba.Core /// public event EventHandler CachePackageNonVitalValidationFailure; + /// + /// The default constructor. + /// + /// + /// The engine object will be valid after handling the OnCreate() event. + /// + protected BootstrapperApplication() + { + } + + /// + /// This constructor is no longer used. + /// + [Obsolete("This constructor is no longer used. Use the default constructor. The engine object will be valid after handling the OnCreate() event.")] + protected BootstrapperApplication(IEngine engine) + { + throw new NotImplementedException("This constructor is no longer used. Use the default constructor. The engine object will be valid after handling the OnCreate() event."); + } + /// /// Entry point that is called when the bootstrapper application is ready to run. /// protected abstract void Run(); /// - /// Called by the engine, raises the event. + /// Called by the engine, raises the event. /// /// Additional arguments for this event. - protected virtual void OnStartup(StartupEventArgs args) + protected virtual void OnCreate(CreateEventArgs args) { - EventHandler handler = this.Startup; + this.engine = args.Engine; + + EventHandler handler = this.Create; if (null != handler) { handler(this, args); } + } - if (this.asyncExecution) + /// + /// Called by the engine, raises the event. + /// + /// Additional arguments for this event. + protected virtual void OnDestroy(DestroyEventArgs args) + { + EventHandler handler = this.Destroy; + if (null != handler) { - this.engine.Log(LogLevel.Verbose, "Creating BA thread to run asynchronously."); - Thread uiThread = new Thread(this.Run); - uiThread.Name = "UIThread"; - uiThread.SetApartmentState(ApartmentState.STA); - uiThread.Start(); + handler(this, args); } - else + } + + /// + /// Called by the engine, raises the event. + /// + /// Additional arguments for this event. + protected virtual void OnStartup(StartupEventArgs args) + { + EventHandler handler = this.Startup; + if (null != handler) { - this.engine.Log(LogLevel.Verbose, "Creating BA thread to run synchronously."); - this.Run(); + handler(this, args); } + + Thread uiThread = new Thread(this.Run); + uiThread.Name = "UIThread"; + uiThread.SetApartmentState(ApartmentState.STA); + uiThread.Start(); } /// @@ -1315,31 +1339,6 @@ namespace WixToolset.Mba.Core } } - /// - /// Called by the engine, raises the event. - /// - /// Additional arguments for this event. - protected virtual void OnSetUpdateBegin(SetUpdateBeginEventArgs args) - { - EventHandler handler = this.SetUpdateBegin; - if (null != handler) - { - handler(this, args); - } - } - - /// - /// Called by the engine, raises the event. - /// - /// Additional arguments for this event. - protected virtual void OnSetUpdateComplete(SetUpdateCompleteEventArgs args) - { - EventHandler handler = this.SetUpdateComplete; - if (null != handler) - { - handler(this, args); - } - } /// /// Called by the engine, raises the event. @@ -1395,7 +1394,7 @@ namespace WixToolset.Mba.Core #region IBootstrapperApplication Members - int IBootstrapperApplication.BAProc(int message, IntPtr pvArgs, IntPtr pvResults, IntPtr pvContext) + int IBootstrapperApplication.BAProc(int message, IntPtr pvArgs, IntPtr pvResults) { switch (message) { @@ -1404,8 +1403,24 @@ namespace WixToolset.Mba.Core } } - void IBootstrapperApplication.BAProcFallback(int message, IntPtr pvArgs, IntPtr pvResults, ref int phr, IntPtr pvContext) + void IBootstrapperApplication.BAProcFallback(int message, IntPtr pvArgs, IntPtr pvResults, ref int phr) + { + } + + int IBootstrapperApplication.OnCreate(IBootstrapperEngine engine, ref Command command) { + CreateEventArgs args = new CreateEventArgs(new Engine(engine), command.GetBootstrapperCommand()); + this.OnCreate(args); + + return args.HResult; + } + + int IBootstrapperApplication.OnDestroy(bool reload) + { + DestroyEventArgs args = new DestroyEventArgs(reload); + this.OnDestroy(args); + + return args.HResult; } int IBootstrapperApplication.OnStartup() @@ -2107,22 +2122,6 @@ namespace WixToolset.Mba.Core return args.HResult; } - int IBootstrapperApplication.OnSetUpdateBegin() - { - SetUpdateBeginEventArgs args = new SetUpdateBeginEventArgs(); - this.OnSetUpdateBegin(args); - - return args.HResult; - } - - int IBootstrapperApplication.OnSetUpdateComplete(int hrStatus, string wzPreviousPackageId, string wzNewPackageId) - { - SetUpdateCompleteEventArgs args = new SetUpdateCompleteEventArgs(hrStatus, wzPreviousPackageId, wzNewPackageId); - this.OnSetUpdateComplete(args); - - return args.HResult; - } - int IBootstrapperApplication.OnPlanRestoreRelatedBundle(string wzBundleId, RequestState recommendedState, ref RequestState pRequestedState, ref bool fCancel) { PlanRestoreRelatedBundleEventArgs args = new PlanRestoreRelatedBundleEventArgs(wzBundleId, recommendedState, pRequestedState, fCancel); -- cgit v1.2.3-55-g6feb