/// <summary> /// Parse ConferenceUser struct by EventSocket responsed strings. /// </summary> /// <param name="user">parsed result</param> /// <param name="text">response string from EventSocket</param> /// <returns>parsing succeed or not?</returns> public static bool TryParse(out ConferenceUser user, string text) { bool ok = false; //example of variable "text" //28;sofia/internal/[email protected];6d103bef-8bbe-4e4b-ad75-ff6bce2537a5;sip-1003;sip-1003;hear|speak;0;0;100 user = new ConferenceUser(); try { if (null != text) { var match = Regex.Match(text, Pattern1); if (match.Success) { user.ID = match.Groups[1].Value; user.EndPoint = match.Groups[2].Value; user.UUID = match.Groups[3].Value; user.SipID = match.Groups[5].Value; ok = true; } } } catch (Exception ex) { ok = false; } return(ok); }
/// <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); }
/// <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); }