//登陆数据处理函数 public static void LandMessDeal(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()); //得到用户名和密码 JObject obj = JObject.Parse(jsonStr); if (obj["isLand"].ToString().Equals("True")) { //MessageBox.Show("登陆成功"); } else { MessageBox.Show("登陆失败"); MClientViewModel mClientViewModel = MClientViewModel.CreateInstance(); mClientViewModel.PassWord = ""; } }
public static void AddFriendRetMessage(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); JArray jArray = JArray.Parse(jsonStr); if (jArray[0]["isOk"].ToString().Equals("True")) { AddFriendViewModel addFriendViewModel = AddFriendViewModel.CreateInstance(); Console.WriteLine("显示模糊搜索到的用户信息"); FriendListViewModel friendListViewModel = FriendListViewModel.CreateInstance(); MClientViewModel mClientViewModel = MClientViewModel.CreateInstance(); foreach (var obj in jArray) { //如果这个用户已经是好友了,那么就继续看下一个 if (friendListViewModel.isFriendList(obj["Id"].ToString())) { continue; } //把自己的id也排除出去 if (mClientViewModel.UserName.Equals(obj["UserName"].ToString())) { continue; } FriendInfo friendInfo = new FriendInfo(); friendInfo.Id = obj["Id"].ToString(); friendInfo.FriendName = obj["UserName"].ToString(); //把搜索到的好友数据添加进去 Application.Current.Dispatcher.Invoke( new Action(() => { //更新查询到的好友信息 addFriendViewModel.FrienInfoGroup.Add(friendInfo); }) ); } } else { MessageBox.Show("没有查询到接近的用户"); } }
public static void RegisMessDeal(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()); //得到用户名和密码 JObject obj = JObject.Parse(jsonStr); if (obj["isRegist"].ToString().Equals("True")) { MessageBox.Show("注册成功"); //关闭注册窗口 MClientViewModel mClientViewModel = MClientViewModel.CreateInstance(); RegisterViewModel registerViewModel = RegisterViewModel.CreateInstance(); //重置输入框 registerViewModel.Resset(); //跨线程调用窗体组件的方法,使注册窗口关闭 mClientViewModel.registerWindow.Dispatcher.Invoke(new Action(() => { mClientViewModel.registerWindow.Close(); })); } else { MessageBox.Show("注册失败"); //清除掉密码 RegisterViewModel registerViewModel = RegisterViewModel.CreateInstance(); registerViewModel.PassWord = ""; registerViewModel.sPassWord = ""; } }
public MainWindow() { InitializeComponent(); this.DataContext = MClientViewModel.CreateInstance(); }