private readonly Tuple<bool, Action>[]Func<bool>>[] action;
// in constructor:
actions = new Tuple<bool, Action>[]Func<bool>>[]
{
Tuple.Createnew Tuple<bool, Func<bool>>(settings.StopOnBackupCurrentInstallerFailure, DoBackupCurrentVersion),
Tuple.Createnew Tuple<bool, Func<bool>>(settings.StopOnUpdateCodeBaseFailure, DoGetLatestVersion),
Tuple.Createnew Tuple<bool, Func<bool>>(settings.StopOnCompileFailure, DoCompileCodeBase),
Tuple.Createnew Tuple<bool, Func<bool>>(settings.StopOnBuildInstallerFailure, DoBuildInstaller)
}
private bool ExecuteInternal()
{
var errors = new List<string>();
var logger = _logProvider.GetLogger(GetType().Name);
var settings = Properties.Settings.Default;
DoArchiveOldInstallers();
foreach (var action in actions)
{
if (action.Item1 && !action.Item2())
return false;
}
return true;
}
The syntax to initialize the list of Tuple
s is not great. You could improve that by having a special type TupleList<T1, T2> : List<Tuple<T1, T2>>
, which would have a method like void Add(T1 item1, T2 item2)
. That way, the initialization simplifies to:
actions = new TupleList<bool, Func<bool>>
{
{ settings.StopOnBackupCurrentInstallerFailure, DoBackupCurrentVersion },
{ settings.StopOnUpdateCodeBaseFailure, DoGetLatestVersion },
{ settings.StopOnCompileFailure, DoCompileCodeBase },
{ settings.StopOnBuildInstallerFailure, DoBuildInstaller }
}