public int HandleResponseMessage(UDPModel uModel) { KevSocketModel ksModel = JsonHelper.ParseFromJson <KevSocketModel>(uModel); if (ksModel == null) { return(ResponseCode.AnalyticalDataError); } if (ksModel.ResponseCode != ResponseCode.Success) { KevRegister.Get <Dispatcher>(ClientItemsPrimaryKey.Dispatcher_MainThread).Invoke(() => { KevRegister.Get <HomeForm>(ClientItemsPrimaryKey.Form_Home).label_status.Text = ResponseCode.GetDescription(ksModel.ResponseCode); }); } return(ResponseCode.Success); }
/// <summary> /// 抛出异常. /// </summary> /// <param name="code">Code.</param> /// <param name="messages">Messages.</param> /// <returns>Friendly Exception.</returns> public static FriendlyException ThrowException(ResponseCode code, params string[] messages) { return(ThrowException(code.GetHashCode(), code.GetDescription(), messages)); }
public int HandleResponseMessage(UDPModel uModel) { KevSocketModel <UserInfoModel> userInfoModel = JsonHelper.ParseFromJson <KevSocketModel <UserInfoModel> >(uModel.Body, uModel.Length); if (userInfoModel == null) { return(ResponseCode.AnalyticalDataError); } if (userInfoModel.ResponseCode != ResponseCode.Success) { KevRegister.Get <Dispatcher>(ClientItemsPrimaryKey.Dispatcher_MainThread).Invoke(() => { KevRegister.Get <HomeForm>(ClientItemsPrimaryKey.Form_Home).label_status.Text = ResponseCode.GetDescription(userInfoModel.ResponseCode); }); return(ResponseCode.NetworkHostError); } if (userInfoModel.Data == null) { return(ResponseCode.AnalyticalDataError); } KevRegister.Get <Dispatcher>(ClientItemsPrimaryKey.Dispatcher_MainThread).Invoke(() => { HomeForm homeForm = KevRegister.Get <HomeForm>(ClientItemsPrimaryKey.Form_Home); homeForm.label_nickName.Text = userInfoModel.Data.NickName; homeForm.label_signature.Text = userInfoModel.Data.Signature; }); return(ResponseCode.Success); }
public int HandleResponseMessage(UDPModel uModel) { KevSocketModel <IEnumerable <UserInfoModel> > ksModel = JsonHelper.ParseFromJson <KevSocketModel <IEnumerable <UserInfoModel> > >(uModel); if (ksModel == null) { return(ResponseCode.AnalyticalDataError); } if (ksModel.ResponseCode != ResponseCode.Success) { KevRegister.Get <Dispatcher>(ClientItemsPrimaryKey.Dispatcher_MainThread).Invoke(() => { KevRegister.Get <HomeForm>(ClientItemsPrimaryKey.Form_Home).label_status.Text = ResponseCode.GetDescription(ksModel.ResponseCode); }); return(ResponseCode.Error); } if (ksModel.Data == null) { return(ResponseCode.AnalyticalDataError); } KevRegister.Get <Dispatcher>(ClientItemsPrimaryKey.Dispatcher_MainThread).Invoke(() => { KevRegister.Get <HomeForm>(ClientItemsPrimaryKey.Form_Home).AddUserRange(ksModel.Data); foreach (UserInfoModel item in ksModel.Data) { UserCache.Updata(item); } }); return(ResponseCode.Success); }
public int HandleResponseMessage(UDPModel uModel) { //判断数据 KevSocketModel <long> ksModel = JsonHelper.ParseFromJson <KevSocketModel <long> >(uModel.Body, uModel.Length); if (ksModel == null) { return(ResponseCode.NotFindKevSocketModel); } //处理相关的逻辑然后进行跳转 Dispatcher dispatcher = KevRegister.Get <Dispatcher>(ClientItemsPrimaryKey.Dispatcher_MainThread); MainForm mainForm = KevRegister.Get <MainForm>(ClientItemsPrimaryKey.Form_Main); if (ksModel.ResponseCode == ResponseCode.Success) { dispatcher.Invoke(() => { if (mainForm != null) { mainForm.Hide(); } //替换本机的Id KevRegister.Add <long>(UDPPrimaryKey.Client_ThisDeviceId, ksModel.Data); KevRegister.Get <HomeForm>(ClientItemsPrimaryKey.Form_Home, () => { return(new HomeForm()); }).Show(); }); //请求本机资料 KevSocketModel ksModel_requestSelfUserInfo = new KevSocketModel { DeviceId = KevRegister.Get <long>(UDPPrimaryKey.Client_ThisDeviceId, -1), MessageId = IdGenerator.NextId(), MessageType = MessageType.GetUserInfo, NetworkType = NetworkType.Request }; UDPClient udpClient = KevRegister.Get <UDPClient>(ClientItemsPrimaryKey.Socket_UDPClient); if (!udpClient.SendMessage(ksModel_requestSelfUserInfo)) { KevRegister.Get <HomeForm>(ClientItemsPrimaryKey.Form_Home).label_status.Text = "请求自己的资料失败"; } //获取已经登录的人 KevSocketModel ksModel_getFriendList = new KevSocketModel { DeviceId = KevRegister.Get <long>(UDPPrimaryKey.Client_ThisDeviceId, -1), MessageId = IdGenerator.NextId(), MessageType = MessageType.GetUserFriendList, NetworkType = NetworkType.Request }; udpClient.SendMessage(ksModel_getFriendList); } else { dispatcher.Invoke(() => { mainForm.ShowAPrompt(ResponseCode.GetDescription(ksModel.ResponseCode)); }); } return(ResponseCode.NoResponse); }