BuildCommandExt.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. namespace XGame.Editor.Build
  2. {
  3. internal static class BuildCommandExt
  4. {
  5. public static void Start(this IBuildCommand cmd)
  6. {
  7. if (cmd is ICommandExecuter executer)
  8. {
  9. var code = executer.Execute();
  10. var context = cmd as IBuildContextAdapter;
  11. BuildLog.Log($"ICommandExecuter Completed. Type:{executer.GetType()} Code:{code}");
  12. BuildUtils.CmdCompleted(code, context?.Context);
  13. }
  14. else if (cmd is ICommandExecuterAsync executerAsync)
  15. {
  16. executerAsync.Execute();
  17. }
  18. else
  19. {
  20. BuildLog.Error($"IBuildCommand Execute Error: No Implemented ICommandExecuter or ICommandExecuterAsync. Type:{cmd?.GetType()}");
  21. var context = cmd as IBuildContextAdapter;
  22. BuildUtils.CmdCompleted(BuildErrorCode.CommandExecuteFailed, context?.Context);
  23. }
  24. }
  25. /// <summary>
  26. /// 异步Command的结束方法
  27. /// </summary>
  28. /// <typeparam name="T"></typeparam>
  29. /// <param name="cmdAsync"></param>
  30. /// <param name="code"></param>
  31. public static void Completed<T>(this T cmdAsync, BuildErrorCode code = BuildErrorCode.CmdCompleted) where T : class, ICommandExecuterAsync
  32. {
  33. //if (cmdAsync == null)
  34. //{
  35. // BuildLog.Error($"ICommandExecuterAsync is null. code:{code}");
  36. // return;
  37. //}
  38. var context = cmdAsync as IBuildContextAdapter;
  39. //if (context == null)
  40. //{
  41. // BuildLog.Error($"ICommandExecuterAsync Context is null. code:{code}");
  42. // return;
  43. //}
  44. BuildLog.Log($"ICommandExecuterAsync Completed. Type:{cmdAsync?.GetType()} Code:{code}");
  45. BuildUtils.CmdCompleted(code, context?.Context);
  46. }
  47. }
  48. }