Example #1
0
 // 账户登陆,主题由ViewModel完成,这个函数只处理App初始化和到MainWindow的衔接
 private void StackPanel_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     App.user = new Model.User()
     {
         userName = UserNameTbx.Text
     };
     App.LoadAddressBook(UserNameTbx.Text);
     App.generalListener = new P2PListener(P2PListener.GENERALLISTENPORT);
     App.generalListener.BeginListen();
     App.fileListener = new P2PListener(P2PListener.FILELISTENPORT);
     App.fileListener.BeginListen();
     UDPListener.getInstance();
     UDPListener.getInstance().BeginListen();
     this.Close();
 }
Example #2
0
        // 初始化,绑定ViewModel, 绑定各类应用层消息的处理函数
        public chattingPage()
        {
            InitializeComponent();
            msgTbx.Style = null;

            // 绑定ViewMode
            chatViewModel            = new ChatViewModel();
            chatRoomList.ItemsSource = chatViewModel.chatRoomViewModels;


            // 绑定各类应用层消息的处理函数
            App.generalListener.RecvCallBack += AppProtocol.RecvData;
            App.fileListener.RecvCallBack    += AppProtocol.RecvData;
            UDPListener.getInstance().RecvCallBack += AppProtocol.RecvData;
            AppProtocol.WordDealer    += recvNewWord;
            AppProtocol.FileDealer    += recvNewFile;
            AppProtocol.PhotoDealer   += recvNewPhoto;
            AppProtocol.ControlDealer += RecvControl;
        }
Example #3
0
        // 主窗口关闭时,关断各类监听端口,写本地通讯录
        private void Window_Closed(object sender, EventArgs e)
        {
            for (int i = 0; i < 100; i++)
            {
                string recv = NetWork.CSClient.getInstance().SendAMsg($"logout{App.user.userName}");
                if (recv == "loo")
                {
                    break;
                }
                if (i == 100 - 1)
                {
                    MessageBox.Show("多次尝试,未能和服务器成功发送下线请求");
                }
            }
            // TODO commonet logout, debug temp

            App.generalListener.EndListen();
            App.fileListener.EndListen();
            UDPListener.getInstance().EndListen();
            UDPSender.getInstance().EndUDPSender();
            App.UpdateAddressBook();
            Environment.Exit(0);
        }