AppManagerComponent.cs 1.6 KB

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