AppManagerComponent.cs 1.2 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. CommandLines commandLines = Game.Scene.GetComponent<OptionsComponent>().AllOptions;
  23. foreach (Options options in commandLines.Options)
  24. {
  25. if (!ips.Contains(options.IP))
  26. {
  27. continue;
  28. }
  29. if (options.AppType == AppType.Manager)
  30. {
  31. continue;
  32. }
  33. string arguments = $"--appType={options.AppType} --id={options.Id} --Protocol={options.Protocol} --Host={options.Host} --Port={options.Port}";
  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. }