diff --git a/StormChatWPF/Chat.cs b/StormChatWPF/Chat.cs index e67a055..0e54842 100644 --- a/StormChatWPF/Chat.cs +++ b/StormChatWPF/Chat.cs @@ -12,79 +12,76 @@ namespace StormChatWPF class Chat { public static List ContactsList;//联系人集合 - public static Chat chat = new Chat(); + public static Chat chat=new Chat(); private Chat() { - StormClient.OnLoginDone += HaveLogin; - StormClient.OnGetUserListDone += GetContactsList; - StormClient.OnMessage +=ReciveMessage; + StormClient.OnLoginDone += OnHaveLogin; + StormClient.OnGetUserListDone += OnGetContactsList; + StormClient.OnMessage +=OnMessage; } - - - private User ChatNow; - internal User SetContact - { - get - { - return ChatNow; - } - set - { - ChatNow = value; - } - }//设置当前联系人对象 - internal static void GetContactsList(ResultHead head, User[] users) + internal static User CurrentContact { get; set; }//设置当前联系人对象 + /// + /// 获取联系人列表(完成后打开主窗体) + /// + private void OnGetContactsList(ResultHead head, User[] users) { if (head.Error != "") { MessageBox.Show("无法获取联系人列表"); - } - else - ContactsList =new List( users); return; - }//获取联系人列表 - internal void Log(string user,string password) + } + App.Current.Dispatcher.Invoke( + (Action)delegate () + { + ContactsList = new List(users); + MainWindow mainWindow = new MainWindow(); + mainWindow.Show(); + LogWindow.Instence.Close(); + }); + } + private void OnHaveLogin(ResultHead head, User user) + { + if (head.Error == "") + { + User.Me = user; + StormClient.QueueGetUserList(); + } + else + { + MessageBox.Show("请核对账号密码!"); + } + }//登录完成 + private void OnMessage(Message message) + { + if (MainWindow.Instence != null) + { + MainWindow.Instence.ShowMessage(message); + } + }//接受到新消息 + + internal void SendMessage(string text,User target) + { + Message msg = new Message(text,target); + Action f = delegate (ResultHead head) + { + MainWindow.Instence.ShowMessage(msg); + }; + StormClient.QueueSendMessage(msg,f); + }//发送消息 + internal static void Log(string user, string password) { if (StormClient.Initialize()) { - StormClient.QueueLogin(user,password); + if (!StormClient.QueueLogin(user, password)) + { + MessageBox.Show("登录失败"); + } } else { MessageBox.Show("连接服务器失败!"); } }//登录 - internal static void HaveLogin(ResultHead head, User user) - { - App.Current.Dispatcher.Invoke( - (Action)delegate () - { - if (head.Error == "") - { - User.Me = user; - MainWindow userWindow = new MainWindow(); - userWindow.Show(); - LogWindow.Instence.Close(); - } - else - { - MessageBox.Show("登录失败!"); - } - }); - }//登录完成 - internal static void ReciveMessage(Message message) - { - LogWindow.Instence.ShowMessage(message); - }//接受到新消息的时候 - internal static void SendMessage(string text,User target) - { - // Message msg = new Message(text); - // Action f = delegate(BaseHead head) - // { - - // }; - // StormClient.QueueSendMessage(msg, target, f); - // LogWindow.Instence.ShowUserMessage(); - } + } } diff --git a/StormChatWPF/LogWindow.xaml b/StormChatWPF/LogWindow.xaml index efe8c9a..12d5f90 100644 --- a/StormChatWPF/LogWindow.xaml +++ b/StormChatWPF/LogWindow.xaml @@ -5,13 +5,25 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:StormChatWPF" mc:Ignorable="d" - Title="MainWindow" Height="450" Width="800"> - - -