StartMachineConfig.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using System.Collections.Generic;
  3. using MongoDB.Bson.Serialization.Attributes;
  4. using ProtoBuf;
  5. namespace ET
  6. {
  7. [ProtoContract]
  8. [Config]
  9. public partial class StartMachineConfigCategory : ProtoObject
  10. {
  11. public static StartMachineConfigCategory Instance;
  12. [ProtoIgnore]
  13. [BsonIgnore]
  14. private Dictionary<int, StartMachineConfig> dict = new Dictionary<int, StartMachineConfig>();
  15. [BsonElement]
  16. [ProtoMember(1)]
  17. private List<StartMachineConfig> list = new List<StartMachineConfig>();
  18. public StartMachineConfigCategory()
  19. {
  20. Instance = this;
  21. }
  22. public override void EndInit()
  23. {
  24. foreach (StartMachineConfig config in list)
  25. {
  26. config.EndInit();
  27. this.dict.Add(config.Id, config);
  28. }
  29. this.AfterEndInit();
  30. }
  31. public StartMachineConfig Get(int id)
  32. {
  33. this.dict.TryGetValue(id, out StartMachineConfig item);
  34. if (item == null)
  35. {
  36. throw new Exception($"配置找不到,配置表名: {nameof (StartMachineConfig)},配置id: {id}");
  37. }
  38. return item;
  39. }
  40. public bool Contain(int id)
  41. {
  42. return this.dict.ContainsKey(id);
  43. }
  44. public Dictionary<int, StartMachineConfig> GetAll()
  45. {
  46. return this.dict;
  47. }
  48. public StartMachineConfig GetOne()
  49. {
  50. if (this.dict == null || this.dict.Count <= 0)
  51. {
  52. return null;
  53. }
  54. return this.dict.Values.GetEnumerator().Current;
  55. }
  56. }
  57. [ProtoContract]
  58. public partial class StartMachineConfig: ProtoObject, IConfig
  59. {
  60. [ProtoMember(1)]
  61. public int Id { get; set; }
  62. [ProtoMember(2)]
  63. public string InnerIP { get; set; }
  64. [ProtoMember(3)]
  65. public string OuterIP { get; set; }
  66. [ProtoMember(4)]
  67. public string WatcherPort { get; set; }
  68. }
  69. }