RobotConsoleHandler.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Reflection;
  3. namespace ET.Server
  4. {
  5. [ConsoleHandler(ConsoleMode.Robot)]
  6. public class RobotConsoleHandler: IConsoleHandler
  7. {
  8. public async ETTask Run(ModeContex contex, string content)
  9. {
  10. string[] ss = content.Split(" ");
  11. switch (ss[0])
  12. {
  13. case ConsoleMode.Robot:
  14. break;
  15. case "Run":
  16. {
  17. int caseType = int.Parse(ss[1]);
  18. try
  19. {
  20. RobotLog.Debug($"run case start: {caseType}");
  21. await EventSystem.Instance.Invoke<RobotInvokeArgs, ETTask>(caseType, new RobotInvokeArgs() { Content = content });
  22. RobotLog.Debug($"run case finish: {caseType}");
  23. }
  24. catch (Exception e)
  25. {
  26. RobotLog.Debug($"run case error: {caseType}\n{e}");
  27. }
  28. break;
  29. }
  30. case "RunAll":
  31. {
  32. FieldInfo[] fieldInfos = typeof (RobotCaseType).GetFields();
  33. foreach (FieldInfo fieldInfo in fieldInfos)
  34. {
  35. int caseType = (int)fieldInfo.GetValue(null);
  36. if (caseType > RobotCaseType.MaxCaseType)
  37. {
  38. RobotLog.Debug($"case > {RobotCaseType.MaxCaseType}: {caseType}");
  39. break;
  40. }
  41. try
  42. {
  43. RobotLog.Debug($"run case start: {caseType}");
  44. await EventSystem.Instance.Invoke<RobotInvokeArgs, ETTask>(caseType, new RobotInvokeArgs() { Content = content});
  45. RobotLog.Debug($"---------run case finish: {caseType}");
  46. }
  47. catch (Exception e)
  48. {
  49. RobotLog.Debug($"run case error: {caseType}\n{e}");
  50. break;
  51. }
  52. }
  53. break;
  54. }
  55. }
  56. await ETTask.CompletedTask;
  57. }
  58. }
  59. }