📄 impsloglistner.cs
字号:
namespace Imps.Client.Core
{
using Imps.Client.Resource;
using Imps.Client.Utils;
using Imps.Client.Utils.Information.Hardware;
using System;
using System.Globalization;
using System.Text;
public class ImpsLogListner : ILoginListner
{
private Imps.Client.Core.User curUser;
private const string DateTimeFormat = "yyyy-MM-dd HH:mm:ss.fff";
private StringBuilder loginLog = new StringBuilder();
private bool suspend;
public ImpsLogListner(Imps.Client.Core.User user)
{
if (user == null)
{
throw new NullReferenceException("user should not be null");
}
this.curUser = user;
this.BuildLogHeader(user);
}
private void AppendLog(string message)
{
this.loginLog.AppendFormat("[{0}]-{1}\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), message);
}
private void AppendLog(string message, Exception ex)
{
this.loginLog.AppendFormat("[{0}]-{1}\r\n\t{2}\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), message, (ex.InnerException != null) ? ex.InnerException.Message : string.Empty);
}
private void BuildLogHeader(Imps.Client.Core.User user)
{
string text = string.Format("【飞信版本】:{0}(Build {1}) - {2}", Imps.Client.Core.Configuration.FixedClientSetting.Version, Imps.Client.Core.Configuration.FixedClientSetting.BuildDate, Imps.Client.Core.Configuration.FixedClientSetting.Branch);
string text2 = Environment.OSVersion.ToString();
string name = CultureInfo.CurrentCulture.Name;
this.loginLog.AppendFormat("{0}\r\n", text);
this.loginLog.AppendFormat("【登录ID】:{0}\r\n", (user.Sid > 0) ? user.Sid.ToString() : user.MobileNo);
this.loginLog.AppendFormat("【操作系统】:{0} \r\n【默认语言】:{1}\r\n", text2, name);
this.loginLog.AppendFormat("【本机网络信息】:\r\n{0}\r\n", NetworkInfo.Instance.Network);
string text4 = "【候选连接方式】:";
if (Imps.Client.Core.NetworkSetting.Instance.UseDirect)
{
text4 = text4 + "\r\n\t直接连接";
}
if (Imps.Client.Core.NetworkSetting.Instance.UseHttpProxy)
{
text4 = text4 + "\r\n\t通过HTTP代理连接";
if (Imps.Client.Core.NetworkSetting.Instance.UseIeProxy)
{
text4 = text4 + "且使用IE代理设置";
}
}
this.loginLog.Append(text4);
this.loginLog.Append("\r\n-------------------------\r\n\r\n");
}
public void NotifyException(LoginStage stage, string message, Exception ex)
{
this.AppendLog(message, ex);
ClientLogger.WriteLogin(message, 0x63, ex.ToString(), 2);
}
public void NotifyLoginFailed(LoginStage stage, string message, LoginException lEx)
{
try
{
SipCException exception;
this.AppendLog(message, lEx);
ClientLogger.WriteLoginFailed(message, lEx.ToString());
if (!this.suspend)
{
this.curUser.DoLoginFailed(lEx);
}
else
{
switch (lEx.ExType)
{
case ExceptionType.WebException:
if (((lEx.PlainText == StringTable.MsgLoginServiceClosed) || (lEx.PlainText == StringTable.User.MsgUnauthorization)) || (lEx.PlainText == StringTable.MsgLoginNotIicUser))
{
this.curUser.DoLoginFailed(lEx);
}
break;
case ExceptionType.SSIAuthException:
this.curUser.DoLoginFailed(lEx);
break;
case ExceptionType.SipCException:
goto Label_009D;
}
}
return;
Label_009D:
exception = lEx.InnerException as SipCException;
if ((exception != null) && (exception.SipCStatusCode == 0x194))
{
this.curUser.DoLoginFailed(lEx);
}
}
catch
{
}
}
public void NotifyMessage(LoginStage stage, string message)
{
this.AppendLog(message);
ClientLogger.WriteLogin(message, 0, string.Empty, 2);
}
public void NotifyWarning(LoginStage stage, string message, Exception ex)
{
this.AppendLog(message, ex);
ClientLogger.WriteLogin(message, 10, ex.ToString(), 2);
}
public void ResumeNotify()
{
this.suspend = false;
}
public void SuspendNotify()
{
this.suspend = true;
}
public string LoginLog
{
get
{
return this.loginLog.ToString();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -