同步代码数据
This commit is contained in:
@@ -8,10 +8,14 @@ namespace Interact
|
|||||||
//Json数据的字段访问字符串
|
//Json数据的字段访问字符串
|
||||||
public static class AttrNames
|
public static class AttrNames
|
||||||
{
|
{
|
||||||
|
//基本信息
|
||||||
public const string Token = "Token";
|
public const string Token = "Token";
|
||||||
public const string Operation = "Operation";
|
public const string Operation = "Operation";
|
||||||
public const string Error = "Error";
|
|
||||||
|
|
||||||
|
//处理结果信息
|
||||||
|
public const string Error = "Error";
|
||||||
|
|
||||||
|
//用户信息
|
||||||
public const string User = "User";
|
public const string User = "User";
|
||||||
public const string NickName = "NickName";
|
public const string NickName = "NickName";
|
||||||
public const string Motto = "Motto";
|
public const string Motto = "Motto";
|
||||||
|
|||||||
+96
-11
@@ -7,6 +7,7 @@ using System.Net;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Interact
|
namespace Interact
|
||||||
{
|
{
|
||||||
@@ -46,7 +47,7 @@ namespace Interact
|
|||||||
//获取用户列表结果处理事件
|
//获取用户列表结果处理事件
|
||||||
public static event GetUserListDoneHandler OnGetUserListDone;
|
public static event GetUserListDoneHandler OnGetUserListDone;
|
||||||
//获取用户头像结果处理事件
|
//获取用户头像结果处理事件
|
||||||
public static event GetUserPhotoDoneHandler OnGetUserPhotoDoneHandler;
|
public static event GetUserPhotoDoneHandler OnGetUserPhotoDone;
|
||||||
//发送消息时是否要求服务器返回处理结果
|
//发送消息时是否要求服务器返回处理结果
|
||||||
public static bool DoesSendMessageReturn
|
public static bool DoesSendMessageReturn
|
||||||
{
|
{
|
||||||
@@ -78,7 +79,8 @@ namespace Interact
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 初始化客户端,连接服务器。如果成功则启动数据接收和发送线程
|
/// 初始化客户端,连接服务器。如果成功则启动数据接收和发送线程。
|
||||||
|
/// 注意,当网络不稳定时此方法可能会阻塞。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>如果已连接到服务器返回true,否则返回false。</returns>
|
/// <returns>如果已连接到服务器返回true,否则返回false。</returns>
|
||||||
public static bool Initialize()
|
public static bool Initialize()
|
||||||
@@ -135,31 +137,100 @@ namespace Interact
|
|||||||
/// <param name="callback">数据发送完毕时回调函数</param>
|
/// <param name="callback">数据发送完毕时回调函数</param>
|
||||||
/// <returns>成功将请求加入发送队列返回true,否则返回false。</returns>
|
/// <returns>成功将请求加入发送队列返回true,否则返回false。</returns>
|
||||||
public static bool QueueSendMessage(string text, User to, Action<BaseHead> callback = null)
|
public static bool QueueSendMessage(string text, User to, Action<BaseHead> callback = null)
|
||||||
{ return false; }
|
{
|
||||||
|
JsonSendMessageHead jsonObj = new JsonSendMessageHead()
|
||||||
|
{
|
||||||
|
Token = "",
|
||||||
|
Operation = Operations.SendMessage.ToString(),
|
||||||
|
To = to.Name,
|
||||||
|
NeedResult = DoesSendMessageReturn ? "1" : "0"
|
||||||
|
};
|
||||||
|
Packet packet = new Packet
|
||||||
|
{
|
||||||
|
Head = jsonObj,
|
||||||
|
Data = Encoding.UTF8.GetBytes(text),
|
||||||
|
CallBack = callback
|
||||||
|
};
|
||||||
|
return Send(packet);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 请求登出。异步,此方法将请求放入请求队列后返回。
|
/// 请求登出。异步,此方法将请求放入请求队列后返回。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="callback">数据发送完毕时回调函数</param>
|
/// <param name="callback">数据发送完毕时回调函数</param>
|
||||||
/// <returns>成功将请求加入发送队列返回true,否则返回false。</returns>
|
/// <returns>成功将请求加入发送队列返回true,否则返回false。</returns>
|
||||||
|
|
||||||
public static bool QueueLogout(Action<BaseHead> callback = null)
|
public static bool QueueLogout(Action<BaseHead> callback = null)
|
||||||
{ return false; }
|
{
|
||||||
|
BaseHead jsonObj = new BaseHead()
|
||||||
|
{
|
||||||
|
Token = "",
|
||||||
|
Operation = Operations.Logout.ToString(),
|
||||||
|
};
|
||||||
|
Packet packet = new Packet
|
||||||
|
{
|
||||||
|
Head = jsonObj,
|
||||||
|
Data = null,
|
||||||
|
CallBack = callback
|
||||||
|
};
|
||||||
|
return Send(packet);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 请求用户列表。异步,此方法将请求放入请求队列后返回。
|
/// 请求用户列表。异步,此方法将请求放入请求队列后返回。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="callback">数据发送完毕时回调函数</param>
|
/// <param name="callback">数据发送完毕时回调函数</param>
|
||||||
/// <returns>成功将请求加入发送队列返回true,否则返回false。</returns>
|
/// <returns>成功将请求加入发送队列返回true,否则返回false。</returns>
|
||||||
|
|
||||||
public static bool QueueGetUserList(Action<BaseHead> callback = null)
|
public static bool QueueGetUserList(Action<BaseHead> callback = null)
|
||||||
{ return false; }
|
{
|
||||||
|
BaseHead jsonObj = new BaseHead()
|
||||||
|
{
|
||||||
|
Token = "",
|
||||||
|
Operation = Operations.GetUserList.ToString(),
|
||||||
|
};
|
||||||
|
Packet packet = new Packet
|
||||||
|
{
|
||||||
|
Head = jsonObj,
|
||||||
|
Data = null,
|
||||||
|
CallBack = callback
|
||||||
|
};
|
||||||
|
return Send(packet);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 请求更新当前登录用户信息。异步,此方法将请求放入请求队列后返回。
|
/// 请求更新当前登录用户信息。异步,此方法将请求放入请求队列后返回。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="callback">数据发送完毕时回调函数</param>
|
/// <param name="callback">数据发送完毕时回调函数</param>
|
||||||
/// <returns>成功将请求加入发送队列返回true,否则返回false。</returns>
|
/// <returns>成功将请求加入发送队列返回true,否则返回false。</returns>
|
||||||
|
public static bool QueueUpdateUserInfo(UserInfo userInfo, Action<BaseHead> callback = null)
|
||||||
public static bool QueueUpdateUserInfo(Action<BaseHead> callback = null)
|
{
|
||||||
{ return false; }
|
byte[] photoData = null; //头像数据
|
||||||
|
//将头像数据转换到字符数组
|
||||||
|
if (userInfo.Photo != null)
|
||||||
|
{
|
||||||
|
MemoryStream memStream = new MemoryStream();
|
||||||
|
userInfo.Photo.Save(memStream, userInfo.Photo.RawFormat);
|
||||||
|
photoData = new byte[memStream.Length];
|
||||||
|
memStream.Seek(0, SeekOrigin.Begin);
|
||||||
|
memStream.Read(photoData, 0, photoData.Length);
|
||||||
|
}
|
||||||
|
//构建数据包
|
||||||
|
JsonUserInfoHead jsonObj = new JsonUserInfoHead()
|
||||||
|
{
|
||||||
|
Token = "",
|
||||||
|
Operation = Operations.UpdateUserInfo.ToString(),
|
||||||
|
NickName = userInfo.NickName,
|
||||||
|
Password = userInfo.Password,
|
||||||
|
Motto = userInfo.Motto,
|
||||||
|
Photo = userInfo.Photo == null ? 0 : photoData.Length
|
||||||
|
};
|
||||||
|
Packet packet = new Packet
|
||||||
|
{
|
||||||
|
Head = jsonObj,
|
||||||
|
Data = photoData,
|
||||||
|
CallBack = callback
|
||||||
|
};
|
||||||
|
return Send(packet);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 请求获取指定用户的头像。异步,此方法将请求放入请求队列后返回。
|
/// 请求获取指定用户的头像。异步,此方法将请求放入请求队列后返回。
|
||||||
@@ -168,6 +239,20 @@ namespace Interact
|
|||||||
/// <param name="callback">数据发送完毕时回调函数</param>
|
/// <param name="callback">数据发送完毕时回调函数</param>
|
||||||
/// <returns>成功将请求加入发送队列返回true,否则返回false。</returns>
|
/// <returns>成功将请求加入发送队列返回true,否则返回false。</returns>
|
||||||
public static bool QueueGetUserPhoto(User user, Action<BaseHead> callback = null)
|
public static bool QueueGetUserPhoto(User user, Action<BaseHead> callback = null)
|
||||||
{ return false; }
|
{
|
||||||
|
JsonGetUserPhotoHead jsonObj = new JsonGetUserPhotoHead()
|
||||||
|
{
|
||||||
|
Token = "",
|
||||||
|
Operation = Operations.GetUserPhoto.ToString(),
|
||||||
|
User = user.Name
|
||||||
|
};
|
||||||
|
Packet packet = new Packet
|
||||||
|
{
|
||||||
|
Head = jsonObj,
|
||||||
|
Data = null,
|
||||||
|
CallBack = callback
|
||||||
|
};
|
||||||
|
return Send(packet);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,10 @@ namespace Interact
|
|||||||
{
|
{
|
||||||
//发起登录完成事件
|
//发起登录完成事件
|
||||||
if (head.Error != "")
|
if (head.Error != "")
|
||||||
|
{
|
||||||
OnLoginDone?.Invoke(head, null);
|
OnLoginDone?.Invoke(head, null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
JObject dataObj = (JObject)JsonConvert.DeserializeObject(Encoding.UTF8.GetString(data));
|
JObject dataObj = (JObject)JsonConvert.DeserializeObject(Encoding.UTF8.GetString(data));
|
||||||
User user = new User
|
User user = new User
|
||||||
{
|
{
|
||||||
|
|||||||
+20
-6
@@ -10,6 +10,7 @@ namespace Interact
|
|||||||
public class BaseHead
|
public class BaseHead
|
||||||
{
|
{
|
||||||
//请求ID,由发送方定义的随机字符串。如果接受方有返回数据应包含相同的Token
|
//请求ID,由发送方定义的随机字符串。如果接受方有返回数据应包含相同的Token
|
||||||
|
//此特性暂时未启用,传空字符串即可
|
||||||
public string Token;
|
public string Token;
|
||||||
//操作类型,决定数据的其他内容
|
//操作类型,决定数据的其他内容
|
||||||
public string Operation;
|
public string Operation;
|
||||||
@@ -30,13 +31,26 @@ namespace Interact
|
|||||||
public string Pwd;
|
public string Pwd;
|
||||||
}
|
}
|
||||||
|
|
||||||
//用户信息
|
//发送消息包头
|
||||||
internal class JsonUserInfo
|
internal class JsonSendMessageHead : BaseHead
|
||||||
{
|
{
|
||||||
public string User; //用户名
|
public string To; //消息接收者用户名
|
||||||
public string NickName; //昵称
|
public string NeedResult = "0"; //是否要求服务器返回处理结果。否传“0”
|
||||||
public string Motto; //个性签名
|
}
|
||||||
public string UGroup; //用户组
|
|
||||||
|
//更新用户信息包头
|
||||||
|
internal class JsonUserInfoHead : BaseHead
|
||||||
|
{
|
||||||
|
public string NickName = null;
|
||||||
|
public string Password = null;
|
||||||
|
public string Motto = null;
|
||||||
|
public int Photo = 0; //新头像大小
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取用户头像请求的包头
|
||||||
|
internal class JsonGetUserPhotoHead : BaseHead
|
||||||
|
{
|
||||||
|
public string User; //要获取头像的用户名
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
namespace Interact
|
namespace Interact
|
||||||
{
|
{
|
||||||
@@ -17,6 +18,15 @@ namespace Interact
|
|||||||
public UserGroup Group; //用户组
|
public UserGroup Group; //用户组
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//更新用户信息时新的用户信息。如果项值为null则不更改相应的信息
|
||||||
|
public class UserInfo
|
||||||
|
{
|
||||||
|
public string Password = null; //新密码
|
||||||
|
public string NickName = null; //新昵称
|
||||||
|
public string Motto = null; //新签名
|
||||||
|
public Image Photo = null; //新头像
|
||||||
|
}
|
||||||
|
|
||||||
//用户类型
|
//用户类型
|
||||||
public enum UserGroup
|
public enum UserGroup
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:local="clr-namespace:StormChatWPF"
|
xmlns:local="clr-namespace:StormChatWPF"
|
||||||
StartupUri="MainWindow.xaml">
|
StartupUri="LogWindow.xaml">
|
||||||
<Application.Resources>
|
<Application.Resources>
|
||||||
|
|
||||||
</Application.Resources>
|
</Application.Resources>
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Interact;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
namespace StormChatWPF
|
||||||
|
{
|
||||||
|
class Chat
|
||||||
|
{
|
||||||
|
public static List<User> userlist = new List<User>();//联系人集合
|
||||||
|
|
||||||
|
|
||||||
|
internal static void GetUsers(ResultHandler head, User user)
|
||||||
|
{
|
||||||
|
|
||||||
|
}//获取联系人对象
|
||||||
|
internal static void GetUserList(ResultHead head, User[] users)
|
||||||
|
{
|
||||||
|
if (head.Error != "")
|
||||||
|
{
|
||||||
|
MessageBox.Show("无法获取联系人列表");
|
||||||
|
}
|
||||||
|
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())
|
||||||
|
{
|
||||||
|
StormClient.QueueLogin(user,password);
|
||||||
|
}
|
||||||
|
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.a.Close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("登录失败!");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}//登录完成
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<Window x:Class="StormChatWPF.LogWindow"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:local="clr-namespace:StormChatWPF"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
Title="MainWindow" Height="450" Width="800">
|
||||||
|
<Grid>
|
||||||
|
<Image x:Name="LogImage" HorizontalAlignment="Left" Height="230" Margin="10,10,0,0" VerticalAlignment="Top" Width="774" Source="/RESOURCES/logFormBackground.jpg" Stretch="None"/>
|
||||||
|
<Button x:Name="Login_button" Content="LogIn" HorizontalAlignment="Left" Margin="240,376,0,0" VerticalAlignment="Top" Width="75" RenderTransformOrigin="0.664,1.51" Click="Login_button_Click"/>
|
||||||
|
<TextBox x:Name="AccountBox" HorizontalAlignment="Left" Height="23" Margin="240,290,0,0" TextWrapping="Wrap" Text="201701110203" VerticalAlignment="Top" Width="120" />
|
||||||
|
<PasswordBox x:Name="passwordBox" HorizontalAlignment="Left" Margin="240,332,0,0" VerticalAlignment="Top" Width="120" Password="1233211234567"/>
|
||||||
|
|
||||||
|
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
using Interact;
|
||||||
|
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.Navigation;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
|
||||||
|
namespace StormChatWPF
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// MainWindow.xaml 的交互逻辑
|
||||||
|
/// </summary>
|
||||||
|
public partial class LogWindow : Window
|
||||||
|
{
|
||||||
|
public static LogWindow a;
|
||||||
|
public LogWindow()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
StormClient.OnLoginDone += Chat.HaveLogin;
|
||||||
|
StormClient.OnGetUserListDone += Chat.GetUserList;
|
||||||
|
StormClient.OnGetUserPhotoDone += Chat.GetUserPhoto;
|
||||||
|
a = this;
|
||||||
|
}
|
||||||
|
Chat chat = new Chat();
|
||||||
|
private void Login_button_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
chat.Log(AccountBox.Text,passwordBox.Password);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,17 +5,17 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:local="clr-namespace:StormChatWPF"
|
xmlns:local="clr-namespace:StormChatWPF"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="MainWindow" Height="421.4" Width="628.2">
|
Title="UserWindow" Height="450" Width="800"
|
||||||
|
|
||||||
|
>
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.ColumnDefinitions>
|
<ListView x:Name="UsersList" HorizontalAlignment="Left" Height="346" VerticalAlignment="Top" Width="191" Margin="10,64,0,0" IsEnabled="False">
|
||||||
<ColumnDefinition Width="190*"/>
|
<ListView.View>
|
||||||
<ColumnDefinition Width="121*"/>
|
<GridView>
|
||||||
</Grid.ColumnDefinitions>
|
<GridViewColumn/>
|
||||||
<Image x:Name="LogImage" HorizontalAlignment="Left" Height="220" Margin="0,20,-0.4,0" VerticalAlignment="Top" Width="622" Source="/RESOURCES/logFormBackground.jpg" Stretch="None" Grid.ColumnSpan="2" RenderTransformOrigin="0.483,0.5"/>
|
</GridView>
|
||||||
<Button x:Name="Login_button" Content="LogIn" HorizontalAlignment="Left" Margin="240,330,0,0" VerticalAlignment="Top" Width="120" RenderTransformOrigin="0.664,1.51" Click="Login_button_Click" Height="40"/>
|
</ListView.View>
|
||||||
<TextBox x:Name="AccountBox" HorizontalAlignment="Left" Margin="240,255,0,0" TextWrapping="Wrap" Text="201701110203" VerticalAlignment="Top" Width="120" FontSize="14" RenderTransformOrigin="0.542,-1.021" />
|
</ListView>
|
||||||
<PasswordBox x:Name="passwordBox" HorizontalAlignment="Left" Margin="240,296,0,0" VerticalAlignment="Top" Width="120" Password="1233211234567" FontSize="14"/>
|
|
||||||
|
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Interact;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -11,50 +10,30 @@ using System.Windows.Documents;
|
|||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Navigation;
|
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
|
|
||||||
namespace StormChatWPF
|
namespace StormChatWPF
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// MainWindow.xaml 的交互逻辑
|
/// UserWindow.xaml 的交互逻辑
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class MainWindow : Window
|
public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
StormClient.OnLoginDone += HaveLogin;
|
|
||||||
}
|
}
|
||||||
|
private void AddUserList()
|
||||||
|
{
|
||||||
|
if (Chat.userlist.Any())
|
||||||
|
{
|
||||||
|
foreach (var user in Chat.userlist)
|
||||||
|
{
|
||||||
|
UsersList.Items.Add(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}//向联系人列表listview中添加元素
|
||||||
|
|
||||||
|
|
||||||
private void Login_button_Click(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
if (StormClient.Initialize())
|
|
||||||
{
|
|
||||||
StormClient.QueueLogin(AccountBox.Text, passwordBox.Password, null);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MessageBox.Show("连接服务器失败!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void HaveLogin(ResultHead head, User user)
|
|
||||||
{
|
|
||||||
App.Current.Dispatcher.Invoke((Action)delegate ()
|
|
||||||
{
|
|
||||||
if (head.Error == "")
|
|
||||||
{
|
|
||||||
User.Me = user;
|
|
||||||
UserWindow userWindow = new UserWindow();
|
|
||||||
userWindow.Show();
|
|
||||||
this.Close();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MessageBox.Show("登录失败!");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+118
-117
@@ -1,118 +1,119 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
<ProjectGuid>{CF4D6BE0-A862-401F-A3A6-4FDAC32F5B70}</ProjectGuid>
|
<ProjectGuid>{CF4D6BE0-A862-401F-A3A6-4FDAC32F5B70}</ProjectGuid>
|
||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
<RootNamespace>StormChatWPF</RootNamespace>
|
<RootNamespace>StormChatWPF</RootNamespace>
|
||||||
<AssemblyName>StormChatWPF</AssemblyName>
|
<AssemblyName>StormChatWPF</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
<Deterministic>true</Deterministic>
|
<Deterministic>true</Deterministic>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
<Optimize>false</Optimize>
|
<Optimize>false</Optimize>
|
||||||
<OutputPath>bin\Debug\</OutputPath>
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
<Optimize>true</Optimize>
|
<Optimize>true</Optimize>
|
||||||
<OutputPath>bin\Release\</OutputPath>
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<StartupObject>StormChatWPF.App</StartupObject>
|
<StartupObject>StormChatWPF.App</StartupObject>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
<Reference Include="System.Net.Http" />
|
<Reference Include="System.Net.Http" />
|
||||||
<Reference Include="System.Xaml">
|
<Reference Include="System.Xaml">
|
||||||
<RequiredTargetFramework>4.0</RequiredTargetFramework>
|
<RequiredTargetFramework>4.0</RequiredTargetFramework>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="WindowsBase" />
|
<Reference Include="WindowsBase" />
|
||||||
<Reference Include="PresentationCore" />
|
<Reference Include="PresentationCore" />
|
||||||
<Reference Include="PresentationFramework" />
|
<Reference Include="PresentationFramework" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ApplicationDefinition Include="App.xaml">
|
<ApplicationDefinition Include="App.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
</ApplicationDefinition>
|
</ApplicationDefinition>
|
||||||
<Compile Include="UserWindow.xaml.cs">
|
<Compile Include="Chat.cs" />
|
||||||
<DependentUpon>UserWindow.xaml</DependentUpon>
|
<Compile Include="MainWindow.xaml.cs">
|
||||||
</Compile>
|
<DependentUpon>MainWindow.xaml</DependentUpon>
|
||||||
<Page Include="MainWindow.xaml">
|
</Compile>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Page Include="LogWindow.xaml">
|
||||||
<SubType>Designer</SubType>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</Page>
|
<SubType>Designer</SubType>
|
||||||
<Compile Include="App.xaml.cs">
|
</Page>
|
||||||
<DependentUpon>App.xaml</DependentUpon>
|
<Compile Include="App.xaml.cs">
|
||||||
<SubType>Code</SubType>
|
<DependentUpon>App.xaml</DependentUpon>
|
||||||
</Compile>
|
<SubType>Code</SubType>
|
||||||
<Compile Include="MainWindow.xaml.cs">
|
</Compile>
|
||||||
<DependentUpon>MainWindow.xaml</DependentUpon>
|
<Compile Include="LogWindow.xaml.cs">
|
||||||
<SubType>Code</SubType>
|
<DependentUpon>LogWindow.xaml</DependentUpon>
|
||||||
</Compile>
|
<SubType>Code</SubType>
|
||||||
<Page Include="UserWindow.xaml">
|
</Compile>
|
||||||
<SubType>Designer</SubType>
|
<Page Include="MainWindow.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<SubType>Designer</SubType>
|
||||||
</Page>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</ItemGroup>
|
</Page>
|
||||||
<ItemGroup>
|
</ItemGroup>
|
||||||
<Compile Include="Properties\AssemblyInfo.cs">
|
<ItemGroup>
|
||||||
<SubType>Code</SubType>
|
<Compile Include="Properties\AssemblyInfo.cs">
|
||||||
</Compile>
|
<SubType>Code</SubType>
|
||||||
<Compile Include="Properties\Resources.Designer.cs">
|
</Compile>
|
||||||
<AutoGen>True</AutoGen>
|
<Compile Include="Properties\Resources.Designer.cs">
|
||||||
<DesignTime>True</DesignTime>
|
<AutoGen>True</AutoGen>
|
||||||
<DependentUpon>Resources.resx</DependentUpon>
|
<DesignTime>True</DesignTime>
|
||||||
</Compile>
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
<Compile Include="Properties\Settings.Designer.cs">
|
</Compile>
|
||||||
<AutoGen>True</AutoGen>
|
<Compile Include="Properties\Settings.Designer.cs">
|
||||||
<DependentUpon>Settings.settings</DependentUpon>
|
<AutoGen>True</AutoGen>
|
||||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
<DependentUpon>Settings.settings</DependentUpon>
|
||||||
</Compile>
|
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||||
<EmbeddedResource Include="Properties\Resources.resx">
|
</Compile>
|
||||||
<Generator>ResXFileCodeGenerator</Generator>
|
<EmbeddedResource Include="Properties\Resources.resx">
|
||||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
<Generator>ResXFileCodeGenerator</Generator>
|
||||||
</EmbeddedResource>
|
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||||
<None Include="Properties\Settings.settings">
|
</EmbeddedResource>
|
||||||
<Generator>SettingsSingleFileGenerator</Generator>
|
<None Include="Properties\Settings.settings">
|
||||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
<Generator>SettingsSingleFileGenerator</Generator>
|
||||||
</None>
|
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||||
</ItemGroup>
|
</None>
|
||||||
<ItemGroup>
|
</ItemGroup>
|
||||||
<None Include="App.config" />
|
<ItemGroup>
|
||||||
</ItemGroup>
|
<None Include="App.config" />
|
||||||
<ItemGroup>
|
</ItemGroup>
|
||||||
<Resource Include="Resources\LogFormBackground.jpg" />
|
<ItemGroup>
|
||||||
</ItemGroup>
|
<Resource Include="Resources\LogFormBackground.jpg" />
|
||||||
<ItemGroup>
|
</ItemGroup>
|
||||||
<ProjectReference Include="..\Interact\Interact.csproj">
|
<ItemGroup>
|
||||||
<Project>{cef054af-95b7-4b88-934e-02705feea554}</Project>
|
<ProjectReference Include="..\Interact\Interact.csproj">
|
||||||
<Name>Interact</Name>
|
<Project>{cef054af-95b7-4b88-934e-02705feea554}</Project>
|
||||||
</ProjectReference>
|
<Name>Interact</Name>
|
||||||
</ItemGroup>
|
</ProjectReference>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
<Window x:Class="StormChatWPF.UserWindow"
|
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
|
||||||
xmlns:local="clr-namespace:StormChatWPF"
|
|
||||||
mc:Ignorable="d"
|
|
||||||
Title="UserWindow" Height="450" Width="800"
|
|
||||||
|
|
||||||
>
|
|
||||||
<Grid>
|
|
||||||
|
|
||||||
</Grid>
|
|
||||||
</Window>
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
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
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// UserWindow.xaml 的交互逻辑
|
|
||||||
/// </summary>
|
|
||||||
public partial class UserWindow : Window
|
|
||||||
{
|
|
||||||
public UserWindow()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user