public void FlushPortMapCache() { portMapCache = new Dictionary <int, PortMapConfigCache>(); Dictionary <string, Server> id2server = new Dictionary <string, Server>(); Dictionary <string, int> server_group = new Dictionary <string, int>(); foreach (Server s in configs) { id2server[s.id] = s; if (s.group != null && s.group.Length > 0) { server_group[s.group] = 1; } } foreach (KeyValuePair <string, PortMapConfig> pair in portMap) { int key = 0; PortMapConfig pm = pair.Value; if (!pm.enable) { continue; } if (id2server.ContainsKey(pm.id) || server_group.ContainsKey(pm.id) || pm.id == null || pm.id.Length == 0) { } else { continue; } try { key = int.Parse(pair.Key); } catch (FormatException) { continue; } portMapCache[key] = new PortMapConfigCache { type = pm.type, id = pm.id, server = id2server.ContainsKey(pm.id) ? id2server[pm.id] : null, server_addr = pm.server_addr, server_port = pm.server_port }; } }
public void FlushPortMapCache() { portMapCache = new Dictionary <int, PortMapConfigCache>(); Dictionary <string, Server> id2server = new Dictionary <string, Server>(); foreach (Server s in configs) { id2server[s.id] = s; } foreach (KeyValuePair <string, PortMapConfig> pair in portMap) { int key = 0; PortMapConfig pm = pair.Value; if (!pm.enable) { continue; } if (!id2server.ContainsKey(pm.id)) { continue; } try { key = int.Parse(pair.Key); } catch (FormatException) { continue; } portMapCache[key] = new PortMapConfigCache { type = pm.type, id = pm.id, server = id2server[pm.id], server_addr = pm.server_addr, server_port = pm.server_port }; } }
public void FlushPortMapCache() { portMapCache = new Dictionary <int, PortMapConfigCache>(); Dictionary <string, Server> id2server = new Dictionary <string, Server>(); Dictionary <string, int> server_group = new Dictionary <string, int>(); foreach (Server s in configs) { id2server[s.id] = s; if (!string.IsNullOrEmpty(s.group)) { server_group[s.group] = 1; } } foreach (KeyValuePair <string, PortMapConfig> pair in portMap) { int key = 0; PortMapConfig pm = pair.Value; if (!pm.enable) { continue; } if (id2server.ContainsKey(pm.id) || server_group.ContainsKey(pm.id) || pm.id == null || pm.id.Length == 0) { } else { continue; } try { key = int.Parse(pair.Key); } catch (FormatException) { continue; } portMapCache[key] = new PortMapConfigCache { type = pm.type, id = pm.id, server = id2server.ContainsKey(pm.id) ? id2server[pm.id] : null, server_addr = pm.server_addr, server_port = pm.server_port }; } lock (serverStrategyMap) { List <int> remove_ports = new List <int>(); foreach (KeyValuePair <int, ServerSelectStrategy> pair in serverStrategyMap) { if (portMapCache.ContainsKey(pair.Key)) { continue; } remove_ports.Add(pair.Key); } foreach (int port in remove_ports) { serverStrategyMap.Remove(port); } if (!portMapCache.ContainsKey(localPort)) { serverStrategyMap.Remove(localPort); } } uricache.Clear(); }