StartConfigComponent.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 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. }
  38. catch (Exception)
  39. {
  40. Log.Error($"config错误: {s2}");
  41. }
  42. }
  43. this.StartConfig = this.Get(appId);
  44. }
  45. public StartConfig Get(int id)
  46. {
  47. return this.configDict[id];
  48. }
  49. public StartConfig[] GetAll()
  50. {
  51. return this.allConfigs.ToArray();
  52. }
  53. }
  54. }