using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CommonLibrary
{
///
/// 用于网络账户的在线情况监视
///
public class NetAccount
{
#region Constructor
///
/// 实例化一个默认的构造函数
///
public NetAccount( )
{
LoginTime = DateTime.Now;
}
#endregion
#region Public Properties
///
/// 唯一的用户名
///
public string UserName { get; set; }
///
/// 别名
///
public string Alias { get; set; }
///
/// ip地址
///
public string IpAddress { get; set; }
///
/// 工厂或是部分分类
///
public string Factory { get; set; }
///
/// 登陆时间
///
public DateTime LoginTime { get; set; }
///
/// 包含的角色名称
///
public string[] Roles { get; set; }
///
/// 本地连接唯一的身份标识
///
public string UniqueId { get; set; }
#endregion
#region Public Method
///
/// 获取当前客户端的在线时间的文本描述方式
///
///
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
///
/// 返回表示当前对象的字符串
///
/// 字符串
public override string ToString( ) => $"{IpAddress} [ {(string.IsNullOrEmpty( Alias ) ? UserName : Alias)} ] [ {GetOnlineTime( )} ]";
#endregion
}
}