public void AddBridge(List <string> gates, List <string> regions) { if (gates.Count == 0 || regions.Count == 0) { throw new InvalidCastException("未找到有效的关联项。"); } lock (Bridges) { foreach (var gate in gates) { var g = Bridges.FirstOrDefault(_ => _.ID == gate); if (g == null) { g = new Bridge() { ID = gate, Links = new List <string>() }; Bridges.Add(g); } else { g.UpdateTime = DateTime.Now; } foreach (var reg in regions) { if (g.Links.All(_ => _ != reg)) { g.Links.Add(reg); } } g.Links = g.Links.OrderBy(_ => _).ToList(); } } }
public TargetObj Get <T>(string id) where T : TargetObj { Type type = typeof(T); switch (type.Name) { case nameof(Bridge): return(Bridges.FirstOrDefault(_ => _.ID == id)); case nameof(GateInfo): return(Gates.FirstOrDefault(_ => _.ID == id)); case nameof(FenceRegionsInfo): return(Regions.FirstOrDefault(_ => _.ID == id)); } return(null); }
public FenceRegionsInfo[] GetBridgeFromGate(string id) { var regions = Bridges?.FirstOrDefault(_ => _.ID == id); List <FenceRegionsInfo> list = new List <FenceRegionsInfo>(); if (regions != null && regions.Links != null) { foreach (var r in regions.Links) { var reg = Regions?.FirstOrDefault(_ => _.ID == r); if (reg != null) { list.Add(reg); } } } return(list.ToArray()); }