/// <summary> /// 连接服务器异步回调 /// </summary> /// <param name="message">发送的信息</param> public void ConnectCallBackF(IAsyncResult ar) { ConnectParam connectParam = (ConnectParam)ar.AsyncState; try { connectParam.tcpClient.EndConnect(ar); connectParam.IsConnect = true; connectParam.GetTcpClient(); //连接成功,然后开启线程等待接收消息 connectParam.ListenerMsgThread.Start(connectParam); //先建立SSL通道(利用公钥将对称key加密发给服务器) AsyncSendMessage(connectParam, RSAProcessor.RSAEncrypt(configModel.PublicKey, connectParam.RandomKey) + MessageTypes.KEY); //发送第一条用对称key加密的信息 AsyncSendMessage(connectParam, RijndaelProcessor.EncryptString(connectParam.Msg, connectParam.RandomKey)); } catch { App.Current.Dispatcher.Invoke(new Action(() => { StoryboardManager.StopStoryboard("Story_Login"); XWT.MessageBox.Show("未能连接到服务器,请检查网络状态!", "提示", MessageBoxButton.OK, MessageBoxImage.Error); }), System.Windows.Threading.DispatcherPriority.Normal); if (connectParam.tcpClient != null) { connectParam.tcpClient = null; } connectParam.IsConnect = false; } }
public void OnReceiveMsg(ReceiveMsgOrder receiveMsgOrder) { if (receiveMsgOrder.Sign == 1) //登陆成功 { //ID+账号+昵称+头像 string[] UserMsg = receiveMsgOrder.MsgContent.Split(MessageTypes.NSP.ToCharArray()); //此处不做窗口跳转处理,由PreViewModel.cs处理 //存储用户 _userModel = UserModel.CreateModel(UserMsg[1], UserMsg[2], UserMsg[3], this.PassWord, Check, DateTime.Now); if (_userAccess.IsAlreadyExists(_userModel)) { _userAccess.UpdateUser(_userModel); } else { _userAccess.AddUser(_userModel); } _userAccess.SortUser(); return; } StoryboardManager.StopStoryboard("Story_Login"); XWT.MessageBox.Show(receiveMsgOrder.MsgContent, "提示", MessageBoxButton.OK, MessageBoxImage.Information); //MsgEvent msgEvent = eventAggregator.GetEvent<MsgEvent>(); //if (subscriptionToken != null) // msgEvent.Unsubscribe(subscriptionToken); }
void OnLoginExcute(PasswordBox pass) { if (IsStringMissing(pass.Password) || IsStringMissing(this.CardWord)) { XWT.MessageBox.Show("账号或密码不能为空!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); return; } //启动动画 StoryboardManager.PlayStoryboard("Story_Login", OnCompletedExcute, null); if (this.Check) { this.PassWord = pass.Password; } else { this.PassWord = ""; } // 信息发送==>事件发布方 send_Aggregator.GetEvent <SendMsgEvent>().Publish(MessageTypes.LOG + this.CardWord + MessageTypes.NSP + pass.Password); //ReceiveMsgOrder receiveMsgOrder = new ReceiveMsgOrder() { ModuleType="LOG",Sign=1,MsgContent="fff"}; ////广播 //receive_Aggregator.GetEvent<ReceiveMsgEvent>().Publish(receiveMsgOrder); }
/// <summary> /// 向服务器发送数据 /// </summary> /// <param name="message">发送的信息</param> public void AsyncSendMessage(ConnectParam connectParam, string message) { try { connectParam.sw.WriteLine(message); connectParam.sw.Flush(); } catch { App.Current.Dispatcher.Invoke(new Action(() => { StoryboardManager.StopStoryboard("Story_Login"); XWT.MessageBox.Show("数据发送失败,请重试!", "提示", MessageBoxButton.OK, MessageBoxImage.Error); }), System.Windows.Threading.DispatcherPriority.Normal); } }
public void OnReceiveMsg(ReceiveMsgOrder receiveMsgOrder) { if (receiveMsgOrder.Sign == 1) { this.OnRequestClose(); StoryboardManager.StopStoryboard("Story_Login"); App.Current.MainWindow.Show(); return; } StoryboardManager.StopStoryboard("Story_Login"); XWT.MessageBox.Show(receiveMsgOrder.MsgContent, "提示", MessageBoxButton.OK, MessageBoxImage.Information); //MessageBox.Show(receiveMsgOrder.MsgContent); //ReceiveMsgEvent msgEvent = receive_Aggregator.GetEvent<ReceiveMsgEvent>(); //if (subscriptionToken != null) // msgEvent.Unsubscribe(subscriptionToken); }
public LoginView() { InitializeComponent(); StoryboardManager.SetID((Storyboard)this.Resources["Story_Login"], "Story_Login"); }