Exemplo n.º 1
0
 public void CheckMemServerState()
 {
     while (true)
     {
         List <MemServer>  allServer = MemServer.GetAllValidServer();
         List <IPEndPoint> list      = new List <IPEndPoint>();
         if (allServer == null)
         {
             return;
         }
         string ip   = string.Empty;
         int    port = 0;
         foreach (var s in allServer)
         {
             ip   = s.ServerID.Split(':')[0];
             port = Convert.ToInt32(s.ServerID.Split(':')[1]);
             list.Add(new IPEndPoint(IPAddress.Parse(ip), port));
         }
         MemcachedMonitor            monitor    = new MemcachedMonitor(list);
         List <MemcachedServerStats> resultList = monitor.GetAllServerStats();
         string result   = string.Empty;
         string toUser   = string.Empty;
         string copyUser = string.Empty;
         string errIp    = string.Empty;
         string serverId = string.Empty;
         int    errPort  = 0;
         string content  = "MemCache 服务器{0}在{1} 检测连接失败,请远程登录查看!";
         foreach (MemcachedServerStats stats in resultList)
         {
             errIp    = stats.IPEndPoint.Address.ToString();
             errPort  = stats.IPEndPoint.Port;
             serverId = errIp + ":" + errPort;
             if (!stats.IsReachable)
             {
                 GetMailUser(serverId, out toUser, out copyUser);
                 //发送邮件
                 WriteState(serverId + "测试连接失败,正在发送邮件!");
                 MailHelper.SendEmail(toUser, copyUser, serverId + "检测连接失败", string.Format(content, serverId, DateTime.Now));
                 WriteState(serverId + "发送邮件成功!");
             }
             else
             {
                 WriteState(serverId + "测试连接成功!");
             }
         }
         Thread.Sleep(sleep);
         WriteState("消息:");
     }
 }
Exemplo n.º 2
0
 public void BindMemServer()
 {
     list = MemServer.GetServerList();
     this.cbMemServer.DisplayMember = "ServerName";
     this.cbMemServer.ValueMember   = "ServerID";
     this.cbMemServer.DataSource    = list;
     if (list != null && list.Count > 0)
     {
         serverList = new ArrayList();
         serverList.Add(this.cbMemServer.SelectedValue.ToString());
         TabControlBind(this.tabControl1.SelectedIndex.ToString());
         this.tabControl1.Enabled         = true;
         this.工具ToolStripMenuItem.Enabled = true;
     }
     else
     {
         MessageBox.Show("请先添加服务器,再进行其他操作!");
         this.tabControl1.Enabled         = false;
         this.工具ToolStripMenuItem.Enabled = false;
         new frmServer(this).Show();
     }
 }