From 39e930d9aaff250e0fd5019eeedaa40717a6c6fe Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Wed, 29 Apr 2020 19:28:50 +1000 Subject: Add DotNetCoreBootstrapperApplicationHost for an SCD-style .NET Core BA. --- .../examples/EarliestCoreMBA/EarliestCoreBA.cs | 34 ++++++++++++++++++++++ .../EarliestCoreMBA/EarliestCoreBAFactory.cs | 22 ++++++++++++++ .../EarliestCoreMBA/Example.EarliestCoreMBA.csproj | 18 ++++++++++++ .../LatestCoreMBA/Example.LatestCoreMBA.csproj | 23 +++++++++++++++ src/test/examples/LatestCoreMBA/LatestCoreBA.cs | 33 +++++++++++++++++++++ .../examples/LatestCoreMBA/LatestCoreBAFactory.cs | 22 ++++++++++++++ src/test/examples/TestEngine/TestEngine.cpp | 16 +++++++++- src/test/examples/TestEngine/precomp.h | 1 + 8 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 src/test/examples/EarliestCoreMBA/EarliestCoreBA.cs create mode 100644 src/test/examples/EarliestCoreMBA/EarliestCoreBAFactory.cs create mode 100644 src/test/examples/EarliestCoreMBA/Example.EarliestCoreMBA.csproj create mode 100644 src/test/examples/LatestCoreMBA/Example.LatestCoreMBA.csproj create mode 100644 src/test/examples/LatestCoreMBA/LatestCoreBA.cs create mode 100644 src/test/examples/LatestCoreMBA/LatestCoreBAFactory.cs (limited to 'src/test/examples') diff --git a/src/test/examples/EarliestCoreMBA/EarliestCoreBA.cs b/src/test/examples/EarliestCoreMBA/EarliestCoreBA.cs new file mode 100644 index 00000000..c9291a7f --- /dev/null +++ b/src/test/examples/EarliestCoreMBA/EarliestCoreBA.cs @@ -0,0 +1,34 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +namespace Example.EarliestCoreMBA +{ + using WixToolset.Mba.Core; + + public class EarliestCoreBA : BootstrapperApplication + { + public EarliestCoreBA(IEngine engine) + : base(engine) + { + + } + + protected override void Run() + { + } + + protected override void OnStartup(StartupEventArgs args) + { + base.OnStartup(args); + + this.engine.Log(LogLevel.Standard, nameof(EarliestCoreBA)); + } + + protected override void OnShutdown(ShutdownEventArgs args) + { + base.OnShutdown(args); + + var message = "Shutdown," + args.Action.ToString() + "," + args.HResult.ToString(); + this.engine.Log(LogLevel.Standard, message); + } + } +} diff --git a/src/test/examples/EarliestCoreMBA/EarliestCoreBAFactory.cs b/src/test/examples/EarliestCoreMBA/EarliestCoreBAFactory.cs new file mode 100644 index 00000000..672e17ee --- /dev/null +++ b/src/test/examples/EarliestCoreMBA/EarliestCoreBAFactory.cs @@ -0,0 +1,22 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +[assembly: WixToolset.Mba.Core.BootstrapperApplicationFactory(typeof(Example.EarliestCoreMBA.EarliestCoreBAFactory))] +namespace Example.EarliestCoreMBA +{ + using WixToolset.Mba.Core; + + public class EarliestCoreBAFactory : BaseBootstrapperApplicationFactory + { + private static int loadCount = 0; + + protected override IBootstrapperApplication Create(IEngine engine, IBootstrapperCommand bootstrapperCommand) + { + if (loadCount > 0) + { + engine.Log(LogLevel.Standard, $"Reloaded {loadCount} time(s)"); + } + ++loadCount; + return new EarliestCoreBA(engine); + } + } +} diff --git a/src/test/examples/EarliestCoreMBA/Example.EarliestCoreMBA.csproj b/src/test/examples/EarliestCoreMBA/Example.EarliestCoreMBA.csproj new file mode 100644 index 00000000..326633ba --- /dev/null +++ b/src/test/examples/EarliestCoreMBA/Example.EarliestCoreMBA.csproj @@ -0,0 +1,18 @@ + + + + netcoreapp3.0 + win-x86;win-x64 + true + Earliest .NET Core MBA + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/examples/LatestCoreMBA/Example.LatestCoreMBA.csproj b/src/test/examples/LatestCoreMBA/Example.LatestCoreMBA.csproj new file mode 100644 index 00000000..1d325b1b --- /dev/null +++ b/src/test/examples/LatestCoreMBA/Example.LatestCoreMBA.csproj @@ -0,0 +1,23 @@ + + + + netcoreapp3.1 + win-x86;win-x64 + true + Latest .NET Core MBA + + + + false + true + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/examples/LatestCoreMBA/LatestCoreBA.cs b/src/test/examples/LatestCoreMBA/LatestCoreBA.cs new file mode 100644 index 00000000..50386a87 --- /dev/null +++ b/src/test/examples/LatestCoreMBA/LatestCoreBA.cs @@ -0,0 +1,33 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +namespace Example.LatestCoreMBA +{ + using WixToolset.Mba.Core; + + public class LatestCoreBA : BootstrapperApplication + { + public LatestCoreBA(IEngine engine) + : base(engine) + { + } + + protected override void Run() + { + } + + protected override void OnStartup(StartupEventArgs args) + { + base.OnStartup(args); + + this.engine.Log(LogLevel.Standard, nameof(LatestCoreBA)); + } + + protected override void OnShutdown(ShutdownEventArgs args) + { + base.OnShutdown(args); + + var message = "Shutdown," + args.Action.ToString() + "," + args.HResult.ToString(); + this.engine.Log(LogLevel.Standard, message); + } + } +} diff --git a/src/test/examples/LatestCoreMBA/LatestCoreBAFactory.cs b/src/test/examples/LatestCoreMBA/LatestCoreBAFactory.cs new file mode 100644 index 00000000..fff3b5c5 --- /dev/null +++ b/src/test/examples/LatestCoreMBA/LatestCoreBAFactory.cs @@ -0,0 +1,22 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +[assembly: WixToolset.Mba.Core.BootstrapperApplicationFactory(typeof(Example.LatestCoreMBA.LatestCoreBAFactory))] +namespace Example.LatestCoreMBA +{ + using WixToolset.Mba.Core; + + public class LatestCoreBAFactory : BaseBootstrapperApplicationFactory + { + private static int loadCount = 0; + + protected override IBootstrapperApplication Create(IEngine engine, IBootstrapperCommand bootstrapperCommand) + { + if (loadCount > 0) + { + engine.Log(LogLevel.Standard, $"Reloaded {loadCount} time(s)"); + } + ++loadCount; + return new LatestCoreBA(engine); + } + } +} diff --git a/src/test/examples/TestEngine/TestEngine.cpp b/src/test/examples/TestEngine/TestEngine.cpp index 203df115..f0811e0a 100644 --- a/src/test/examples/TestEngine/TestEngine.cpp +++ b/src/test/examples/TestEngine/TestEngine.cpp @@ -35,6 +35,12 @@ HRESULT TestEngine::LoadBA( command.cbSize = sizeof(BOOTSTRAPPER_COMMAND); + hr = PathGetDirectory(wzBAFilePath, &command.wzBootstrapperWorkingFolder); + ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to allocate wzBootstrapperWorkingFolder"); + + hr = PathConcat(command.wzBootstrapperWorkingFolder, L"BootstrapperApplicationData.xml", &command.wzBootstrapperApplicationDataPath); + ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to allocate wzBootstrapperApplicationDataPath"); + args.cbSize = sizeof(BOOTSTRAPPER_CREATE_ARGS); args.pCommand = &command; args.pfnBootstrapperEngineProc = TestEngine::EngineProc; @@ -53,6 +59,9 @@ HRESULT TestEngine::LoadBA( ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure on BootstrapperApplicationCreate."); LExit: + ReleaseStr(command.wzBootstrapperApplicationDataPath); + ReleaseStr(command.wzBootstrapperWorkingFolder); + return hr; } @@ -92,6 +101,7 @@ HRESULT TestEngine::SendStartupEvent() void TestEngine::UnloadBA() { PFN_BOOTSTRAPPER_APPLICATION_DESTROY pfnDestroy = NULL; + BOOL fDisableUnloading = m_pCreateResults && m_pCreateResults->fDisableUnloading; ReleaseNullMem(m_pCreateResults); @@ -104,7 +114,11 @@ void TestEngine::UnloadBA() if (m_hBAModule) { - ::FreeLibrary(m_hBAModule); + if (!fDisableUnloading) + { + ::FreeLibrary(m_hBAModule); + } + m_hBAModule = NULL; } } diff --git a/src/test/examples/TestEngine/precomp.h b/src/test/examples/TestEngine/precomp.h index 0d2afb06..3fbc7e90 100644 --- a/src/test/examples/TestEngine/precomp.h +++ b/src/test/examples/TestEngine/precomp.h @@ -9,6 +9,7 @@ #include "logutil.h" #include "memutil.h" #include "pathutil.h" +#include "strutil.h" #include "BootstrapperEngine.h" #include "BootstrapperApplication.h" -- cgit v1.2.3-55-g6feb