Ejemplo n.º 1
0
        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();
            }
        }
Ejemplo n.º 2
0
        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());
        }
Ejemplo n.º 3
0
        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());
        }
Ejemplo n.º 4
0
 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));
        }
Ejemplo n.º 6
0
 public ResponseBuilder(Biz.BizContext context)
 {
     this.context = context;
 }
Ejemplo n.º 7
0
 public BizCommand(BizAgent agent, BizContext context, string name)
     : base(agent, context, name)
 {
 }