static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Dispatcher dispatcher = Dispatcher.CurrentDispatcher; KevRegister.Add(ClientItemsPrimaryKey.Dispatcher_MainThread, dispatcher); MainForm mainForm = new MainForm(); KevRegister.Add(ClientItemsPrimaryKey.Form_Main, mainForm); LoginSocketDelegate loginSocketDelegate = new LoginSocketDelegate(); loginSocketDelegate.MainForm = mainForm; UDPClientRouteHelper.GetInstanse().SetDelegate(loginSocketDelegate); UDPClientRouteHelper.GetInstanse().SetDelegate(new GetUserInfoSocketDelegate()); UDPClientRouteHelper.GetInstanse().SetDelegate(new NewUserLoginSocketDelegate()); UDPClientRouteHelper.GetInstanse().SetDelegate(new GetUserFriendListSocketDelegate()); UDPClientRouteHelper.GetInstanse().SetDelegate(new ChatTextMessageSocketDelegate()); Application.Run(mainForm); }
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); }