修改服务器端在线客户端信息的呈现
This commit is contained in:
@@ -44,7 +44,7 @@ namespace ClientsLibrary
|
||||
/// 服务器的IP地址,默认为127.0.0.1,可用于单机调试,
|
||||
/// 云服务器端:117.48.203.204,注意,云端为最新版,客户端版本比较旧会调试失败
|
||||
/// </summary>
|
||||
public static string ServerIp { get; } = "117.48.203.204"; // 用于测试的云服务器地址
|
||||
public static string ServerIp { get; } = "127.0.0.1"; // 用于测试的云服务器地址
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -10,33 +10,97 @@ namespace CommonLibrary
|
||||
/// </summary>
|
||||
public class NetAccount
|
||||
{
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// 实例化一个默认的构造函数
|
||||
/// </summary>
|
||||
public NetAccount( )
|
||||
{
|
||||
LoginTime = DateTime.Now;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 唯一的用户名
|
||||
/// </summary>
|
||||
public string UserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 别名
|
||||
/// </summary>
|
||||
public string Alias { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ip地址
|
||||
/// </summary>
|
||||
public string IpAddress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 工厂或是部分分类
|
||||
/// </summary>
|
||||
public string Factory { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 登陆时间
|
||||
/// </summary>
|
||||
public DateTime LoginTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 包含的角色名称
|
||||
/// </summary>
|
||||
public string[] Roles { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 本地连接唯一的身份标识
|
||||
/// </summary>
|
||||
public string UniqueId { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Method
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前客户端的在线时间的文本描述方式
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetOnlineTime( )
|
||||
{
|
||||
TimeSpan timeSpan = DateTime.Now - LoginTime;
|
||||
if (timeSpan.TotalSeconds < 60)
|
||||
{
|
||||
return timeSpan.Seconds.ToString( );
|
||||
}
|
||||
else if (timeSpan.TotalMinutes < 60)
|
||||
{
|
||||
return timeSpan.Minutes + " : " + timeSpan.Seconds;
|
||||
}
|
||||
else if (timeSpan.TotalHours < 24)
|
||||
{
|
||||
return timeSpan.Hours + " : " + timeSpan.Minutes + " : " + timeSpan.Seconds;
|
||||
}
|
||||
else
|
||||
{
|
||||
return timeSpan.Days + " D " + timeSpan.Hours + " : " + timeSpan.Minutes + " : ";
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Object Override
|
||||
|
||||
/// <summary>
|
||||
/// 返回表示当前对象的字符串
|
||||
/// </summary>
|
||||
/// <returns>字符串</returns>
|
||||
public override string ToString( ) => $"{IpAddress} [ {(string.IsNullOrEmpty( Alias ) ? UserName : Alias)} ] [ {GetOnlineTime( )} ]";
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,27 @@ namespace 软件系统服务端模版.BasicSupport
|
||||
|
||||
#region Public Method
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有在线客户端的信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string[] GetOnlineInformation()
|
||||
{
|
||||
string[] result = null;
|
||||
|
||||
hybirdLock.Enter( );
|
||||
result = new string[OnlineClients.Count];
|
||||
|
||||
for (int i = 0; i < result.Length; i++)
|
||||
{
|
||||
result[i] = OnlineClients[i].ToString( );
|
||||
}
|
||||
|
||||
hybirdLock.Leave( );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 新增一个在线的客户端
|
||||
|
||||
27
软件系统服务端模版/FormServerWindow.Designer.cs
generated
27
软件系统服务端模版/FormServerWindow.Designer.cs
generated
@@ -69,6 +69,7 @@
|
||||
//
|
||||
// statusStrip1
|
||||
//
|
||||
this.statusStrip1.BackColor = System.Drawing.Color.AliceBlue;
|
||||
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.toolStripStatusLabel1,
|
||||
this.toolStripStatusLabel2,
|
||||
@@ -294,42 +295,45 @@
|
||||
//
|
||||
this.label6.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.label6.AutoSize = true;
|
||||
this.label6.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.label6.Location = new System.Drawing.Point(564, 37);
|
||||
this.label6.Name = "label6";
|
||||
this.label6.Size = new System.Drawing.Size(59, 17);
|
||||
this.label6.Size = new System.Drawing.Size(74, 21);
|
||||
this.label6.TabIndex = 14;
|
||||
this.label6.Text = "对象内存:";
|
||||
this.label6.Text = "Simplify:";
|
||||
//
|
||||
// label7
|
||||
//
|
||||
this.label7.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.label7.AutoSize = true;
|
||||
this.label7.Location = new System.Drawing.Point(564, 58);
|
||||
this.label7.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.label7.Location = new System.Drawing.Point(564, 68);
|
||||
this.label7.Name = "label7";
|
||||
this.label7.Size = new System.Drawing.Size(59, 17);
|
||||
this.label7.Size = new System.Drawing.Size(51, 21);
|
||||
this.label7.TabIndex = 15;
|
||||
this.label7.Text = "进程内存:";
|
||||
this.label7.Text = "Push:";
|
||||
//
|
||||
// label_GC_Memery
|
||||
//
|
||||
this.label_GC_Memery.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.label_GC_Memery.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.label_GC_Memery.Cursor = System.Windows.Forms.Cursors.Hand;
|
||||
this.label_GC_Memery.Location = new System.Drawing.Point(629, 37);
|
||||
this.label_GC_Memery.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.label_GC_Memery.Location = new System.Drawing.Point(648, 37);
|
||||
this.label_GC_Memery.Name = "label_GC_Memery";
|
||||
this.label_GC_Memery.Size = new System.Drawing.Size(125, 17);
|
||||
this.label_GC_Memery.Size = new System.Drawing.Size(108, 24);
|
||||
this.label_GC_Memery.TabIndex = 16;
|
||||
this.label_GC_Memery.Text = "0";
|
||||
this.label_GC_Memery.TextAlign = System.Drawing.ContentAlignment.TopRight;
|
||||
this.label_GC_Memery.Click += new System.EventHandler(this.label_GC_Memery_Click);
|
||||
//
|
||||
// label_Pm_Memery
|
||||
//
|
||||
this.label_Pm_Memery.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.label_Pm_Memery.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.label_Pm_Memery.Location = new System.Drawing.Point(629, 58);
|
||||
this.label_Pm_Memery.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.label_Pm_Memery.Location = new System.Drawing.Point(648, 67);
|
||||
this.label_Pm_Memery.Name = "label_Pm_Memery";
|
||||
this.label_Pm_Memery.Size = new System.Drawing.Size(125, 17);
|
||||
this.label_Pm_Memery.Size = new System.Drawing.Size(108, 24);
|
||||
this.label_Pm_Memery.TabIndex = 17;
|
||||
this.label_Pm_Memery.Text = "0";
|
||||
this.label_Pm_Memery.TextAlign = System.Drawing.ContentAlignment.TopRight;
|
||||
@@ -338,6 +342,7 @@
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.BackColor = System.Drawing.Color.AliceBlue;
|
||||
this.ClientSize = new System.Drawing.Size(764, 481);
|
||||
this.Controls.Add(this.label_Pm_Memery);
|
||||
this.Controls.Add(this.label_GC_Memery);
|
||||
@@ -396,11 +401,11 @@
|
||||
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel_time;
|
||||
private System.Windows.Forms.ToolStripMenuItem 框架作者ToolStripMenuItem;
|
||||
private System.Windows.Forms.Label label5;
|
||||
private System.Windows.Forms.ToolStripMenuItem 日志查看ToolStripMenuItem;
|
||||
private System.Windows.Forms.Label label6;
|
||||
private System.Windows.Forms.Label label7;
|
||||
private System.Windows.Forms.Label label_GC_Memery;
|
||||
private System.Windows.Forms.Label label_Pm_Memery;
|
||||
private System.Windows.Forms.ToolStripMenuItem 日志查看ToolStripMenuItem;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -223,12 +223,12 @@ namespace 软件系统服务端模版
|
||||
// Start Server
|
||||
if (!IsSystemStart)
|
||||
{
|
||||
Net_Simplify_Server_Initialization();//同步网络初始化
|
||||
Net_Socket_Server_Initialization();//异步网络初始化
|
||||
Net_SoftUpdate_Server_Initialization();//软件更新引擎初始化
|
||||
Ultimate_File_Initiaization();//共享文件引擎初始化
|
||||
Net_File_Portrait_Initialization();//头像文件管理服务
|
||||
Net_Udp_Server_Initialization();//UDP引擎服务初始化
|
||||
Net_Simplify_Server_Initialization(); // 同步网络初始化
|
||||
Net_Socket_Server_Initialization(); // 异步网络初始化
|
||||
Net_SoftUpdate_Server_Initialization(); // 软件更新引擎初始化
|
||||
Ultimate_File_Initiaization(); // 共享文件引擎初始化
|
||||
Net_File_Portrait_Initialization(); // 头像文件管理服务
|
||||
Net_Udp_Server_Initialization(); // UDP引擎服务初始化
|
||||
启动服务器ToolStripMenuItem.Text = "已启动";
|
||||
启动服务器ToolStripMenuItem.BackColor = Color.LimeGreen;
|
||||
IsSystemStart = true;
|
||||
@@ -256,9 +256,9 @@ namespace 软件系统服务端模版
|
||||
|
||||
private void 消息发送ToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
//测试发送字节数据
|
||||
//net_socket_server.SendAllClients(BitConverter.GetBytes(12345678));
|
||||
//将消息群发给所有的客户端,并使用消息弹窗的方式显示
|
||||
// 测试发送字节数据
|
||||
// net_socket_server.SendAllClients(BitConverter.GetBytes(12345678));
|
||||
// 将消息群发给所有的客户端,并使用消息弹窗的方式显示
|
||||
using (FormInputAndAction fiaa = new FormInputAndAction(
|
||||
m =>
|
||||
{
|
||||
@@ -271,7 +271,7 @@ namespace 软件系统服务端模版
|
||||
|
||||
private void 一键断开ToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
//关闭信号发送至所有在线客户端
|
||||
// 关闭信号发送至所有在线客户端
|
||||
net_socket_server.SendAllClients(CommonHeadCode.MultiNetHeadCode.关闭客户端, "");
|
||||
}
|
||||
|
||||
@@ -296,7 +296,7 @@ namespace 软件系统服务端模版
|
||||
}
|
||||
private void 账户管理ToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
//该部分比较复杂,需要对委托,匿名委托概念比较清晰
|
||||
// 该部分比较复杂,需要对委托,匿名委托概念比较清晰
|
||||
using (FormAccountManage fam = new FormAccountManage(() => UserServer.ServerAccounts.GetAllAccountsJson(),
|
||||
m => { UserServer.ServerAccounts.LoadAllAccountsJson(m); return true; }))
|
||||
{
|
||||
@@ -313,32 +313,19 @@ namespace 软件系统服务端模版
|
||||
}
|
||||
private void MaintenanceInitialization()
|
||||
{
|
||||
//维护状态变更
|
||||
// 维护状态变更
|
||||
if (UserServer.ServerSettings.Can_Account_Login)
|
||||
{
|
||||
label3.Text = "可登录";
|
||||
label3.Text = "可登录"; // Login Enabled True
|
||||
label3.BackColor = Color.LimeGreen;
|
||||
}
|
||||
else
|
||||
{
|
||||
label3.Text = "维护中";
|
||||
label3.Text = "维护中"; // Login Enabled False
|
||||
label3.BackColor = Color.Tomato;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void label_GC_Memery_Click(object sender, EventArgs e)
|
||||
{
|
||||
//点击了性能组件
|
||||
using (FormSuper fs = new FormSuper(() =>
|
||||
{
|
||||
return SoftCachePerfomance.GetIntArray();
|
||||
}))
|
||||
{
|
||||
fs.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void 日志查看ToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
using (FormLogNetView fln = new FormLogNetView())
|
||||
@@ -412,16 +399,9 @@ namespace 软件系统服务端模版
|
||||
/// <param name="session">网络状态</param>
|
||||
/// <param name="customer">字节数据,根据实际情况选择是否使用</param>
|
||||
/// <param name="data">来自客户端的字节数据</param>
|
||||
private void Net_simplify_server_ReceivedBytesEvent(AppSession session, NetHandle customer, byte[] data)
|
||||
private void Net_simplify_server_ReceivedBytesEvent( AppSession session, NetHandle customer, byte[] data )
|
||||
{
|
||||
if(customer==CommonHeadCode.SimplifyHeadCode.性能计数)
|
||||
{
|
||||
net_simplify_server.SendMessage(session, customer, GetPerfomace());
|
||||
}
|
||||
else
|
||||
{
|
||||
net_simplify_server.SendMessage(session, customer, data);
|
||||
}
|
||||
net_simplify_server.SendMessage( session, customer, data );
|
||||
}
|
||||
|
||||
|
||||
@@ -1045,7 +1025,6 @@ namespace 软件系统服务端模版
|
||||
{
|
||||
// 此处决定要不要将在线客户端的数据发送所有客户端
|
||||
// net_socket_server.SendAllClients(CommonHeadCode.MultiNetHeadCode.总在线信息, netAccountManager.ClientsOnlineCache);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1084,6 +1063,16 @@ namespace 软件系统服务端模版
|
||||
/// </summary>
|
||||
private NetAccountManager netAccountManager { get; set; } = new NetAccountManager();
|
||||
|
||||
/// <summary>
|
||||
/// 现在所有的在线客户端
|
||||
/// </summary>
|
||||
private void RenderOnlineAccount( )
|
||||
{
|
||||
string[] buffer = netAccountManager.GetOnlineInformation( );
|
||||
label4.Text = buffer.Length.ToString( );
|
||||
listBox1.DataSource = buffer;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Time Tick Thread
|
||||
@@ -1111,31 +1100,12 @@ namespace 软件系统服务端模版
|
||||
thread.Start();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 缓存的上次内存占用
|
||||
/// </summary>
|
||||
private long GC_Memery { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 程序的内存对象
|
||||
/// </summary>
|
||||
private long Pm_Memery { get; set; }
|
||||
|
||||
|
||||
private void MethodOccurEverySecond()
|
||||
private void MethodOccurEverySecond( )
|
||||
{
|
||||
long current1 = GC.GetTotalMemory(false);
|
||||
// 增加到性能计数
|
||||
AddPerfomace(current1);
|
||||
|
||||
long current2 = 0;
|
||||
toolStripStatusLabel_time.Text = DateTime.Now.ToString();
|
||||
label_GC_Memery.Text = current1.ToString();
|
||||
label_Pm_Memery.Text = "备用"; //current2.ToString();
|
||||
label_GC_Memery.BackColor = current1 < GC_Memery ? Color.Tomato : SystemColors.Control;
|
||||
label_Pm_Memery.BackColor = current2 < Pm_Memery ? Color.Tomato : SystemColors.Control;
|
||||
GC_Memery = current1;
|
||||
Pm_Memery = current2;
|
||||
toolStripStatusLabel_time.Text = DateTime.Now.ToString( );
|
||||
RenderOnlineAccount( );
|
||||
}
|
||||
|
||||
|
||||
@@ -1181,23 +1151,6 @@ namespace 软件系统服务端模版
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region 服务器内存性能缓存小模块
|
||||
|
||||
private SoftCacheArrayInt SoftCachePerfomance = new SoftCacheArrayInt(500, 0);
|
||||
|
||||
private void AddPerfomace(long value)
|
||||
{
|
||||
SoftCachePerfomance.AddValue((int)value);//虽然存在不安全隐患,但是几乎不可能大于20亿
|
||||
}
|
||||
|
||||
private byte[] GetPerfomace()
|
||||
{
|
||||
return SoftCachePerfomance.GetAllData();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Advanced File Server
|
||||
|
||||
Reference in New Issue
Block a user