From 5bc6f9047e598760c56583038f724954e2e877ea Mon Sep 17 00:00:00 2001
From: Kaniu Tayou <1056879522@qq.com>
Date: Mon, 17 Dec 2018 18:49:16 +0800
Subject: [PATCH 1/4] =?UTF-8?q?=E6=96=B0wpf=E7=AA=97=E5=8F=A3=E5=BB=BA?=
=?UTF-8?q?=E7=AB=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
StormChatWPF/MainWindow.xaml | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/StormChatWPF/MainWindow.xaml b/StormChatWPF/MainWindow.xaml
index 7ac6f61..2a03a35 100644
--- a/StormChatWPF/MainWindow.xaml
+++ b/StormChatWPF/MainWindow.xaml
@@ -5,12 +5,16 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:StormChatWPF"
mc:Ignorable="d"
- Title="MainWindow" Height="450" Width="800">
+ Title="MainWindow" Height="421.4" Width="628.2">
-
-
-
-
+
+
+
+
+
+
+
+
From 1881936429eb0dd49b8e1d8804264905cda1cc34 Mon Sep 17 00:00:00 2001
From: Kaniu Tayou <1056879522@qq.com>
Date: Tue, 18 Dec 2018 11:17:57 +0800
Subject: [PATCH 2/4] some new methods
---
Interact/Client.cs | 2 +-
StormChatWPF/Chat.cs | 35 +++++++++++++++++++++++-----------
StormChatWPF/LogWindow.xaml.cs | 16 +++++++++-------
3 files changed, 34 insertions(+), 19 deletions(-)
diff --git a/Interact/Client.cs b/Interact/Client.cs
index 79a10f0..e341eb7 100644
--- a/Interact/Client.cs
+++ b/Interact/Client.cs
@@ -38,7 +38,7 @@ namespace Interact
//登录结果处理事件
public static event LoginDoneHandler OnLoginDone;
//获取用户列表结果处理事件
- private static event GetUserListDoneHandler OnGetUserListDone;
+ public static event GetUserListDoneHandler OnGetUserListDone;
//当前连接状态
public static ClientStatus Status
diff --git a/StormChatWPF/Chat.cs b/StormChatWPF/Chat.cs
index 6377be9..b957f97 100644
--- a/StormChatWPF/Chat.cs
+++ b/StormChatWPF/Chat.cs
@@ -12,8 +12,16 @@ namespace StormChatWPF
class Chat
{
public static List userlist = new List();//联系人集合
-
+ public static Chat chat = new Chat();
+ private Chat()
+ {
+ StormClient.OnLoginDone += HaveLogin;
+ StormClient.OnGetUserListDone += GetUserList;
+ StormClient.OnMessage +=ReciveMessage;
+ }
+
+
internal static void GetUsers(ResultHandler head, User user)
{
@@ -27,13 +35,6 @@ namespace StormChatWPF
else
return;
}//获取用户列表
- internal static void GetUserPhoto(ResultHead head, Image image)
- {
- if (head.Error != "")
- {
- MessageBox.Show("无法读取用户图片");
- }
- }//对用户头像进行赋值
internal void Log(string user,string password)
{
if (StormClient.Initialize())
@@ -55,7 +56,7 @@ namespace StormChatWPF
User.Me = user;
MainWindow userWindow = new MainWindow();
userWindow.Show();
- LogWindow.a.Close();
+ LogWindow.Instence.Close();
}
else
{
@@ -63,7 +64,19 @@ namespace StormChatWPF
}
});
}//登录完成
-
-
+ 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.cs b/StormChatWPF/LogWindow.xaml.cs
index 2775cfa..924a07b 100644
--- a/StormChatWPF/LogWindow.xaml.cs
+++ b/StormChatWPF/LogWindow.xaml.cs
@@ -21,20 +21,22 @@ namespace StormChatWPF
///
public partial class LogWindow : Window
{
- public static LogWindow a;
+ public static LogWindow Instence;
public LogWindow()
{
InitializeComponent();
- StormClient.OnLoginDone += Chat.HaveLogin;
- StormClient.OnGetUserListDone += Chat.GetUserList;
- StormClient.OnGetUserPhotoDone += Chat.GetUserPhoto;
- a = this;
+ Instence = this;
}
- Chat chat = new Chat();
private void Login_button_Click(object sender, RoutedEventArgs e)
{
- chat.Log(AccountBox.Text,passwordBox.Password);
+ Chat.chat.Log(AccountBox.Text,passwordBox.Password);
}
+ internal void ShowMessage(Message message)
+ {
+ }//将收到的消息展现于UI界面
+ internal void ShowUserMessage()
+ {
+ }
}
}
From d854d278176f1dfc6ad4ca03b45b6c4d768d8be3 Mon Sep 17 00:00:00 2001
From: Kaniu Tayou <1056879522@qq.com>
Date: Tue, 18 Dec 2018 11:35:23 +0800
Subject: [PATCH 3/4] =?UTF-8?q?=E4=B8=80=E4=BA=9B=E6=94=B9=E5=8A=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
StormChatWPF/Chat.cs | 40 ++++++++++++++++++++++++----------------
1 file changed, 24 insertions(+), 16 deletions(-)
diff --git a/StormChatWPF/Chat.cs b/StormChatWPF/Chat.cs
index b957f97..e67a055 100644
--- a/StormChatWPF/Chat.cs
+++ b/StormChatWPF/Chat.cs
@@ -11,30 +11,38 @@ namespace StormChatWPF
{
class Chat
{
- public static List userlist = new List();//联系人集合
+ public static List ContactsList;//联系人集合
public static Chat chat = new Chat();
private Chat()
{
StormClient.OnLoginDone += HaveLogin;
- StormClient.OnGetUserListDone += GetUserList;
+ StormClient.OnGetUserListDone += GetContactsList;
StormClient.OnMessage +=ReciveMessage;
}
-
-
- internal static void GetUsers(ResultHandler head, User user)
+
+ private User ChatNow;
+ internal User SetContact
{
-
- }//获取联系人对象
- internal static void GetUserList(ResultHead head, User[] users)
+ get
+ {
+ return ChatNow;
+ }
+ set
+ {
+ ChatNow = value;
+ }
+ }//设置当前联系人对象
+ internal static void GetContactsList(ResultHead head, User[] users)
{
if (head.Error != "")
{
MessageBox.Show("无法获取联系人列表");
}
else
+ ContactsList =new List( users);
return;
- }//获取用户列表
+ }//获取联系人列表
internal void Log(string user,string password)
{
if (StormClient.Initialize())
@@ -70,13 +78,13 @@ namespace StormChatWPF
}//接受到新消息的时候
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();
+ // Message msg = new Message(text);
+ // Action f = delegate(BaseHead head)
+ // {
+
+ // };
+ // StormClient.QueueSendMessage(msg, target, f);
+ // LogWindow.Instence.ShowUserMessage();
}
}
}
From 4ec1c438799b6379b177fa95858e029b4a26500c Mon Sep 17 00:00:00 2001
From: Kaniu Tayou <1056879522@qq.com>
Date: Tue, 18 Dec 2018 19:38:27 +0800
Subject: [PATCH 4/4] =?UTF-8?q?=E4=B8=80=E4=BA=9B=E6=96=B0=E8=AE=BE?=
=?UTF-8?q?=E5=AE=9A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Interact/Client.cs | 2 +-
Interact/User.cs | 2 +-
StormChatWPF/Chat.cs | 43 ++++++++-----------
StormChatWPF/LogWindow.xaml | 10 ++---
StormChatWPF/LogWindow.xaml.cs | 10 +++--
StormChatWPF/MainWindow.xaml | 5 ++-
StormChatWPF/MainWindow.xaml.cs | 73 +++++++++++++++++++--------------
7 files changed, 78 insertions(+), 67 deletions(-)
diff --git a/Interact/Client.cs b/Interact/Client.cs
index 79a10f0..708986c 100644
--- a/Interact/Client.cs
+++ b/Interact/Client.cs
@@ -38,7 +38,7 @@ namespace Interact
//登录结果处理事件
public static event LoginDoneHandler OnLoginDone;
//获取用户列表结果处理事件
- private static event GetUserListDoneHandler OnGetUserListDone;
+ public static event GetUserListDoneHandler OnGetUserListDone;
//当前连接状态
public static ClientStatus Status
diff --git a/Interact/User.cs b/Interact/User.cs
index 0a94d81..692e66e 100644
--- a/Interact/User.cs
+++ b/Interact/User.cs
@@ -11,7 +11,7 @@ namespace Interact
public class User
{
public static User Me; //当前用户
-
+ public static string Password;//用户的密码
public string Name; //用户名
public string NickName; //昵称
public string Motto; //个性签名
diff --git a/StormChatWPF/Chat.cs b/StormChatWPF/Chat.cs
index 6377be9..f328679 100644
--- a/StormChatWPF/Chat.cs
+++ b/StormChatWPF/Chat.cs
@@ -11,13 +11,9 @@ namespace StormChatWPF
{
class Chat
{
- public static List userlist = new List();//联系人集合
-
+ public static User[] userlist;//联系人集合
+ public static User ChatNow = new User();//当前聊天对象
- internal static void GetUsers(ResultHandler head, User user)
- {
-
- }//获取联系人对象
internal static void GetUserList(ResultHead head, User[] users)
{
if (head.Error != "")
@@ -25,27 +21,24 @@ namespace StormChatWPF
MessageBox.Show("无法获取联系人列表");
}
else
- return;
- }//获取用户列表
- internal static void GetUserPhoto(ResultHead head, Image image)
- {
- if (head.Error != "")
- {
- MessageBox.Show("无法读取用户图片");
- }
- }//对用户头像进行赋值
+ userlist = users;
+ }//获取联系人用户列表
internal void Log(string user,string password)
{
- if (StormClient.Initialize())
- {
- StormClient.QueueLogin(user,password);
- }
- else
- {
- MessageBox.Show("连接服务器失败!");
+ if (StormClient.Initialize())
+ {
+ StormClient.QueueLogin(user,password);
+ }
+ else
+ {
+ MessageBox.Show("连接服务器失败!");
}
}//登录
- internal static void HaveLogin(ResultHead head, User user)
+ internal static void Reconnect(Exception e)
+ {
+ StormClient.Initialize();
+ }//尝试重连接一次,如果失败,则关闭mainwindow,打开登录窗口
+ internal static void HaveLogin(ResultHead head, User user)
{
App.Current.Dispatcher.Invoke(
(Action)delegate ()
@@ -55,13 +48,13 @@ namespace StormChatWPF
User.Me = user;
MainWindow userWindow = new MainWindow();
userWindow.Show();
- LogWindow.a.Close();
+ LogWindow.entry.Close();
}
else
{
MessageBox.Show("登录失败!");
}
- });
+ });
}//登录完成
diff --git a/StormChatWPF/LogWindow.xaml b/StormChatWPF/LogWindow.xaml
index 0e46e9f..efe8c9a 100644
--- a/StormChatWPF/LogWindow.xaml
+++ b/StormChatWPF/LogWindow.xaml
@@ -6,11 +6,11 @@
xmlns:local="clr-namespace:StormChatWPF"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
-
-
-
-
-
+
+
+
+
+
diff --git a/StormChatWPF/LogWindow.xaml.cs b/StormChatWPF/LogWindow.xaml.cs
index 2775cfa..166f091 100644
--- a/StormChatWPF/LogWindow.xaml.cs
+++ b/StormChatWPF/LogWindow.xaml.cs
@@ -21,14 +21,14 @@ namespace StormChatWPF
///
public partial class LogWindow : Window
{
- public static LogWindow a;
+ public static LogWindow entry;
public LogWindow()
{
InitializeComponent();
StormClient.OnLoginDone += Chat.HaveLogin;
StormClient.OnGetUserListDone += Chat.GetUserList;
- StormClient.OnGetUserPhotoDone += Chat.GetUserPhoto;
- a = this;
+ StormClient.OnDisconnect += Chat.Reconnect;
+ entry = this;
}
Chat chat = new Chat();
private void Login_button_Click(object sender, RoutedEventArgs e)
@@ -36,5 +36,9 @@ namespace StormChatWPF
chat.Log(AccountBox.Text,passwordBox.Password);
}
+ private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
+ {
+
+ }
}
}
diff --git a/StormChatWPF/MainWindow.xaml b/StormChatWPF/MainWindow.xaml
index f6a31f3..7f41ef2 100644
--- a/StormChatWPF/MainWindow.xaml
+++ b/StormChatWPF/MainWindow.xaml
@@ -9,13 +9,14 @@
>
-
+
-
+
+
diff --git a/StormChatWPF/MainWindow.xaml.cs b/StormChatWPF/MainWindow.xaml.cs
index 59f1481..052fe07 100644
--- a/StormChatWPF/MainWindow.xaml.cs
+++ b/StormChatWPF/MainWindow.xaml.cs
@@ -1,28 +1,28 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Shapes;
-
-namespace StormChatWPF
-{
- ///
- /// UserWindow.xaml 的交互逻辑
- ///
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- }
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+
+namespace StormChatWPF
+{
+ ///
+ /// UserWindow.xaml 的交互逻辑
+ ///
+ public partial class MainWindow : Window
+ {
+ public MainWindow()
+ {
+ InitializeComponent();
+ }
private void AddUserList()
{
if (Chat.userlist.Any())
@@ -32,8 +32,21 @@ namespace StormChatWPF
UsersList.Items.Add(user);
}
}
- }//向联系人列表listview中添加元素
-
-
- }
-}
+ }//向联系人列表listview中添加元素
+
+ private void UsersList_Selected(object sender, RoutedEventArgs e)
+ {
+
+ }
+
+ private void UsersList_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+
+ }
+
+ private void Button_Click(object sender, RoutedEventArgs e)
+ {
+ AddUserList();
+ }
+ }
+}