Пример #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 void DeleteFriend(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("删除该好友?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question);

            if (MessageBoxResult.OK == result)
            {
                //进行删除好友的操作
                //将删除好友的信息发送给服务端,由服务端同时删除用户和好友的好友表中的对应ID
                JObject obj = new JObject();
                obj["Id"] = this.Id;
                String  str     = obj.ToString();
                MClient mClient = MClient.CreateInstance();
                mClient.SendDeleteFriend(str);
                //同时客户端本地将该好友从队列中删除
                SqliteConnect.DeleteFriendById(this.Id);
                //然后从好友队列中删除
                Application.Current.Dispatcher.Invoke(
                    new Action(() =>
                {
                    FriendListViewModel friendListViewModel = FriendListViewModel.CreateInstance();
                    FriendEntity.InGroupListDelete(friendListViewModel.friendGroups, this.Id);
                })
                    );
            }
        }