Ejemplo n.º 1
0
        protected ExecResult External(string Dir, string Option, ArgumentList Args, OptRewrite[] Rewrite)
        {
            int Separator = Option.IndexOf(".exe");

            if (Separator == -1)
            {
                return(new ERError($"Fail to detect .exe"));
            }

            string Exe     = Option.Substring(0, Separator + 4);
            string ExeArgs = Option.Substring(Separator + 5);

            ExternalToolResult Output = ExternalExec.Exec(Exe, ExeArgs, Args, Rewrite);

            if (Output != null)
            {
                if (Output.ExitCode == 0)
                {
                    return(new EROk());
                }
                else
                {
                    return(new ERError(Output.Result));
                }
            }
            else
            {
                return(new ERError($"Fail"));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Выполнить команду
        /// </summary>
        /// <param name="Command"></param>
        /// <param name="Args"></param>
        /// <param name="Rewrite"></param>
        /// <returns></returns>
        public ExecResult Exec(string Command, ArgumentList Args, OptRewrite[] Rewrite)
        {
            var A = GetAction(Command);

            if (A != null)
            {
                //var Cmd = ProcessCommand(A.Command, Args, Rewrite);

                string Dir = Args.Get("$dir");
                string P   = (A.CustomToolPath != null) ? A.CustomToolPath : ToolPath;
                if (!File.Exists(P))
                {
                    return(new ERError($"No specified path for tool: {P}"));
                }
                ExternalToolResult Result;

                try
                {
                    Result = ExternalExec.Exec(P, A.Command, Args, Rewrite);
                }
                catch (Exception Exc)
                {
                    return(new ERError(Exc.Message));
                }
                //string Output = ExternalTool.Run(P, Cmd, Dir);
                if (Result == null)
                {
                    return(new ERError("No output"));
                }

                var E = GetMessage(Result, A.ErrorMask);
                if (E != null)
                {
                    return(new ERError(E));
                }

                var W = GetMessage(Result, A.WarningMask);
                if (W != null)
                {
                    return(new ERWarning(W));
                }

                return(new EROk());
            }
            else
            {
                return(new ERError($"No available command '{Command}'"));
            }
        }