コード例 #1
0
        public static void DeleteFriendMessage(SocketAsyncEventArgs e)
        {
            MClient        mClient = MClient.CreateInstance();
            AsyncUserToken token   = (AsyncUserToken)e.UserToken;
            //得到一个完整的包的数据,放入新list,第二个参数是数据长度,所以要减去8
            List <byte> onePackage = token.receiveBuffer.GetRange(8, token.packageLen - 8);

            //将复制出来的数据从receiveBuffer旧list中删除
            token.receiveBuffer.RemoveRange(0, token.packageLen);
            //list要先转换成数组,再转换成字符串
            String jsonStr = Encoding.Default.GetString(onePackage.ToArray());

            //得到用户名和密码
            Console.WriteLine("jsonStr = " + jsonStr);
            JObject obj = JObject.Parse(jsonStr);

            //先从数据库中删除
            SqliteConnect.DeleteFriendById(obj["Id"].ToString());
            //然后从好友队列中删除
            Application.Current.Dispatcher.Invoke(
                new Action(() =>
            {
                FriendListViewModel friendListViewModel = FriendListViewModel.CreateInstance();
                FriendEntity.InGroupListDelete(friendListViewModel.friendGroups, obj["Id"].ToString());
            })
                );
        }
コード例 #2
0
        public static void ChangeGroupMessage(SocketAsyncEventArgs e)
        {
            MClient        mClient = MClient.CreateInstance();
            AsyncUserToken token   = (AsyncUserToken)e.UserToken;
            //得到一个完整的包的数据,放入新list,第二个参数是数据长度,所以要减去8
            List <byte> onePackage = token.receiveBuffer.GetRange(8, token.packageLen - 8);

            //将复制出来的数据从receiveBuffer旧list中删除
            token.receiveBuffer.RemoveRange(0, token.packageLen);
            //list要先转换成数组,再转换成字符串
            String jsonStr = Encoding.Default.GetString(onePackage.ToArray());
            //得到用户名和密码
            JArray jArray = JArray.Parse(jsonStr);

            //先保存好友信息
            if (jArray[0]["isOk"].ToString().Equals("True"))
            {
                Console.WriteLine("保存好友信息");

                foreach (var obj in jArray)
                {
                    SqliteConnect.SaveFriendInfo(obj["id"].ToString(), obj["Group"].ToString(), obj["UserName"].ToString(), obj["RealName"].ToString(), obj["Sex"].ToString(),
                                                 obj["BirthDay"].ToString(), obj["Address"].ToString(), obj["Email"].ToString(), obj["PhoneNumber"].ToString(),
                                                 obj["Remarks"].ToString());
                }
            }
            //然后删除原分组List中的好友
            Application.Current.Dispatcher.Invoke(
                new Action(() =>
            {
                FriendListViewModel friendListViewModel = FriendListViewModel.CreateInstance();
                FriendEntity.InGroupListDelete(friendListViewModel.friendGroups, jArray[0]["id"].ToString());
            })
                );
        }