Пример #1
0
        public static void ChangePassReturnMessage(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);

            if (obj["isOK"].ToString().Equals("True"))
            {
                MessageBox.Show("密码修改成功");
            }
            else
            {
                MessageBox.Show("密码修改失败");
            }
        }
Пример #2
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());
            })
                );
        }
Пример #3
0
        //更新好友状态
        public static void FriendStatusMessage(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);

            foreach (var obj in jArray)
            {
                //修改好友状态
                Application.Current.Dispatcher.Invoke(
                    new Action(() =>
                {
                    FriendListViewModel friendListViewModel = FriendListViewModel.CreateInstance();
                    try
                    {
                        FriendEntity.UpdateFriendStatus(friendListViewModel.friendGroups, obj["id"].ToString(), obj["Group"].ToString(), obj["Status"].ToString());
                    }
                    catch (Exception ex)
                    {
                        Console.Write(ex);
                    }
                })
                    );
            }
        }
Пример #4
0
        //处理好友请求消息
        public static void FriendRequestMessageDeal(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.SaveFriendRequestInfo(obj["id"].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());
                }
            }
        }
Пример #5
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());
            })
                );
        }
Пример #6
0
        public static void UserMessageDeal(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"))
            {
                Console.WriteLine("保存用户消息");

                foreach (var obj in jArray)
                {
                    SqliteConnect.SaveMessage(obj["FriendId"].ToString(), obj["Message"].ToString(), obj["MessageDate"].ToString());
                }
            }
        }
Пример #7
0
        //登陆数据处理函数
        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 = "";
            }
        }
Пример #8
0
 public static MClient CreateInstance(String ip, String port)
 {
     if (mClient == null)
     {
         Console.WriteLine("mClient创建开始");
         mClient = new MClient(ip, port);
         Console.WriteLine("mClient创建完毕");
     }
     return(mClient);
 }
Пример #9
0
        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("没有查询到接近的用户");
            }
        }
Пример #10
0
        public static void UserInfoDeal(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);
            Console.WriteLine("清除receiveBuffer中的数据 , token.packageLen = " + token.packageLen);
            //list要先转换成数组,再转换成字符串
            String jsonStr = Encoding.Default.GetString(onePackage.ToArray());
            //得到用户名和密码
            JObject obj = JObject.Parse(jsonStr);

            //如果传回来的用户信息是正确的
            if (obj["isOk"].ToString().Equals("True"))
            {
                Console.WriteLine("保存自己的信息");
                //先初始化数据库的静态变量(这里是用id合成数据库名)
                SqliteConnect.SqliteInit(obj["id"].ToString());
                //然后创建好友表和信息表(如果有,不会重复创建)
                SqliteConnect.CreateTable();
                //保存自己的最新信息到数据库
                SqliteConnect.SaveUserInfo(obj["id"].ToString(), obj["UserName"].ToString(), obj["RealName"].ToString(), obj["Sex"].ToString(),
                                           obj["BirthDay"].ToString(), obj["Address"].ToString(), obj["Email"].ToString(), obj["PhoneNumber"].ToString(),
                                           obj["Remark"].ToString());

                //主窗口隐藏
                Application.Current.Dispatcher.Invoke(new Action(() => { Application.Current.MainWindow.Hide(); }));
                //打开好友界面
                Application.Current.Dispatcher.Invoke(new Action(() => {
                    FriendListWindow friedListWindow = new FriendListWindow();
                    friedListWindow.Show();
                }));
            }
            else
            {
                MessageBox.Show("用户信息返回失败");
            }
        }
Пример #11
0
        public static void FriendInfoDeal(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("保存好友信息");

                //保存还没有更新前的时间,如果时间比这个时间还晚,说明是已经被删除的好友
                String updatetime = DateTime.Now.ToString();

                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());
                }

                //在保存完好友信息后,就要根据更新时间对数据库表中的数据进行排查,删除掉这一次还没有更新的数据
                SqliteConnect.DeleteFriendByTime(updatetime);
            }
            else
            {
                //如果不进行这个补充,那么在只有一个好友,且服务端已经删除这个好友的情况下,客户端本地的该好友不会被删除
                String updatetime = DateTime.Now.ToString();
                SqliteConnect.DeleteFriendByTime(updatetime);
            }
        }
Пример #12
0
        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 = "";
            }
        }