/// <summary> /// 获取群列表 /// </summary> /// <returns>获取成功返回 <see cref="List{Group}"/>, 失败返回 null</returns> public List <Model.GroupInfo> GetGroupList() { string result = CQP.CQ_getGroupList(_authCode).ToString(Encoding.ASCII); if (string.IsNullOrEmpty(result)) { return(null); } List <Model.GroupInfo> groups = new List <Model.GroupInfo> (); #region --其他_转换_文本到群列表信息a-- using (BinaryReader binary = new BinaryReader(new MemoryStream(Convert.FromBase64String(result)))) { for (int i = 0, len = binary.ReadInt32_Ex(); i < len; i++) { if (binary.Length() <= 0) { return(null); } #region --其他_转换_ansihex到群信息-- using (BinaryReader tempBinary = new BinaryReader(new MemoryStream(binary.ReadToken_Ex()))) { Model.GroupInfo group = new Model.GroupInfo(); group.Id = tempBinary.ReadInt64_Ex(); group.Name = tempBinary.ReadString_Ex(_defaultEncoding); group.CurrentNumber = tempBinary.ReadInt32_Ex(); group.MaximumNumber = tempBinary.ReadInt32_Ex(); groups.Add(group); } #endregion } return(groups); } #endregion }
/// <summary> /// 获取群列表 /// </summary> /// <param name="groups"></param> /// <returns></returns> public int GetGroupList(out List <Group> groups) { string result = CQP.CQ_getGroupList(_authCode); if (string.IsNullOrEmpty(result)) { groups = null; return(-1000); } groups = new List <Group> (); #region --其他_转换_文本到群列表信息a-- UnPack unpack = new UnPack(Convert.FromBase64String(result)); for (int i = 0, len = unpack.GetInt32(); i < len; i++) { if (unpack.OverLength <= 0) { groups = null; return(-1000); } #region --其他_转换_ansihex到群信息-- UnPack temp = new UnPack(unpack.GetToken()); Group group = new Group(); group.Id = temp.GetInt64(); group.Name = temp.GetString(Encoding.GetEncoding("GB18030")); groups.Add(group); #endregion } #endregion return(0); }
/// <summary> /// 获取群列表 /// </summary> /// <param name="groups">返回的群列表</param> /// <returns></returns> public int GetGroupList(out List <Group> groups) { string result = CQP.CQ_getGroupList(_authCode); if (string.IsNullOrEmpty(result)) { groups = null; return(-1000); } groups = new List <Group> (); #region --其他_转换_文本到群列表信息a-- BinaryReader binary = new BinaryReader(new MemoryStream(Convert.FromBase64String(result))); for (int i = 0, len = binary.ReadInt32_Ex(); i < len; i++) { if (binary.Length() <= 0) { groups = null; return(-1000); } #region --其他_转换_ansihex到群信息-- BinaryReader tempBinary = new BinaryReader(new MemoryStream(binary.ReadToken_Ex())); Group group = new Group(); group.Id = tempBinary.ReadInt64_Ex(); group.Name = tempBinary.ReadString_Ex(_defaultEncoding); groups.Add(group); #endregion } #endregion return(0); }
/// <summary> /// 获取群列表 /// </summary> /// <exception cref="InvalidDataException">数据流格式错误或为 null</exception> /// <exception cref="EndOfStreamException">无法读取数据, 因为已读取到数据流末尾</exception> /// <returns>获取成功返回 <see cref="GroupInfoCollection"/> 对象, 失败返回 <see langword="null"/></returns> public GroupInfoCollection GetGroupList() { string data = CQP.CQ_getGroupList(this.AppInfo.AuthCode).ToString(CQApi.DefaultEncoding); if (string.IsNullOrEmpty(data)) { #if DEBUG throw new InvalidDataException("获取的数据流格式无效"); #else return(null); #endif } try { return(new GroupInfoCollection(this, data)); } catch { #if DEBUG throw; #else return(null); #endif } }