AppManagerComponent.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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))
  26. {
  27. continue;
  28. }
  29. if (startConfig.Options.AppType == AppType.Manager)
  30. {
  31. continue;
  32. }
  33. string arguments = $"--id={startConfig.Options.Id} --appType={startConfig.Options.AppType}";
  34. ProcessStartInfo info = new ProcessStartInfo(@"App.exe", arguments)
  35. {
  36. UseShellExecute = true,
  37. WorkingDirectory = @"..\Server\Bin\Debug"
  38. };
  39. Process process = Process.Start(info);
  40. this.processes.Add(process.Id, process);
  41. }
  42. }
  43. }
  44. }