StartConfigComponent.cs 1.5 KB

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