StartZoneConfig.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Collections.Generic;
  3. using MongoDB.Bson.Serialization.Attributes;
  4. using MongoDB.Bson.Serialization.Options;
  5. using System.ComponentModel;
  6. namespace ET
  7. {
  8. [Config]
  9. public partial class StartZoneConfigCategory : Singleton<StartZoneConfigCategory>, IMerge
  10. {
  11. [BsonElement]
  12. [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)]
  13. private Dictionary<int, StartZoneConfig> dict = new();
  14. public void Merge(object o)
  15. {
  16. StartZoneConfigCategory s = o as StartZoneConfigCategory;
  17. foreach (var kv in s.dict)
  18. {
  19. this.dict.Add(kv.Key, kv.Value);
  20. }
  21. }
  22. public StartZoneConfig Get(int id)
  23. {
  24. this.dict.TryGetValue(id, out StartZoneConfig item);
  25. if (item == null)
  26. {
  27. throw new Exception($"配置找不到,配置表名: {nameof (StartZoneConfig)},配置id: {id}");
  28. }
  29. return item;
  30. }
  31. public bool Contain(int id)
  32. {
  33. return this.dict.ContainsKey(id);
  34. }
  35. public Dictionary<int, StartZoneConfig> GetAll()
  36. {
  37. return this.dict;
  38. }
  39. public StartZoneConfig GetOne()
  40. {
  41. if (this.dict == null || this.dict.Count <= 0)
  42. {
  43. return null;
  44. }
  45. var enumerator = this.dict.Values.GetEnumerator();
  46. enumerator.MoveNext();
  47. return enumerator.Current;
  48. }
  49. }
  50. public partial class StartZoneConfig: ProtoObject, IConfig
  51. {
  52. /// <summary>Id</summary>
  53. public int Id { get; set; }
  54. /// <summary>数据库地址</summary>
  55. public string DBConnection { get; set; }
  56. /// <summary>数据库名</summary>
  57. public string DBName { get; set; }
  58. }
  59. }