IAction ( Action) Command Pattern. , (.NET v1.0), Composite, . , Add, Execute .
public CompositeAction : IAction
{
private ActiondCollection Action;
void Add(Action action)
{
Action.Add(action);
}
void Execute()
{
foreach(Action action in Actions)
{
action.Execute();
}
}
}
.
, Execute void, - ( IsValid DoWebSiteExist, )
, .
, , bool, , Func
, bool, . , , , .
namespace Test
{
class Program
{
static bool isvalid = true;
static void Main(string[] args)
{
List<System.Func<bool>> MainActions = new List<System.Func<bool>>();
List<System.Func<bool>> CompositeActions = new List<System.Func<bool>>();
MainActions.Add(() => NonCompositeAction());
CompositeActions.Add(() => DoesWebsiteNotExists());
CompositeActions.Add(() => CreatePhyiscalDir());
CompositeActions.Add(() => CreateVirDirectories());
CompositeActions.Add(() => CreateWebsite());
MainActions.Add(() => ExcuteCompositeActions(CompositeActions));
foreach (Func<bool> action in MainActions)
action.Invoke();
}
static bool ExcuteCompositeActions(List<System.Func<bool>> Actions)
{
bool Success = true;
foreach (Func<bool> action in Actions)
{
if (!action.Invoke())
{
Success = false;
break;
}
}
return Success;
}
static bool NonCompositeAction()
{
Console.WriteLine("NonCompositeAction");
return true;
}
static bool DoesWebsiteNotExists()
{
Console.WriteLine("DoesWebsiteExists");
return isvalid;
}
static bool CreatePhyiscalDir()
{
Console.WriteLine("CreatePhyiscalDir");
return true;
}
static bool CreateWebsite()
{
Console.WriteLine("CreateWebsite");
return true;
}
static bool CreateVirDirectories()
{
Console.WriteLine("CreateVirDirectories");
return true;
}
}
}
, , , .
. List<Func<bool> .
,
public class CreatePhyiscalDir
{
public bool Execute()
{
Console.WriteLine("CreatePhyiscalDir");
return true;
}
}
CreatePhyiscalDir cpd = new CreatePhyiscalDir();
CompositeActions.Add(() => DoesWebsiteExists());
CompositeActions.Add(() => cpd.Execute());
, cpd.
, List<Func<bool>...
...
, Chain of Responsiblity Pipeline, , , List<Func<bool>> Composite Actionl, SnOrfus. , , , , .
. , , , . , .