Exemplo n.º 1
0
        internal static ClientInfo[] Parse(string input)
        {
            if (input == null)
            {
                return(null);
            }

            var clients = new List <ClientInfo>();

            using (var reader = new StringReader(input))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    var client = new ClientInfo();
                    client.Raw = line;
                    string[] tokens = line.Split(StringSplits.Space);
                    for (int i = 0; i < tokens.Length; i++)
                    {
                        string tok = tokens[i];
                        int    idx = tok.IndexOf('=');
                        if (idx < 0)
                        {
                            continue;
                        }
                        string key = tok.Substring(0, idx), value = tok.Substring(idx + 1);

                        switch (key)
                        {
                        case "addr": client.Address = Format.TryParseEndPoint(value); break;

                        case "age": client.AgeSeconds = Format.ParseInt32(value); break;

                        case "idle": client.IdleSeconds = Format.ParseInt32(value); break;

                        case "db": client.Database = Format.ParseInt32(value); break;

                        case "name": client.Name = value; break;

                        case "sub": client.SubscriptionCount = Format.ParseInt32(value); break;

                        case "psub": client.PatternSubscriptionCount = Format.ParseInt32(value); break;

                        case "multi": client.TransactionCommandLength = Format.ParseInt32(value); break;

                        case "cmd": client.LastCommand = value; break;

                        case "flags":
                            client.FlagsRaw = value;
                            ClientFlags flags = ClientFlags.None;
                            AddFlag(ref flags, value, ClientFlags.SlaveMonitor, 'O');
                            AddFlag(ref flags, value, ClientFlags.Slave, 'S');
                            AddFlag(ref flags, value, ClientFlags.Master, 'M');
                            AddFlag(ref flags, value, ClientFlags.Transaction, 'x');
                            AddFlag(ref flags, value, ClientFlags.Blocked, 'b');
                            AddFlag(ref flags, value, ClientFlags.TransactionDoomed, 'd');
                            AddFlag(ref flags, value, ClientFlags.Closing, 'c');
                            AddFlag(ref flags, value, ClientFlags.Unblocked, 'u');
                            AddFlag(ref flags, value, ClientFlags.CloseASAP, 'A');
                            client.Flags = flags;
                            break;

                        case "id": client.Id = Format.ParseInt64(value); break;
                        }
                    }
                    clients.Add(client);
                }
            }

            return(clients.ToArray());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Format the object as a string
        /// </summary>
        public override string ToString()
        {
            string addr = Format.ToString(Address);

            return(string.IsNullOrWhiteSpace(Name) ? addr : (addr + " - " + Name));
        }