// 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 WixToolset.Mba.Core
{
using System;
using System.Runtime.InteropServices;
///
/// Default implementation of .
///
public abstract class BaseBootstrapperApplicationFactory : IBootstrapperApplicationFactory
{
///
/// Default implementation of
///
/// The args struct given by the engine when initially creating the BA.
/// The results struct given by the engine when initially creating the BA
public void Create(IntPtr pArgs, IntPtr pResults)
{
InitializeFromCreateArgs(pArgs, out var engine, out var bootstrapperCommand);
var ba = this.Create(engine, bootstrapperCommand);
StoreBAInCreateResults(pResults, ba);
}
///
/// Called by to get the .
///
/// The bundle engine.
/// Command information passed from the engine for the BA to perform.
/// The for the bundle.
protected abstract IBootstrapperApplication Create(IEngine engine, IBootstrapperCommand bootstrapperCommand);
///
/// Initializes the native part of .
/// Most users should inherit from instead of calling this method.
///
/// The args struct given by the engine when initially creating the BA.
/// The bundle engine interface.
/// The context of the current run of the bundle.
public static void InitializeFromCreateArgs(IntPtr pArgs, out IEngine engine, out IBootstrapperCommand bootstrapperCommand)
{
Command pCommand = new Command
{
cbSize = Marshal.SizeOf(typeof(Command))
};
var pEngine = MbaNative.InitializeFromCreateArgs(pArgs, ref pCommand);
engine = new Engine(pEngine);
bootstrapperCommand = pCommand.GetBootstrapperCommand();
}
///
/// Registers the BA with the engine using the default mapping between the message based interface and the COM interface.
/// Most users should inherit from instead of calling this method.
///
/// The results struct given by the engine when initially creating the BA
/// The .
public static void StoreBAInCreateResults(IntPtr pResults, IBootstrapperApplication ba)
{
MbaNative.StoreBAInCreateResults(pResults, ba);
}
}
}