修改服务器端在线客户端信息的呈现

This commit is contained in:
Richard.Hu
2018-05-07 22:26:39 +08:00
parent dc5d9fbbe3
commit c5ba15a95b
5 changed files with 132 additions and 89 deletions

View File

@@ -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>

View File

@@ -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
}
}

View File

@@ -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>
/// 新增一个在线的客户端

View File

@@ -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;
}
}

View File

@@ -316,29 +316,16 @@ namespace 软件系统服务端模版
// 维护状态变更
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())
@@ -413,16 +400,9 @@ namespace 软件系统服务端模版
/// <param name="customer">字节数据,根据实际情况选择是否使用</param>
/// <param name="data">来自客户端的字节数据</param>
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 );
}
}
@@ -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( )
{
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;
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