Example #1
0
        /// <summary>
        /// List all users in specified conference room.
        /// </summary>
        /// <param name="userlist">User list </param>
        /// <param name="conf_id">conference room name caller want to query.</param>
        /// <returns>true if query succeed.</returns>
        public bool GetConferenceUserList(out List <ConferenceUser> userlist, string conf_id)
        {
            string cmd  = "";
            string resp = "";

            userlist = null;

            cmd  = string.Format("api conference {0} list", conf_id);
            resp = SendCommand(cmd);

            if (resp.IndexOf("-ERR") >= 0)
            {
                return(false);
            }

            //todo: parse conference list
            userlist = new List <ConferenceUser>();
            using (var reader = new StringReader(resp))
            {
                string line = "";
                line = reader.ReadLine();
                while (line != null)
                {
                    ConferenceUser user;
                    if (ConferenceUser.TryParse(out user, line))
                    {
                        userlist.Add(user);
                    }

                    line = reader.ReadLine();
                }
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// Parse ConferenceRoom struct by EventSocket responsed strings.
        /// </summary>
        /// <param name="room">parsed result</param>
        /// <param name="text">response string from EventSocket</param>
        /// <returns>parsing succeed or not?</returns>
        public static bool TryParse(out ConferenceRoom room, string text)
        {
            bool ok = false;

            room          = new ConferenceRoom();
            room.UserList = new List <ConferenceUser>();
            room.FlagList = new List <string>();
            try
            {
                using (var reader = new StringReader(text))
                {
                    string line  = reader.ReadLine();
                    var    match = Regex.Match(line, Pattern1);
                    if (match.Success)
                    {
                        room.ID        = match.Groups[1].Value;
                        room.VoiceRate = int.Parse(match.Groups[3].Value);
                        room.FlagList.AddRange(match.Groups[4].Value.Split('|'));

                        //read following lines by user counts
                        int count = int.Parse(match.Groups[2].Value);
                        for (int i = 0; i < count; i++)
                        {
                            line = reader.ReadLine();
                            ConferenceUser user;
                            if (ConferenceUser.TryParse(out user, line))
                            {
                                room.UserList.Add(user);
                            }
                        }
                        ok = true;
                    }
                }
            }
            catch (Exception ex)
            {
                ok = false;
            }

            return(ok);
        }