using System; using System.Collections.Generic; using System.IO; using Base; namespace Model { [ObjectEvent] public class RealmGateAddressComponentEvent : ObjectEvent, IAwake { public void Awake() { this.GetValue().Awake(); } } public class RealmGateAddressComponent : Component { private readonly List GateAddress = new List(); public void Awake() { string s = File.ReadAllText("./CommandLineConfig.txt"); CommandLines commandLines = MongoHelper.FromJson(s); foreach (CommandLine commandLine in commandLines.Commands) { if (commandLine.Options.AppType != "Gate") { continue; } this.GateAddress.Add($"{commandLine.Options.Host}:{commandLine.Options.Port}"); } } public string GetAddress() { int n = RandomHelper.RandomNumber(0, this.GateAddress.Count); return this.GateAddress[n]; } } }