Exemple #1
0
 public void RemoveFrom(AddressAndPort from)
 {
     if (map.ContainsKey(from))
     {
         map.Remove(from);
     }
 }
Exemple #2
0
        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));
        }
Exemple #3
0
 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));
 }
Exemple #4
0
 public override bool Equals(object obj)
 {
     if (obj != null)
     {
         AddressAndPort other = (AddressAndPort)obj;
         return(this.ToString().Equals(other.ToString(), StringComparison.InvariantCultureIgnoreCase));
     }
     return(false);
 }
Exemple #5
0
 public void RemoveTo(AddressAndPort from, AddressAndPort to)
 {
     if (map.ContainsKey(from))
     {
         if (map[from].Item2.Contains(to))
         {
             map[from].Item2.Remove(to);
         }
     }
 }
Exemple #6
0
        public List <AddressAndPort> GetTo(AddressAndPort from)
        {
            List <AddressAndPort> tos = new List <AddressAndPort>();

            if (map.ContainsKey(from))
            {
                tos = map[from].Item2;
            }
            return(tos);
        }
Exemple #7
0
 public static bool ContainsPort(this List <AddressAndPort> list, AddressAndPort other)
 {
     foreach (AddressAndPort e in list)
     {
         if (e.Port == other.Port)
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #8
0
 public Tuple <int, List <AddressAndPort>, string> this[AddressAndPort from]
 {
     get
     {
         return(map[from]);
     }
     set
     {
         map[from] = value;
     }
 }
Exemple #9
0
 public SocketMap(AddressAndPort device, List <ClientSocket> clients)
 {
     this.device = device;
     if (clients != null)
     {
         this.clients = clients;
     }
     else
     {
         this.clients = new List <ClientSocket>();
     }
 }
Exemple #10
0
        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);
        }
Exemple #11
0
        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();
            }
        }
Exemple #12
0
 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);
         }
     }
 }
Exemple #13
0
 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);
             }
         }
     }
 }
Exemple #14
0
 public bool Exist(AddressAndPort from)
 {
     return(map.ContainsKey(from));
 }
Exemple #15
0
 public static string Parse(AddressAndPort ap)
 {
     return(ap.ToString());
 }
Exemple #16
0
 public string GetRemark(AddressAndPort from)
 {
     return(map[from].Item3);
 }
Exemple #17
0
 public SocketMap(AddressAndPort device)
 {
     this.device  = device;
     this.clients = new List <ClientSocket>();
 }