Esempio n. 1
0
        /// <summary>
        /// Run command (parse, find, compare arguments and execute if ok)
        /// </summary>
        /// <param name="commandline"></param>
        /// <returns></returns>
        public CommandResult Run(string commandline)
        {
            // Validate
            var result = ValidateDo(commandline);

            // Run
            if (result.Item1.State == ResultState.Success)
            {
                var method = _lookup.GetMethode(result.Item3);
                if (method != null)
                {
                    try
                    {
                        var obj          = Activator.CreateInstance(method.Item3, null);
                        var methodResult = method.Item2.Invoke(obj, result.Item2.ToArray());
                        result.Item1.Result = methodResult;
                        result.Item1.State  = ResultState.Success;
                        return(result.Item1);
                    }
                    catch (Exception ex)
                    {
                        result.Item1.State = ResultState.ErrorWhileExecuting;
                        result.Item1.Exceptions.Add(ex);
                        return(result.Item1);
                    }
                }
            }

            // Result
            return(result.Item1);
        }