StartConfigComponent.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. namespace Model
  5. {
  6. [ObjectEvent]
  7. public class StartConfigComponentEvent : ObjectEvent<StartConfigComponent>, IAwake<string, int>
  8. {
  9. public void Awake(string a, int b)
  10. {
  11. this.Get().Awake(a, b);
  12. }
  13. }
  14. public class StartConfigComponent: Component
  15. {
  16. private readonly List<StartConfig> allConfigs = new List<StartConfig>();
  17. private readonly Dictionary<int, StartConfig> configDict = new Dictionary<int, StartConfig>();
  18. public StartConfig StartConfig { get; private set; }
  19. public StartConfig DBStartConfig { get; private set; }
  20. public StartConfig RealmConfig { get; private set; }
  21. public StartConfig LocationConfig { get; private set; }
  22. public void Awake(string path, int appId)
  23. {
  24. string[] ss = File.ReadAllText(path).Split('\n');
  25. foreach (string s in ss)
  26. {
  27. string s2 = s.Trim();
  28. if (s2 == "")
  29. {
  30. continue;
  31. }
  32. try
  33. {
  34. StartConfig startConfig = MongoHelper.FromJson<StartConfig>(s2);
  35. this.allConfigs.Add(startConfig);
  36. this.configDict.Add(startConfig.AppId, startConfig);
  37. if (startConfig.AppType.Is(AppType.Realm))
  38. {
  39. this.RealmConfig = startConfig;
  40. }
  41. if (startConfig.AppType.Is(AppType.Location))
  42. {
  43. this.LocationConfig = startConfig;
  44. }
  45. }
  46. catch (Exception)
  47. {
  48. Log.Error($"config错误: {s2}");
  49. }
  50. }
  51. this.StartConfig = this.Get(appId);
  52. }
  53. public StartConfig Get(int id)
  54. {
  55. return this.configDict[id];
  56. }
  57. public StartConfig[] GetAll()
  58. {
  59. return this.allConfigs.ToArray();
  60. }
  61. }
  62. }