master
This commit is contained in:
parent
47920b3a72
commit
1442570541
7
chatclient/App.config
Normal file
7
chatclient/App.config
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
|
||||
</configSections>
|
||||
<log4net configSource="config/log4net.config" />
|
||||
</configuration>
|
18
chatclient/App.xaml
Normal file
18
chatclient/App.xaml
Normal file
@ -0,0 +1,18 @@
|
||||
<Application x:Class="chatclient.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:local="clr-namespace:chatclient"
|
||||
StartupUri="MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<materialDesign:BundledTheme BaseTheme="Light" PrimaryColor="DeepPurple" SecondaryColor="Lime" />
|
||||
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesign3.Defaults.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesign2.Defaults.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Application.Resources>
|
||||
</Application>
|
14
chatclient/App.xaml.cs
Normal file
14
chatclient/App.xaml.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Windows;
|
||||
|
||||
namespace chatclient
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
}
|
||||
|
||||
}
|
10
chatclient/AssemblyInfo.cs
Normal file
10
chatclient/AssemblyInfo.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System.Windows;
|
||||
|
||||
[assembly: ThemeInfo(
|
||||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||
//(used if a resource is not found in the page,
|
||||
// or application resource dictionaries)
|
||||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||
//(used if a resource is not found in the page,
|
||||
// app, or any theme specific resource dictionaries)
|
||||
)]
|
82
chatclient/LoginWindow.xaml
Normal file
82
chatclient/LoginWindow.xaml
Normal file
@ -0,0 +1,82 @@
|
||||
<Window
|
||||
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:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:local="clr-namespace:chatclient"
|
||||
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls" x:Class="chatclient.LoginWindow"
|
||||
mc:Ignorable="d"
|
||||
Title="LoginWindow" Height="590" Width="360" MinHeight="590" MinWidth="360" MaxHeight="590" MaxWidth="360"
|
||||
ResizeMode="NoResize">
|
||||
|
||||
<TabControl>
|
||||
<TabItem Header="登录账号" Cursor="Hand">
|
||||
<Grid Background="#FFE5E5E5">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="1.2*"/>
|
||||
<RowDefinition Height="6*"/>
|
||||
<RowDefinition Height="0.8*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="10" Cursor="Hand">
|
||||
<StackPanel>
|
||||
<Grid>
|
||||
<materialDesign:PackIcon Kind="LoginVariant" Width="48" Height="48" Margin="54,0,0,0" VerticalAlignment="Center"/>
|
||||
<TextBlock Style="{StaticResource MaterialDesignHeadline3TextBlock}" Text="登录" HorizontalAlignment="Left" Margin="107,0,0,4"/>
|
||||
</Grid>
|
||||
<Grid Width="280">
|
||||
<StackPanel>
|
||||
<TextBox VerticalAlignment="Top" materialDesign:HintAssist.Hint="用户名" Text="{Binding UserName}" Style="{StaticResource MaterialDesignOutlinedTextBox}" Margin="0,2,0,5"/>
|
||||
<PasswordBox VerticalContentAlignment="Bottom" materialDesign:HintAssist.Hint="密码"
|
||||
materialDesign:TextFieldAssist.HasClearButton="False" Margin="0,10,0,5"
|
||||
materialDesign:PasswordBoxAssist.Password="{Binding UserPassword}"
|
||||
Style="{StaticResource MaterialDesignOutlinedRevealPasswordBox}"/>
|
||||
<Grid>
|
||||
<CheckBox Content="记住我" IsChecked="{Binding SaveAccount}"/>
|
||||
<TextBlock x:Name="LoginMsg" Text="" Style="{StaticResource MaterialDesignBody2TextBlock}" HorizontalAlignment="Right" Foreground="#FFCC3333"/>
|
||||
</Grid>
|
||||
<Button Content="登录" Margin="0,20,0,0" Click="Login_Click" Style="{StaticResource MaterialDesignRaisedButton}" ToolTip="登录账号" FontWeight="Normal"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
<TabItem Header="注册账号">
|
||||
<Grid Background="#FFE5E5E5">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="0.8*"/>
|
||||
<RowDefinition Height="6*"/>
|
||||
<RowDefinition Height="1*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="10" Cursor="Hand">
|
||||
<StackPanel>
|
||||
<Grid>
|
||||
<materialDesign:PackIcon Kind="LoginVariant" Width="48" Height="48" Margin="54,0,0,0" VerticalAlignment="Center"/>
|
||||
<TextBlock Style="{StaticResource MaterialDesignHeadline3TextBlock}" Text="注册" HorizontalAlignment="Left" Margin="107,0,0,4"/>
|
||||
</Grid>
|
||||
<Grid Width="280">
|
||||
<StackPanel>
|
||||
<TextBox VerticalAlignment="Top" materialDesign:HintAssist.Hint="用户名" Text="{Binding SignName}" Style="{StaticResource MaterialDesignOutlinedTextBox}" Margin="0,2,0,5"/>
|
||||
<PasswordBox VerticalContentAlignment="Bottom" materialDesign:HintAssist.Hint="密码"
|
||||
materialDesign:TextFieldAssist.HasClearButton="False" Margin="0,10,0,5"
|
||||
materialDesign:PasswordBoxAssist.Password="{Binding SignPassword1}"
|
||||
Style="{StaticResource MaterialDesignOutlinedRevealPasswordBox}"/>
|
||||
<PasswordBox VerticalContentAlignment="Bottom" materialDesign:HintAssist.Hint="确认密码"
|
||||
materialDesign:TextFieldAssist.HasClearButton="False" Margin="0,10,0,5"
|
||||
materialDesign:PasswordBoxAssist.Password="{Binding SignPassword2}"
|
||||
Style="{StaticResource MaterialDesignOutlinedRevealPasswordBox}"/>
|
||||
<Grid>
|
||||
<CheckBox Content="记住我" IsChecked="{Binding SaveAccount}"/>
|
||||
<TextBlock Text="{Binding SignMsg}" Style="{StaticResource MaterialDesignBody2TextBlock}" HorizontalAlignment="Right" Foreground="#FFCC3333"/>
|
||||
</Grid>
|
||||
<Button Content="注册" Margin="0,20,0,0" Click="Sign_Click" Style="{StaticResource MaterialDesignRaisedButton}" ToolTip="注册账号" FontWeight="Normal"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
|
||||
</Window>
|
403
chatclient/LoginWindow.xaml.cs
Normal file
403
chatclient/LoginWindow.xaml.cs
Normal file
@ -0,0 +1,403 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
>>>>>>> 添加基础功能
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
>>>>>>> ui编辑
|
||||
=======
|
||||
>>>>>>> 添加基础功能
|
||||
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;
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
>>>>>>> 添加基础功能
|
||||
using System.Net.Sockets;
|
||||
using System.IO;
|
||||
using log4net;
|
||||
using log4net.Config;
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
using System.Windows.Interop;
|
||||
using chatapi;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
=======
|
||||
>>>>>>> ui编辑
|
||||
=======
|
||||
=======
|
||||
using System.Windows.Interop;
|
||||
using chatapi;
|
||||
using System.Runtime.CompilerServices;
|
||||
>>>>>>> 添加登录ui以及部分交互逻辑
|
||||
|
||||
>>>>>>> 添加基础功能
|
||||
|
||||
namespace chatclient
|
||||
{
|
||||
/// <summary>
|
||||
/// LoginWindow.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
public partial class LoginWindow : Window, INotifyPropertyChanged
|
||||
{
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(LoginWindow));
|
||||
static string? receive;
|
||||
public LoginWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.DataContext = this;
|
||||
}
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
private void Update(string UpdateName)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(UpdateName));
|
||||
}
|
||||
public static string UserName { get; set; } = "";
|
||||
public static string UserPassword { get; set; } = "";
|
||||
public static string SignName { get; set; } = "";
|
||||
public static string SignPassword1 { get; set; } = "";
|
||||
public static string SignPassword2 { get; set; } = "";
|
||||
private string? _SignMsg;
|
||||
public string? SignMsg
|
||||
{
|
||||
get { return _SignMsg; }
|
||||
set
|
||||
{
|
||||
_SignMsg = value;
|
||||
Update("SignMsg");
|
||||
}
|
||||
}
|
||||
private bool _SaveAccount;
|
||||
public bool SaveAccount
|
||||
{
|
||||
get { return _SaveAccount; }
|
||||
set
|
||||
{
|
||||
_SaveAccount = value;
|
||||
Update("SaveAccount");
|
||||
}
|
||||
}
|
||||
private void Login_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (UserName == "")
|
||||
{
|
||||
LoginMsg.Text = "用户名不能为空";
|
||||
}
|
||||
else if (UserPassword == "")
|
||||
{
|
||||
LoginMsg.Text = "密码不能为空";
|
||||
}
|
||||
else
|
||||
{
|
||||
var LoginData = new
|
||||
{
|
||||
type = "login",
|
||||
username = UserName,
|
||||
password = UserPassword
|
||||
};
|
||||
string LoginJsonData = JsonSerializer.Serialize(LoginData);
|
||||
byte[] dataBytes = Encoding.UTF8.GetBytes(LoginJsonData);
|
||||
log.Info($"向服务器发送登录请求(UserName:{UserName})");
|
||||
if (MainWindow.Client is not null)
|
||||
{
|
||||
if (MainWindow.Client.Connected)
|
||||
{
|
||||
MainWindow.Client.Send(dataBytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
log.Info("未连接服务器,尝试连接");
|
||||
MainWindow.Client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
MainWindow.Client.Connect("127.0.0.1", 5555);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.Error(ex);
|
||||
MainWindow.Client.Close();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LoginMsg.Text = "服务器连接失败或已断开连接";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void Sign_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (SignName == "")
|
||||
{
|
||||
SignMsg = "用户名不能为空";
|
||||
}
|
||||
else if (SignPassword1 == "")
|
||||
{
|
||||
SignMsg = "密码不能为空";
|
||||
}
|
||||
else if (SignPassword2 == "")
|
||||
{
|
||||
SignMsg = "请再次确认密码";
|
||||
}
|
||||
else if (SignPassword1 != SignPassword2)
|
||||
{
|
||||
SignMsg = "两次密码输入不一致";
|
||||
}
|
||||
else
|
||||
{
|
||||
var SignData = new
|
||||
{
|
||||
type = "register",
|
||||
username = SignName,
|
||||
password = SignPassword1
|
||||
};
|
||||
string SignJsonData = JsonSerializer.Serialize(SignData);
|
||||
byte[] dataBytes = Encoding.UTF8.GetBytes(SignJsonData);
|
||||
log.Info($"向服务器发送注册请求(UserName:{SignName})");
|
||||
Update("LoginMsg");
|
||||
if (MainWindow.Client is not null)
|
||||
{
|
||||
if (MainWindow.Client.Connected)
|
||||
{
|
||||
Thread th = new Thread(LoginReceive);
|
||||
th.Start();
|
||||
MainWindow.Client.Send(dataBytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
log.Info("未连接服务器,尝试连接");
|
||||
MainWindow.Client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
MainWindow.Client.Connect("127.0.0.1", 5555);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.Error(ex);
|
||||
MainWindow.Client.Close();
|
||||
}
|
||||
finally
|
||||
{
|
||||
SignMsg = "服务器连接失败或已断开连接";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
static void LoginReceive()
|
||||
{
|
||||
byte[] buffer = new byte[1024];
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
int num = MainWindow.Client!.Receive(buffer);
|
||||
if (num == 0) break;
|
||||
if (MainWindow.Client.Poll(100, SelectMode.SelectRead) && MainWindow.Client.Available == 0 || !MainWindow.Client.Connected)
|
||||
{
|
||||
log.Error("连接已断开");
|
||||
break;
|
||||
}
|
||||
receive = Encoding.UTF8.GetString(buffer, 0, num);
|
||||
response(receive);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.Error(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
MainWindow.Client?.Close();
|
||||
}
|
||||
}
|
||||
static void response(string msg)
|
||||
{
|
||||
LoginData data = JsonSerializer.Deserialize<LoginData>(msg)!;
|
||||
if (data.success)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//LoginWindow.Instance.LoginMsg.Text = msg;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
=======
|
||||
public partial class LoginWindow : Window
|
||||
=======
|
||||
public partial class LoginWindow : Window,INotifyPropertyChanged
|
||||
>>>>>>> 添加基础功能
|
||||
=======
|
||||
public partial class LoginWindow : Window, INotifyPropertyChanged
|
||||
>>>>>>> 添加登录ui以及部分交互逻辑
|
||||
{
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(LoginWindow));
|
||||
public LoginWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.DataContext = this;
|
||||
}
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
private void Update(string UpdateName)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(UpdateName));
|
||||
}
|
||||
public static string UserName { get; set; } = "";
|
||||
public static string UserPassword { get; set; } = "";
|
||||
public static string SignName { get; set; } = "";
|
||||
public static string SignPassword1 { get; set; } = "";
|
||||
public static string SignPassword2 { get; set; } = "";
|
||||
private string? _SignMsg;
|
||||
public string? SignMsg
|
||||
{
|
||||
get { return _SignMsg; }
|
||||
set
|
||||
{
|
||||
_SignMsg = value;
|
||||
Update("SignMsg");
|
||||
}
|
||||
}
|
||||
private bool _SaveAccount;
|
||||
public bool SaveAccount
|
||||
{
|
||||
get { return _SaveAccount; }
|
||||
set
|
||||
{
|
||||
_SaveAccount = value;
|
||||
Update("SaveAccount");
|
||||
}
|
||||
}
|
||||
private void Login_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (UserName == "")
|
||||
{
|
||||
LoginMsg.Text = "用户名不能为空";
|
||||
}
|
||||
else if (UserPassword == "")
|
||||
{
|
||||
LoginMsg.Text = "密码不能为空";
|
||||
}
|
||||
else
|
||||
{
|
||||
var LoginData = new
|
||||
{
|
||||
type = "login",
|
||||
username = UserName,
|
||||
password = UserPassword
|
||||
};
|
||||
string LoginJsonData = JsonSerializer.Serialize(LoginData);
|
||||
byte[] dataBytes = Encoding.UTF8.GetBytes(LoginJsonData);
|
||||
log.Info($"向服务器发送登录请求(UserName:{UserName})");
|
||||
if (MainWindow.Client is not null)
|
||||
{
|
||||
if (MainWindow.Client.Connected)
|
||||
{
|
||||
MainWindow.Client.Send(dataBytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
log.Info("未连接服务器,尝试连接");
|
||||
MainWindow.Client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
MainWindow.Client.Connect("127.0.0.1", 5555);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.Error(ex);
|
||||
MainWindow.Client.Close();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LoginMsg.Text = "服务器连接失败或已断开连接";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void Sign_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (SignName == "")
|
||||
{
|
||||
SignMsg = "用户名不能为空";
|
||||
}
|
||||
else if (SignPassword1 == "")
|
||||
{
|
||||
SignMsg = "密码不能为空";
|
||||
}
|
||||
else if (SignPassword2 == "")
|
||||
{
|
||||
SignMsg = "请再次确认密码";
|
||||
}
|
||||
else if (SignPassword1 != SignPassword2)
|
||||
{
|
||||
SignMsg = "两次密码输入不一致";
|
||||
}
|
||||
else
|
||||
{
|
||||
var SignData = new
|
||||
{
|
||||
type = "register",
|
||||
username = SignName,
|
||||
password = SignPassword1
|
||||
};
|
||||
string SignJsonData = JsonSerializer.Serialize(SignData);
|
||||
byte[] dataBytes = Encoding.UTF8.GetBytes(SignJsonData);
|
||||
log.Info($"向服务器发送注册请求(UserName:{SignName})");
|
||||
Update("LoginMsg");
|
||||
if (MainWindow.Client is not null)
|
||||
{
|
||||
if (MainWindow.Client.Connected)
|
||||
{
|
||||
MainWindow.Client.Send(dataBytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
log.Info("未连接服务器,尝试连接");
|
||||
MainWindow.Client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
MainWindow.Client.Connect("127.0.0.1", 5555);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.Error(ex);
|
||||
MainWindow.Client.Close();
|
||||
}
|
||||
finally
|
||||
{
|
||||
SignMsg = "服务器连接失败或已断开连接";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
|
||||
>>>>>>> ui编辑
|
||||
=======
|
||||
>>>>>>> 添加基础功能
|
||||
}
|
||||
}
|
44
chatclient/MainWindow.xaml
Normal file
44
chatclient/MainWindow.xaml
Normal file
@ -0,0 +1,44 @@
|
||||
<Window x:Class="chatclient.MainWindow"
|
||||
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:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:local="clr-namespace:chatclient"
|
||||
mc:Ignorable="d"
|
||||
Title="ChatWindow" Height="450" Width="800" MinHeight="240" MinWidth="380"
|
||||
Style="{StaticResource MaterialDesignWindow}">
|
||||
<Grid>
|
||||
<materialDesign:Card>
|
||||
<TabControl VerticalContentAlignment="Bottom" materialDesign:ColorZoneAssist.Mode="PrimaryMid" Style="{StaticResource MaterialDesignNavigationRailTabControl}">
|
||||
<materialDesign:NavigationRailAssist.FloatingContent>
|
||||
<Button Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}" Margin="12" ToolTip="name">
|
||||
<Image Source="/user.png" />
|
||||
</Button>
|
||||
</materialDesign:NavigationRailAssist.FloatingContent>
|
||||
<TabItem>
|
||||
<TabItem.Header>
|
||||
<StackPanel Width="auto" Height="auto">
|
||||
<materialDesign:PackIcon Width="24" Height="24" HorizontalAlignment="Center" Kind="Message" />
|
||||
<TextBlock HorizontalAlignment="Center" Text="消息" />
|
||||
</StackPanel>
|
||||
</TabItem.Header>
|
||||
<Grid>
|
||||
|
||||
</Grid>
|
||||
</TabItem>
|
||||
<TabItem>
|
||||
<TabItem.Header>
|
||||
<StackPanel Width="auto" Height="auto">
|
||||
<materialDesign:PackIcon Width="24" Height="24" HorizontalAlignment="Center" Kind="Cog" />
|
||||
<TextBlock HorizontalAlignment="Center" Text="设置" />
|
||||
</StackPanel>
|
||||
</TabItem.Header>
|
||||
<StackPanel>
|
||||
<TextBlock Text="这里没有东西..."/>
|
||||
</StackPanel>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
</materialDesign:Card>
|
||||
</Grid>
|
||||
</Window>
|
183
chatclient/MainWindow.xaml.cs
Normal file
183
chatclient/MainWindow.xaml.cs
Normal file
@ -0,0 +1,183 @@
|
||||
using System.Text;
|
||||
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;
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
>>>>>>> 添加基础功能
|
||||
using System.Net.Sockets;
|
||||
using System.Net;
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.Security.Policy;
|
||||
using log4net;
|
||||
using log4net.Config;
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
>>>>>>> 添加登录ui以及部分交互逻辑
|
||||
using System.Text.Json;
|
||||
using chatapi;
|
||||
using System.Diagnostics;
|
||||
using System.Windows.Interop;
|
||||
using ControlzEx.Standard;
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
>>>>>>> 添加基础功能
|
||||
|
||||
[assembly: XmlConfigurator(ConfigFile = "config/log4net.config", Watch = true)]
|
||||
=======
|
||||
|
||||
>>>>>>> 添加项目文件。
|
||||
=======
|
||||
|
||||
[assembly: XmlConfigurator(ConfigFile = "config/log4net.config", Watch = true)]
|
||||
>>>>>>> 添加登录ui以及部分交互逻辑
|
||||
namespace chatclient
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
LoginWindow Login = new();
|
||||
static string? receive;
|
||||
public static int user_id = 0;
|
||||
public static string? LoginMsg = "123";
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(MainWindow));
|
||||
public static Socket? Client;
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
log.Info("Hello World!");
|
||||
this.Hide();
|
||||
Client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
try
|
||||
{
|
||||
log.Info("连接服务器 127.0.0.1:5555 ");
|
||||
Client.Connect("127.0.0.1", 5555);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Client.Close();
|
||||
log.Error(ex);
|
||||
}
|
||||
Login.Show();
|
||||
Thread th = new Thread(Receive);
|
||||
th.Start();
|
||||
}
|
||||
static void Receive()
|
||||
{
|
||||
byte[] buffer = new byte[1024];
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
int num = Client!.Receive(buffer);
|
||||
if (num == 0) break;
|
||||
if (Client.Poll(100, SelectMode.SelectRead) && Client.Available == 0 || !Client.Connected)
|
||||
{
|
||||
log.Error("连接已断开");
|
||||
break;
|
||||
}
|
||||
receive = Encoding.UTF8.GetString(buffer, 0, num);
|
||||
response(receive);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
log.Error(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Client?.Close();
|
||||
}
|
||||
}
|
||||
static void response(string msg)
|
||||
{
|
||||
|
||||
=======
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
>>>>>>> 添加项目文件。
|
||||
=======
|
||||
=======
|
||||
LoginWindow Login = new();
|
||||
>>>>>>> 添加登录ui以及部分交互逻辑
|
||||
static string? receive;
|
||||
public static int user_id = 0;
|
||||
public static string? LoginMsg = "123";
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(MainWindow));
|
||||
public static Socket? Client;
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
log.Info("Hello World!");
|
||||
this.Hide();
|
||||
Client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
try
|
||||
{
|
||||
log.Info("连接服务器 127.0.0.1:5555 ");
|
||||
Client.Connect("127.0.0.1", 5555);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Client.Close();
|
||||
log.Error(ex);
|
||||
}
|
||||
Login.Show();
|
||||
Thread th = new Thread(Receive);
|
||||
th.Start();
|
||||
>>>>>>> 添加基础功能
|
||||
}
|
||||
static void Receive()
|
||||
{
|
||||
byte[] buffer = new byte[1024];
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
int num = Client!.Receive(buffer);
|
||||
if (num == 0) break;
|
||||
if (Client.Poll(100, SelectMode.SelectRead) && Client.Available == 0 || !Client.Connected)
|
||||
{
|
||||
log.Error("连接已断开");
|
||||
break;
|
||||
}
|
||||
receive = Encoding.UTF8.GetString(buffer, 0, num);
|
||||
response(receive);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
log.Error(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Client?.Close();
|
||||
}
|
||||
}
|
||||
static void response(string msg)
|
||||
{
|
||||
LoginData data = JsonSerializer.Deserialize<LoginData>(msg)!;
|
||||
|
||||
if (data.success) {
|
||||
|
||||
}
|
||||
else {
|
||||
//LoginWindow.Instance.LoginMsg.Text = msg;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
22
chatclient/chatapi.cs
Normal file
22
chatclient/chatapi.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace chatapi
|
||||
{
|
||||
internal class LoginData
|
||||
{
|
||||
public bool success { get; set; }
|
||||
public string? message { get; set; }
|
||||
public string? token { get; set; }
|
||||
public int? user_id { get; set; }
|
||||
public string? username { get; set; }
|
||||
}
|
||||
internal class RegisterData
|
||||
{
|
||||
public bool success { get; set; }
|
||||
public string? message { get; set; }
|
||||
}
|
||||
}
|
28
chatclient/chatclient.csproj
Normal file
28
chatclient/chatclient.csproj
Normal file
@ -0,0 +1,28 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="log4net" Version="3.1.0" />
|
||||
<PackageReference Include="MaterialDesignThemes" Version="5.2.1" />
|
||||
<PackageReference Include="MaterialDesignThemes.MahApps" Version="5.2.1" />
|
||||
<PackageReference Include="MaterialDesignThemes.Wpf" Version="1.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Resource Include="user.png" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="config\log4net.config">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
9
chatclient/chatclient.csproj.user
Normal file
9
chatclient/chatclient.csproj.user
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
<ItemGroup>
|
||||
<Compile Update="LoginWindow.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
</Project>
|
21
chatclient/config/log4net.config
Normal file
21
chatclient/config/log4net.config
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<log4net>
|
||||
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
|
||||
<datePattern value="yyyyMM\\yyyyMMdd'_chat.log'" />
|
||||
<encoding value="utf-8" />
|
||||
<file value="..\\..\\log\\" />
|
||||
<appendToFile value="true" />
|
||||
<rollingStyle value="Date" />
|
||||
<staticLogFileName value="false" />
|
||||
<param name="MaxSizeRollBackups" value="100" />
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="[%date %thread %-5level %logger]%ndc - %message%newline" />
|
||||
</layout>
|
||||
</appender>
|
||||
<root>
|
||||
<level value="All" />
|
||||
<appender-ref ref="RollingLogFileAppender" />
|
||||
</root>
|
||||
</log4net>
|
||||
</configuration>
|
BIN
chatclient/user.png
Normal file
BIN
chatclient/user.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.8 KiB |
Loading…
x
Reference in New Issue
Block a user