コード例 #1
0
ファイル: Memcached.cs プロジェクト: yhhno/Adhesive
        internal static Dictionary<string, object> GetCurrentStatus(string url)
        {
            if (url.Split(':').Length != 2) return null;
            string ip = url.Split(':')[0];
            int port;
            if (string.IsNullOrWhiteSpace(ip) || !int.TryParse(url.Split(':')[1], out port))
                return null;

            var data = new Dictionary<string, object>();
            using (MemcachedSocket s = new MemcachedSocket(new IPEndPoint(IPAddress.Parse(ip), port)))
            {
                var raw = s.GetStats();
                foreach (var item in items)
                {
                    if (raw.ContainsKey(item.Key))
                    {
                        if (item.Value.ItemValueType == ItemValueType.TextValue)
                        {
                            data.Add(item.Key, raw[item.Key]);
                        }
                        else if (item.Value.ItemValueType == ItemValueType.StateValue || item.Value.ItemValueType == ItemValueType.TotalValue)
                        {
                            long val = 0;
                            if (long.TryParse(raw[item.Key], out val))
                            {
                                data.Add(item.Key, val);
                            }
                        }
                    }
                }
            }
            return data;
        }
コード例 #2
0
        internal static Dictionary <string, object> GetCurrentStatus(string url)
        {
            if (url.Split(':').Length != 2)
            {
                return(null);
            }
            string ip = url.Split(':')[0];
            int    port;

            if (string.IsNullOrWhiteSpace(ip) || !int.TryParse(url.Split(':')[1], out port))
            {
                return(null);
            }

            var data = new Dictionary <string, object>();

            using (MemcachedSocket s = new MemcachedSocket(new IPEndPoint(IPAddress.Parse(ip), port)))
            {
                var raw = s.GetStats();
                foreach (var item in items)
                {
                    if (raw.ContainsKey(item.Key))
                    {
                        if (item.Value.ItemValueType == ItemValueType.TextValue)
                        {
                            data.Add(item.Key, raw[item.Key]);
                        }
                        else if (item.Value.ItemValueType == ItemValueType.StateValue || item.Value.ItemValueType == ItemValueType.TotalValue)
                        {
                            long val = 0;
                            if (long.TryParse(raw[item.Key], out val))
                            {
                                data.Add(item.Key, val);
                            }
                        }
                    }
                }
            }
            return(data);
        }