AppManagerComponent.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System.Collections.Generic;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Linq;
  5. using Base;
  6. namespace Model
  7. {
  8. [ObjectEvent]
  9. public class AppManagerComponentEvent : ObjectEvent<AppManagerComponent>, IAwake
  10. {
  11. public void Awake()
  12. {
  13. this.GetValue().Awake();
  14. }
  15. }
  16. public class AppManagerComponent : Component
  17. {
  18. private readonly Dictionary<int, Process> processes = new Dictionary<int, Process>();
  19. public void Awake()
  20. {
  21. string[] ips = NetHelper.GetAddressIPs();
  22. StartConfig[] startConfigs = Game.Scene.GetComponent<StartConfigComponent>().GetAll();
  23. foreach (StartConfig startConfig in startConfigs)
  24. {
  25. if (!ips.Contains(startConfig.IP) && startConfig.IP != "*")
  26. {
  27. continue;
  28. }
  29. if (startConfig.Options.AppType == AppType.Manager)
  30. {
  31. continue;
  32. }
  33. #if __MonoCS__
  34. const string exe = @"mono";
  35. string arguments = $"App.exe --id={startConfig.Options.Id} --appType={startConfig.Options.AppType}";
  36. const string workDir = @"../Server/Bin/Debug";
  37. #else
  38. const string exe = @"App.exe";
  39. string arguments = $"--id={startConfig.Options.Id} --appType={startConfig.Options.AppType}";
  40. const string workDir = @"..\Server\Bin\Debug";
  41. #endif
  42. Log.Debug($"{startConfig.Options.Id} {MongoHelper.ToJson(startConfig)}");
  43. ProcessStartInfo info = new ProcessStartInfo
  44. {
  45. FileName = exe,
  46. Arguments = arguments,
  47. CreateNoWindow = true,
  48. UseShellExecute = true,
  49. WorkingDirectory = workDir
  50. };
  51. Process process = Process.Start(info);
  52. this.processes.Add(process.Id, process);
  53. }
  54. }
  55. }
  56. }