Beispiel #1
0
        public async ETTask Run(ModeContex contex, string content)
        {
            string[] ss = content.Split(" ");
            switch (ss[0])
            {
            case ConsoleMode.Robot:
                break;

            case "Run":
            {
                int caseType = int.Parse(ss[1]);

                try
                {
                    RobotLog.Debug($"run case start: {caseType}");
                    await RobotCaseDispatcherComponent.Instance.Run(caseType, content);

                    RobotLog.Debug($"run case finish: {caseType}");
                }
                catch (Exception e)
                {
                    RobotLog.Debug($"run case error: {caseType}\n{e}");
                }
                break;
            }

            case "RunAll":
            {
                FieldInfo[] fieldInfos = typeof(RobotCaseType).GetFields();
                foreach (FieldInfo fieldInfo in fieldInfos)
                {
                    int caseType = (int)fieldInfo.GetValue(null);
                    if (caseType > RobotCaseType.MaxCaseType)
                    {
                        RobotLog.Debug($"case > {RobotCaseType.MaxCaseType}: {caseType}");
                        break;
                    }
                    try
                    {
                        RobotLog.Debug($"run case start: {caseType}");
                        await RobotCaseDispatcherComponent.Instance.Run(caseType, content);

                        RobotLog.Debug($"---------run case finish: {caseType}");
                    }
                    catch (Exception e)
                    {
                        RobotLog.Debug($"run case error: {caseType}\n{e}");
                        break;
                    }
                }
                break;
            }
            }
            await ETTask.CompletedTask;
        }
        public static async ETTask Run(this RobotCaseDispatcherComponent self, int caseType, string line)
        {
            if (!self.Dictionary.TryGetValue(caseType, out IRobotCase iRobotCase))
            {
                return;
            }

            try
            {
                using (RobotCase robotCase = await RobotCaseComponent.Instance.New())
                {
                    robotCase.CommandLine = line;
                    await iRobotCase.Run(robotCase);
                }
            }
            catch (Exception e)
            {
                Log.Error($"{self.DomainZone()} {e}");
                RobotLog.Console($"RobotCase Error {caseType}:\n\t{e}");
            }
        }