/// <summary>
 /// 
 /// </summary>
 /// <param name="serverList"></param>
 /// <returns></returns>
 public static ArrayList GetAllItems(ArrayList serverList)
 {
     ArrayList itemarr = new ArrayList();
     ArrayList arr = MemCachedManager.GetStats(serverList, MemCachedManager.Stats.Items, null);
     int host = Convert.ToInt32(serverList[0].ToString().Split(':')[1]);
     if (arr == null)
     {
         return null;
     }
     foreach (string a in arr)
     {
         string[] tmparr = a.Split(':');
         if (tmparr.Length > 1)
         {
             int item_id = 0;
             int.TryParse(tmparr[1], out item_id);
             bool find = false;
             foreach (int item in itemarr)
             {
                 if (item == item_id)
                     find = true;
             }
             if (!find && item_id > 0 && item_id != host)
                 itemarr.Add(item_id);
         }
     }
     return itemarr;
 }
Beispiel #2
0
    public void Process()
    {
        string    path      = frm.BackPath;
        string    IndexPath = frm.BackPath;//文件索引地址
        string    filePath  = "";
        ArrayList cachearr  = MemCachedManager.GetStats(arrayList, MemCachedManager.Stats.CachedDump, "" + number + " 0");

        if (cachearr.Count > 0)
        {
            IndexPath = path + "\\" + number + "\\" + number;
            for (var i = 0; i < cachearr.Count; i++)
            {
                path = frm.BackPath;
                path = path + "\\" + number + "\\" + help.count;
                string key   = cachearr[i].ToString().Split(':')[0];
                object value = MemcachedTools.Get(key);
                if (value != null && value.ToString() != "")
                {
                    filePath = path + "\\" + key + ".txt";
                    frm.WriteFile(key, value.ToString(), help.totalNum, number, path, filePath, IndexPath);
                    help.totalNum++;
                    help.num++;
                    if (help.num == 1000)
                    {
                        help.count++;
                        help.num = 0;
                    }
                    filePath = "";
                }
            }
            frm.WriteState("Item " + number + " 备份数据完成,总共写入文件" + help.totalNum + "个!");
            thread.Abort();
        }
    }
Beispiel #3
0
        private void GetItems()
        {
            ArrayList itemarr = new ArrayList();
            ArrayList arr = null;
            StringBuilder sb = new StringBuilder();
            try
            {
                arr = MemCachedManager.GetStats(serverList, MemCachedManager.Stats.Items, null);
                if (arr.Count == 0)
                {
                    this.frm.备份ToolStripMenuItem1.Enabled = true;
                    this.frm.还原ToolStripMenuItem.Enabled = true;
                    WriteState("没有找到数据!");
                    return;
                }
                if (arr == null)
                {
                    WriteState("连接服务器异常!");
                    return;
                }
            }
            catch (Exception ex)
            {
                WriteState(ex.Message.ToString());
            }

            foreach (string a in arr)
            {
                string[] tmparr = a.Split(':');
                if (tmparr.Length > 1)
                {
                    int item_id = 0;
                    int.TryParse(tmparr[1], out item_id);

                    bool find = false;
                    foreach (int item in itemarr)
                    {
                        if (item == item_id)
                            find = true;
                    }
                    if (!find && item_id > 0 && item_id != 11211)
                        itemarr.Add(item_id);
                }
            }
            WriteState("获取Item 成功" + itemarr.Count + "个Item!");
            foreach (int item in itemarr)
            {
                WorkThread wt = null;
                wt = new WorkThread(item, new Help(0, 1, 0, true));
                wt.frm = this;
                wt.arrayList = serverList;
                dic.Add(item, wt);
                wt.Run();
            }
        }
 /// <summary>
 /// 获取一个ItemKey
 /// </summary>
 /// <param name="serverList">MemCache服务器</param>
 /// <param name="item">Item</param>
 /// <param name="count">个数,0表示所有</param>
 /// <returns></returns>
 public static List<string> GetOneItemKey(ArrayList serverList, int item, int count)
 {
     List<string> allKeys = new List<string>();
     ArrayList itemKey = MemCachedManager.GetStats(serverList, MemCachedManager.Stats.CachedDump, "" + item + " " + count + "");
     foreach (string key in itemKey)
     {
         if (key == serverList[0].ToString())
             continue;
         allKeys.Add(key.Split(':')[0]);
     }
     return allKeys;
 }
Beispiel #5
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            ArrayList serverList  = new ArrayList();
            string    ip          = this.txtIp.Text;
            string    port        = this.txtport.Text;
            string    servername  = this.txtServerName.Text;
            string    serverDescr = this.txtServerDescr.Text;
            string    serverId    = ip + ":" + port;
            string    valid       = this.rdoYes.Checked ? "1" : "0";
            int       rs          = 0;
            string    sql         = string.Empty;

            serverList.Add(serverId);
            string xmlpath = Application.StartupPath + @"\MemServerInfo.xml";

            if (MemServer.GetServerList().Count > 0)
            {
                try
                {
                    ArrayList arrlist = MemCachedManager.GetStats(serverList, MemCachedManager.Stats.Detail, null);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("MemCache服务器验证失败!" + ex.Message.ToString(), "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }
            MemServer mem = new MemServer(xmlpath);

            if (string.IsNullOrEmpty(serverid))
            {
                if (IsExistsServerId(serverId))
                {
                    MessageBox.Show("已存在该服务器,请重新输入!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                mem.Add(serverId, servername, "1", serverDescr);
                //sql = "Insert Into tb_MemServer('ServerID','ServerName','ServerDescr','UpdateTime','Valid') values('" + serverId + "','" + servername + "','" + serverDescr + "','" + DateTime.Now + "','1')";
                //rs = SQLiteHelper.ExecuteNonQuery(CommandType.Text, sql, null);
            }
            else
            {
                mem.Modify(serverId, servername, "1", serverDescr);
                // sql = "Update tb_MemServer set ServerID='" + serverId + "',ServerName='" + servername + "',ServerDescr='" + serverDescr + "',UpdateTime='" + DateTime.Now + "',valid='" + valid + "' where ServerID='" + serverid + "'";mem.Add(serverId, servername, serverDescr,"1");
                //rs = SQLiteHelper.ExecuteNonQuery(CommandType.Text, sql, null);
            }
            //if (rs >= 0)
            Clear();
            BindServer();
            frm.BindMemServer();
        }
Beispiel #6
0
        public void GetBackUpItems(out int count)
        {
            count = -1;
            ArrayList itemarr = new ArrayList();
            ArrayList arr     = MemCachedManager.GetStats(serverList, MemCachedManager.Stats.Items, null);

            if (arr == null)
            {
                count = -1;
                return;
            }
            foreach (string a in arr)
            {
                string[] tmparr = a.Split(':');
                if (tmparr.Length > 1)
                {
                    int item_id = 0;
                    int.TryParse(tmparr[1], out item_id);
                    bool find = false;
                    foreach (int item in itemarr)
                    {
                        if (item == item_id)
                        {
                            find = true;
                        }
                    }
                    if (!find && item_id > 0 && item_id != 11211)
                    {
                        itemarr.Add(item_id);
                    }
                }
            }
            int total = 0;

            foreach (int item in itemarr)
            {
                WriteState("正在获取Item" + item + " 数据!");
                ArrayList cachearr = MemCachedManager.GetStats(serverList, MemCachedManager.Stats.CachedDump, "" + item + " 0");
                WriteState("获取Item" + item + " 数据" + cachearr.Count + "条!");
                total += cachearr.Count;
                if (total > MemchcheCount)
                {
                    WriteState("Memcache 已有超过 " + MemchcheCount + " 数据项!不恢复操作");
                    count = total;
                    return;
                }
            }
            WriteState("获取Item 成功" + itemarr.Count + "个Item");
            count = total;
        }
 public static int GetTotalCountBySlab(ArrayList serverList, int item)
 {
     ArrayList items = MemCachedManager.GetStats(serverList, MemCachedManager.Stats.CachedDump, "" + item + " 0");
     return items.Count;
 }
 /// <summary>
 /// 获取MemCache 详细信息
 /// </summary>
 /// <param name="serverList"></param>
 /// <returns></returns>
 public static ArrayList GetMemServerDetials(ArrayList serverList)
 {
     ArrayList arrlist = MemCachedManager.GetStats(serverList, MemCachedManager.Stats.Detail, null);
     return arrlist;
 }