Exemplo n.º 1
0
        public static List <CommandInfo> GetAppInfo(string arguments, IHaveLog context)
        {
            var res = new List <CommandInfo>();

            context.DebugLog($"GetAppInfo.Running command {arguments}");
            var unparsedArg = Utils.runApp(arguments);

            context.DebugLog($"GetAppInfo: Above command got {unparsedArg}");
            foreach (var cmd in unparsedArg.Split(new char[] { '\r', '\n' }))
            {
                if (cmd.Length < 2)
                {
                    continue;
                }
                if (cmd.StartsWith("ERR:"))
                {
                    context.DebugLog($"{cmd.Trim()} arg={arguments}");
                    continue;
                }
                if (cmd.StartsWith("*"))
                {
                    continue;
                }
                context.DebugLog($"  ***{cmd}");
                try
                {
                    if (cmd.StartsWith("RecoResult_"))
                    {
                        int sp = cmd.IndexOf(" ");
                        res.Add(new CommandInfo
                        {
                            command = cmd.Substring(0, sp),
                            Text    = cmd.Substring(sp + 1).Trim()
                        });
                        continue;
                    }
                    var     cmds = cmd.Split(' ');
                    var     command = cmds[0];
                    int     x = 0, y = 0;
                    decimal cmpRes = decimal.MaxValue;
                    if (cmds.Length > 2)
                    {
                        x = Convert.ToInt32(cmds[1]);
                        y = Convert.ToInt32(cmds[2]);
                    }
                    if (cmds.Length > 3)
                    {
                        cmpRes = Convert.ToDecimal(cmds[3]);
                    }
                    string decision = null;
                    if (cmds.Length > 4)
                    {
                        decision = cmds[4];
                    }
                    string extraInfo = null;
                    if (cmds.Length > 5)
                    {
                        extraInfo = cmds[5];
                    }
                    res.Add(new CommandInfo {
                        command = command, cmpRes = cmpRes, x = x, y = y, decision = decision, extraInfo = extraInfo
                    });
                } catch (Exception exc)
                {
                    context.InfoLog("failed " + exc.Message + " " + cmd);
                    context.InfoLog("StackTrace:" + exc.ToString());
                    throw exc;
                }
            }
            return(res);
        }