已完成聊天交流平台的服务端消息缓存,测试缓存200条。
This commit is contained in:
16
软件系统客户端模版/FormMainWindow.Designer.cs
generated
16
软件系统客户端模版/FormMainWindow.Designer.cs
generated
@@ -43,6 +43,7 @@
|
|||||||
this.账户管理ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.账户管理ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.远程更新ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.远程更新ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.注册账号ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.注册账号ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.消息发送ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.设置ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.设置ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.修改密码ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.修改密码ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.留言板ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.留言板ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
@@ -75,7 +76,6 @@
|
|||||||
this.panel_left = new System.Windows.Forms.Panel();
|
this.panel_left = new System.Windows.Forms.Panel();
|
||||||
this.label10 = new System.Windows.Forms.Label();
|
this.label10 = new System.Windows.Forms.Label();
|
||||||
this.panel_main = new System.Windows.Forms.Panel();
|
this.panel_main = new System.Windows.Forms.Panel();
|
||||||
this.消息发送ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
|
||||||
this.statusStrip1.SuspendLayout();
|
this.statusStrip1.SuspendLayout();
|
||||||
this.menuStrip1.SuspendLayout();
|
this.menuStrip1.SuspendLayout();
|
||||||
this.panel_right.SuspendLayout();
|
this.panel_right.SuspendLayout();
|
||||||
@@ -206,6 +206,13 @@
|
|||||||
this.注册账号ToolStripMenuItem.Text = "注册账号";
|
this.注册账号ToolStripMenuItem.Text = "注册账号";
|
||||||
this.注册账号ToolStripMenuItem.Click += new System.EventHandler(this.注册账号ToolStripMenuItem_Click);
|
this.注册账号ToolStripMenuItem.Click += new System.EventHandler(this.注册账号ToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
|
// 消息发送ToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.消息发送ToolStripMenuItem.Name = "消息发送ToolStripMenuItem";
|
||||||
|
this.消息发送ToolStripMenuItem.Size = new System.Drawing.Size(164, 32);
|
||||||
|
this.消息发送ToolStripMenuItem.Text = "消息发送";
|
||||||
|
this.消息发送ToolStripMenuItem.Click += new System.EventHandler(this.消息发送ToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
// 设置ToolStripMenuItem
|
// 设置ToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.设置ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
this.设置ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
@@ -519,13 +526,6 @@
|
|||||||
this.panel_main.Size = new System.Drawing.Size(557, 419);
|
this.panel_main.Size = new System.Drawing.Size(557, 419);
|
||||||
this.panel_main.TabIndex = 5;
|
this.panel_main.TabIndex = 5;
|
||||||
//
|
//
|
||||||
// 消息发送ToolStripMenuItem
|
|
||||||
//
|
|
||||||
this.消息发送ToolStripMenuItem.Name = "消息发送ToolStripMenuItem";
|
|
||||||
this.消息发送ToolStripMenuItem.Size = new System.Drawing.Size(164, 32);
|
|
||||||
this.消息发送ToolStripMenuItem.Text = "消息发送";
|
|
||||||
this.消息发送ToolStripMenuItem.Click += new System.EventHandler(this.消息发送ToolStripMenuItem_Click);
|
|
||||||
//
|
|
||||||
// FormMainWindow
|
// FormMainWindow
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
||||||
|
|||||||
@@ -331,10 +331,14 @@ namespace 软件系统客户端模版
|
|||||||
//收到服务器的数据
|
//收到服务器的数据
|
||||||
JObject json = JObject.Parse(data);
|
JObject json = JObject.Parse(data);
|
||||||
UserClient.DateTimeServer = json["Time"].ToObject<DateTime>();
|
UserClient.DateTimeServer = json["Time"].ToObject<DateTime>();
|
||||||
|
List<string> chats = JArray.Parse(json["chats"].ToString()).ToObject<List<string>>();
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
chats.ForEach(m => { sb.Append(m + Environment.NewLine); });
|
||||||
if (IsHandleCreated) Invoke(new Action(() =>
|
if (IsHandleCreated) Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
toolStripStatusLabel_time.Text = UserClient.DateTimeServer.ToString("yyyy-MM-dd HH:mm");
|
toolStripStatusLabel_time.Text = UserClient.DateTimeServer.ToString("yyyy-MM-dd HH:mm");
|
||||||
label_file_count.Text = json["FileCount"].ToObject<int>().ToString();
|
label_file_count.Text = json["FileCount"].ToObject<int>().ToString();
|
||||||
|
UIControls_Chat.AddChatsHistory(sb.ToString());
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
else if (customer == CommonHeadCode.MultiNetHeadCode.文件总数量)
|
else if (customer == CommonHeadCode.MultiNetHeadCode.文件总数量)
|
||||||
|
|||||||
@@ -41,6 +41,14 @@ namespace 软件系统客户端模版.UIControls
|
|||||||
{
|
{
|
||||||
richTextBox1.AppendText(str + Environment.NewLine);
|
richTextBox1.AppendText(str + Environment.NewLine);
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 新增聊天的历史记录
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="str"></param>
|
||||||
|
public void AddChatsHistory(string str)
|
||||||
|
{
|
||||||
|
richTextBox1.Text = str;
|
||||||
|
}
|
||||||
|
|
||||||
public void InputFocus()
|
public void InputFocus()
|
||||||
{
|
{
|
||||||
|
|||||||
1
软件系统服务端模版/FormServerWindow.Designer.cs
generated
1
软件系统服务端模版/FormServerWindow.Designer.cs
generated
@@ -16,6 +16,7 @@
|
|||||||
//紧急存储数据
|
//紧急存储数据
|
||||||
UserServer.ServerSettings.SaveToFile();
|
UserServer.ServerSettings.SaveToFile();
|
||||||
UserServer.ServerAccounts.SaveToFile();
|
UserServer.ServerAccounts.SaveToFile();
|
||||||
|
Chats_Managment.SaveToFile();
|
||||||
|
|
||||||
if (disposing && (components != null))
|
if (disposing && (components != null))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -98,6 +98,8 @@ namespace 软件系统服务端模版
|
|||||||
UserServer.ServerAccounts.FileSavePath = Application.StartupPath + @"\accounts.txt";
|
UserServer.ServerAccounts.FileSavePath = Application.StartupPath + @"\accounts.txt";
|
||||||
UserServer.ServerAccounts.LoadByFile();
|
UserServer.ServerAccounts.LoadByFile();
|
||||||
UserServer.ServerAccounts.LogHelper = RuntimeLogHelper;
|
UserServer.ServerAccounts.LogHelper = RuntimeLogHelper;
|
||||||
|
//初始化聊天信息
|
||||||
|
ChatInitialization();
|
||||||
}
|
}
|
||||||
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
|
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
{
|
{
|
||||||
@@ -385,8 +387,10 @@ namespace 软件系统服务端模版
|
|||||||
}
|
}
|
||||||
else if (customer == CommonHeadCode.SimplifyHeadCode.参数下载)
|
else if (customer == CommonHeadCode.SimplifyHeadCode.参数下载)
|
||||||
{
|
{
|
||||||
Newtonsoft.Json.Linq.JObject json = new Newtonsoft.Json.Linq.JObject();
|
JObject json = new JObject
|
||||||
json.Add(nameof(UserServer.ServerSettings.Announcement), new Newtonsoft.Json.Linq.JValue(UserServer.ServerSettings.Announcement));
|
{
|
||||||
|
{ nameof(UserServer.ServerSettings.Announcement), new JValue(UserServer.ServerSettings.Announcement) }
|
||||||
|
};
|
||||||
net_simplify_server.SendMessage(state, customer, json.ToString());
|
net_simplify_server.SendMessage(state, customer, json.ToString());
|
||||||
}
|
}
|
||||||
else if (customer == CommonHeadCode.SimplifyHeadCode.账户检查)
|
else if (customer == CommonHeadCode.SimplifyHeadCode.账户检查)
|
||||||
@@ -636,9 +640,7 @@ namespace 软件系统服务端模版
|
|||||||
{
|
{
|
||||||
if (customer == CommonHeadCode.MultiNetHeadCode.留言版消息)
|
if (customer == CommonHeadCode.MultiNetHeadCode.留言版消息)
|
||||||
{
|
{
|
||||||
string content = state.LoginAlias + DateTime.Now.ToString(" yyyy-MM-dd HH:mm:ss") + Environment.NewLine + data;
|
ChatAddMessage(state.LoginAlias, data);
|
||||||
//转发所有的客户端,包括发送者
|
|
||||||
net_socket_server.SendAllClients(customer, content);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -672,13 +674,15 @@ namespace 软件系统服务端模版
|
|||||||
JObject json = new JObject
|
JObject json = new JObject
|
||||||
{
|
{
|
||||||
{ "Time", new JValue(DateTime.Now) },
|
{ "Time", new JValue(DateTime.Now) },
|
||||||
{ "FileCount", new JValue(net_simple_file_server.File_Count()) }
|
{ "FileCount", new JValue(net_simple_file_server.File_Count()) },
|
||||||
|
{ "chats", new JValue(Chats_Managment.ToSaveString())}
|
||||||
};
|
};
|
||||||
//发送客户端的初始化数据
|
//发送客户端的初始化数据
|
||||||
net_socket_server.Send(object1, CommonHeadCode.MultiNetHeadCode.初始化数据, json.ToString());
|
net_socket_server.Send(object1, CommonHeadCode.MultiNetHeadCode.初始化数据, json.ToString());
|
||||||
//触发上下线功能
|
//触发上下线功能
|
||||||
Net_socket_clients_change(DateTime.Now.ToString("MM-dd HH:mm:ss ") + object1._IpEnd_Point.Address.ToString() + ":" +
|
Net_socket_clients_change(DateTime.Now.ToString("MM-dd HH:mm:ss ") + object1._IpEnd_Point.Address.ToString() + ":" +
|
||||||
object1.LoginAlias + " 上线");
|
object1.LoginAlias + " 上线");
|
||||||
|
ChatAddMessage(object1.LoginAlias + " 上线");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -982,6 +986,25 @@ namespace 软件系统服务端模版
|
|||||||
Chats_Managment.LoadByFile();//加载以前的数据
|
Chats_Managment.LoadByFile();//加载以前的数据
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ChatAddMessage(string user,string message)
|
||||||
|
{
|
||||||
|
string content = "\u0002" + user + DateTime.Now.ToString(" yyyy-MM-dd HH:mm:ss") + Environment.NewLine + " " + message;
|
||||||
|
//转发所有的客户端,包括发送者
|
||||||
|
net_socket_server.SendAllClients(CommonHeadCode.MultiNetHeadCode.留言版消息, content);
|
||||||
|
//添加缓存
|
||||||
|
Chats_Managment.AddNewItem(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 如果需要发送一些系统自己的消息,请调用这个方法。
|
||||||
|
/// 一般来说将系统消息和用户聊天消息进行区分
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">消息</param>
|
||||||
|
private void ChatAddMessage(string message)
|
||||||
|
{
|
||||||
|
ChatAddMessage("[系统]", message);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user