AppManagerComponent.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #else
  37. const string exe = @"App.exe";
  38. string arguments = $"--id={startConfig.Options.Id} --appType={startConfig.Options.AppType}";
  39. #endif
  40. ProcessStartInfo info = new ProcessStartInfo(exe, arguments)
  41. {
  42. UseShellExecute = true,
  43. WorkingDirectory = @"..\Server\Bin\Debug"
  44. };
  45. Process process = Process.Start(info);
  46. this.processes.Add(process.Id, process);
  47. }
  48. }
  49. }
  50. }