Ejemplo n.º 1
0
        public void Handle(Command cmd)
        {
            var export = _router.FindExport(cmd);

            object target = null;

            try
            {
                target = _instantiationStrategy.Instantiate(export.Type);
            }
            catch(Exception ex)
            {
                var msg = string.Format("Unable to instantiate type {0}", export.Type.FullName);
                throw new InvocationException(msg, ex);
            }

            var parameters = new List<object>();
            if (export.ParameterType != null)
            {
                try
                {
                    parameters.Add(_parameterBinder.BuildParameter(export.ParameterType, cmd.Args));
                }
                catch (Exception ex)
                {
                    var msg = string.Format("Unable to bind parameter type {0}", export.ParameterType.FullName);
                    throw new InvocationException(msg, ex);
                }
            }

            export.Method.Invoke(target, parameters.ToArray());
        }
Ejemplo n.º 2
0
 public Export FindExport(Command command)
 {
     try
     {
         var @namespace = command.Namespace.HasValue() ? command.Namespace : _routingInfo.DefaultNamespace;
         return _routingInfo.ExportsInNamespace(@namespace).Single(export => export.Name == command.Name);
     }
     catch (Exception)
     {
         throw new RoutingException(command.CommandString);
     }
 }
Ejemplo n.º 3
0
 public void Handle(Command cmd)
 {
     if (cmd.CommandString == "help" && cmd.Args.Length > 0)
     {
         var referencedCommand = Command.Parse(cmd.Args);
         PrintCommandHelp(referencedCommand);
     }
     else
     {
         PrintUsage();
     }
 }
Ejemplo n.º 4
0
 public void PrintCommandHelp(Command cmd)
 {
     var export = _router.FindExport(cmd);
     Console.Write(_parameterHelpProvider.GetHelp(export.ParameterType));
 }
Ejemplo n.º 5
0
 public bool CanHandle(Command cmd)
 {
     return cmd.CommandString == null || cmd.CommandString == "help";
 }