public void RemoveFrom(AddressAndPort from) { if (map.ContainsKey(from)) { map.Remove(from); } }
public AddressMap(int id, AddressAndPort from, AddressAndPort to, string remark) { map = new Dictionary <AddressAndPort, Tuple <int, List <AddressAndPort>, string> >(); List <AddressAndPort> tos = new List <AddressAndPort>(); tos.Add(to); map.Add(from, new Tuple <int, List <AddressAndPort>, string>(id, tos, remark)); }
public void Update(int id, AddressAndPort from, List <AddressAndPort> to, string remark) { if (map.ContainsKey(from)) { map.Remove(from); } map.Add(from, new Tuple <int, List <AddressAndPort>, string>(id, to, remark)); }
public override bool Equals(object obj) { if (obj != null) { AddressAndPort other = (AddressAndPort)obj; return(this.ToString().Equals(other.ToString(), StringComparison.InvariantCultureIgnoreCase)); } return(false); }
public void RemoveTo(AddressAndPort from, AddressAndPort to) { if (map.ContainsKey(from)) { if (map[from].Item2.Contains(to)) { map[from].Item2.Remove(to); } } }
public List <AddressAndPort> GetTo(AddressAndPort from) { List <AddressAndPort> tos = new List <AddressAndPort>(); if (map.ContainsKey(from)) { tos = map[from].Item2; } return(tos); }
public static bool ContainsPort(this List <AddressAndPort> list, AddressAndPort other) { foreach (AddressAndPort e in list) { if (e.Port == other.Port) { return(true); } } return(false); }
public Tuple <int, List <AddressAndPort>, string> this[AddressAndPort from] { get { return(map[from]); } set { map[from] = value; } }
public SocketMap(AddressAndPort device, List <ClientSocket> clients) { this.device = device; if (clients != null) { this.clients = clients; } else { this.clients = new List <ClientSocket>(); } }
public List <AddressAndPort> GetFrom(AddressAndPort to) { List <AddressAndPort> froms = new List <AddressAndPort>(); foreach (AddressAndPort ap in map.Keys) { if (map[ap].Item2.Contains(to)) { froms.Add(ap); } } return(froms); }
public static void LoadMap() { //if (!init) // throw new ApplicationException("尚未连接数据库,请先调用InitDB方法来初始化映射管理器!"); string connString = ConfigurationManager.ConnectionStrings["connString"].ConnectionString; SqlConnectionStringBuilder scsb = new SqlConnectionStringBuilder(connString); if (!MapManager.Init) { MapManager.InitDB(scsb.InitialCatalog, scsb.DataSource, scsb.UserID, scsb.Password); } if (map == null) { map = new AddressMap(); } try { if (conn.State != ConnectionState.Open) { conn.Open(); } using (SqlCommand cmd = new SqlCommand("select [From],[To],[ID],[Remark] from [" + tablename + "]", conn)) { SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); if (reader.HasRows) { while (reader.Read()) { string from = reader.GetString(0); string to = reader.GetString(1); int id = reader.GetInt32(2); string remark = reader.GetString(3); AddressAndPort From = ParseFrom(from); List <AddressAndPort> To = ParseTo(to); Tuple <int, List <AddressAndPort>, string> Tos = new Tuple <int, List <AddressAndPort>, string>(id, To, remark); if (!map.Exist(From)) { map.Add(From, Tos); } } } } } finally { conn.Close(); } }
public void Add(int id, AddressAndPort from, AddressAndPort to, string remark) { if (!map.ContainsKey(from)) { List <AddressAndPort> tos = new List <AddressAndPort>(); tos.Add(to); map.Add(from, new Tuple <int, List <AddressAndPort>, string>(id, tos, remark)); } else { if (!map[from].Item2.Contains(to)) { map[from].Item2.Add(to); } } }
public void Add(AddressAndPort from, Tuple <int, List <AddressAndPort>, string> to) { if (!map.ContainsKey(from)) { map.Add(from, to); } else { foreach (AddressAndPort ap in to.Item2) { if (!map[from].Item2.Contains(ap)) { map[from].Item2.Add(ap); } } } }
public bool Exist(AddressAndPort from) { return(map.ContainsKey(from)); }
public static string Parse(AddressAndPort ap) { return(ap.ToString()); }
public string GetRemark(AddressAndPort from) { return(map[from].Item3); }
public SocketMap(AddressAndPort device) { this.device = device; this.clients = new List <ClientSocket>(); }