JD2022-TU1/main/tools/framework/JD.TeaBoxAddinSystem/Bootstrap/BootstrapCommandRunner.cs

58 lines
1.5 KiB
C#

using System.Collections.Generic;
using JD.Kernel.StaticHelpers;
namespace JD.TeaBoxAddinSystem.Bootstrap
{
/// <summary>
/// Class that runs bootstrap commands from a list of commands.
/// </summary>
public class BootstrapCommandRunner
{
#region Variables
private readonly IEnumerable<IBootstrapCommand> m_commands;
#endregion
#region Constructor
/// <summary>
/// Alternative constructor.
/// </summary>
/// <param name="commands">Commands to run.</param>
public BootstrapCommandRunner(IEnumerable<IBootstrapCommand> commands)
{
Throw.IfNull(commands, "commands");
m_commands = commands;
}
#endregion
#region Methods
/// <summary>
/// Runs the commands.
/// </summary>
/// <returns>True if all commands executed normally, or false if one of the commands asked to quit or threw an exception.</returns>
public bool Run()
{
foreach (IBootstrapCommand command in m_commands)
{
LogService.LogService.LogDebugMessage("Running command {0}...", command);
command.Execute();
ICommandLineHandler handler = command as ICommandLineHandler;
if (handler != null && handler.QuitAfterExecuted)
{
return false;
}
}
return true;
}
#endregion
}
}