public TaskContext CreateContext(IScriptParams init) { Debug.Assert(Context==null); var context = new TaskContext(init); context.RequestedTask = TaskName; Context = context; return context; }
public TasksListTests() { _sut = new TasksList(Setup.Configuration(c => { c.MethodToExecute(m => m.Name == "Execute"); })); _context = Setup.Context(); _context.RequestedTask = "Build"; AddClean(); AddBuild(); AddDummy(); }
TaskExecutor GetExecutor(TaskConfiguration config, TaskContext context) { var deps = config.GetDependencies(context.InitData); var execDeps = new TaskExecutor[deps.Length]; for (var i = 0; i < deps.Length; i++) { var typeConfig = _tasks.Find(d => d.Type == deps[i]); if (typeConfig==null)throw new InvalidOperationException("Can't find task '{0}'".ToFormat(deps[i].Name)); execDeps[i] = GetExecutor(typeConfig, context); } if (!config.ShouldExecute(context.InitData)) return TaskExecutor.SkipTask; var method = _configuration.GetExecutableMethod(config.Type); return new TaskExecutor(config.Instance,method,execDeps); }
public TaskExecutor BuildExecutor(TaskContext context) { var name = context.RequestedTask; TaskConfiguration task = null; if (name.IsNullOrEmpty()) { task = _tasks.FirstOrDefault(d => d.IsDefault); if (task==null) throw new InvalidOperationException("There's no default task specified. Either specify a script name or annotate a task with [Default]"); } else { task = _tasks.Find(d => d.Type.Name == name); if (task==null) throw new InvalidOperationException("Can't find task '{0}'".ToFormat(name)); } return GetExecutor(task,context); }
public void Execute(TaskContext context) { if (_instance == null) { return; } foreach (var task in Dependencies) { task.Execute(context); } //var method = _instance.GetType().GetMethods().FirstOrDefault(_matchMethod); //if (method==null) throw new InvalidOperationException("No method in '{0}' matches convention to execute".ToFormat(_instance.GetType())); var name = _instance.GetType().Name; "Executing {0}".WriteInfo(name); context.Timer.Start(name); _method.Invoke(_instance,null); context.Timer.End(); }
public static TaskContext Context() { var c = new TaskContext(FakeScriptParamsObject()); return c; }