static void Main(string[] args) { try { //Register Type Biz.BizCommandFactory.Instance.Register(CMD_FOO, new Biz.Foo.FooAgent()); Biz.BizCommandFactory.Instance.Register(CMD_BAR, new Biz.Bar.BarAgent()); Biz.BizCommandFactory.Instance.Register(CMD_BAZ, new Biz.Baz.BazAgent()); //Composite Commands var invoker = new Invoker(); var context = new Biz.BizContext(); var commands = new string[] { CMD_FOO, CMD_BAR, CMD_BAZ }; // Run synchronously // invoker.Execute(payload, commands); // Run asynchronously var cancelcancelTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(3)); var records = invoker.ExecuteAsync(context, cancelcancelTokenSource.Token, commands).Result; Logger.Record("Invoke Success"); Logger.Record(JsonConvert.SerializeObject(records)); } catch (Exception exception) { Logger.Record("Invoke Exception"); Logger.Record(exception); } finally { Console.WriteLine("Press any key to exit"); Console.ReadKey(); } }
public async Task <Response> ExecuteAsync(Biz.BizContext context, CancellationToken cancellationToken, string[] names) { var builder = new Biz.BizCommandBuilder(context, Biz.BizCommandFactory.Instance); foreach (var name in names) { builder.Add(name); } var engine = new Engine(); await engine.ExecuteAsync(builder, cancellationToken); var response = new ResponseBuilder(context); return(response.Build()); }
public Response Execute(Biz.BizContext context, string[] names) { var builder = new Biz.BizCommandBuilder(context, Biz.BizCommandFactory.Instance); foreach (var name in names) { builder.Add(name); } var engine = new Engine(); engine.Execute(builder); var response = new ResponseBuilder(context); return(response.Build()); }
public BizCommandBuilder(BizContext context, BizCommandFactory factory) { this.context = context; this.factory = factory; }
public ICommand Create(string name, BizContext context) { var agent = this.agents[name]; return(new BizCommand(agent, context, name)); }
public ResponseBuilder(Biz.BizContext context) { this.context = context; }
public BizCommand(BizAgent agent, BizContext context, string name) : base(agent, context, name) { }