using System.Collections.Generic;
using JD.Kernel.StaticHelpers;
namespace JD.TeaBoxAddinSystem.Bootstrap
{
///
/// Class that runs bootstrap commands from a list of commands.
///
public class BootstrapCommandRunner
{
#region Variables
private readonly IEnumerable m_commands;
#endregion
#region Constructor
///
/// Alternative constructor.
///
/// Commands to run.
public BootstrapCommandRunner(IEnumerable commands)
{
Throw.IfNull(commands, "commands");
m_commands = commands;
}
#endregion
#region Methods
///
/// Runs the commands.
///
/// True if all commands executed normally, or false if one of the commands asked to quit or threw an exception.
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
}
}