RealmGateAddressComponent.cs 923 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using Base;
  5. namespace Model
  6. {
  7. [ObjectEvent]
  8. public class RealmGateAddressComponentEvent : ObjectEvent<RealmGateAddressComponent>, IAwake
  9. {
  10. public void Awake()
  11. {
  12. this.GetValue().Awake();
  13. }
  14. }
  15. public class RealmGateAddressComponent : Component
  16. {
  17. private readonly List<string> GateAddress = new List<string>();
  18. public void Awake()
  19. {
  20. string s = File.ReadAllText("./CommandLineConfig.txt");
  21. CommandLines commandLines = MongoHelper.FromJson<CommandLines>(s);
  22. foreach (CommandLine commandLine in commandLines.Commands)
  23. {
  24. if (commandLine.Options.AppType != "Gate")
  25. {
  26. continue;
  27. }
  28. this.GateAddress.Add($"{commandLine.Options.Host}:{commandLine.Options.Port}");
  29. }
  30. }
  31. public string GetAddress()
  32. {
  33. int n = RandomHelper.RandomNumber(0, this.GateAddress.Count);
  34. return this.GateAddress[n];
  35. }
  36. }
  37. }