📄 user.cs
字号:
return new SipRequestEx(this.InnerCreateSipcRequest(method, ref callId, cSeq), op);
}
internal SipResponse CreateSipResponse(SipRequest req)
{
return this.CreateSipResponse(req, 200, "OK");
}
internal SipResponse CreateSipResponse(SipRequest req, int statusCode, string reasonPhrease)
{
SipcRequest message = req.Message;
SipcResponse sipcResponse = new SipcResponse(statusCode, reasonPhrease);
if (message.From != null)
{
sipcResponse.AddHeader(req.Message.From);
}
sipcResponse.AddHeader(message.CallId);
sipcResponse.AddHeader(message.CSeq);
return new SipResponse(sipcResponse, req);
}
private string DecodePassword()
{
try
{
return this._encryptor.Decrypt(this._password);
}
catch
{
return this._password;
}
}
private void DoAfterLogout(SignoutMode mode)
{
try
{
this.SipConnection = null;
this.Status = UserAccountStatus.Logoff;
GC.Collect();
}
finally
{
this._evtExit.Set();
}
}
private void DoCancelLogin(object state)
{
if (state is UserAccountStatus)
{
this.DoCancelLogin(state, (UserAccountStatus) state, true);
}
else
{
this.DoCancelLogin(state, UserAccountStatus.None, true);
}
}
private void DoCancelLogin(object state, UserAccountStatus status, bool resetSipConnection)
{
this._loginCancelled = true;
this.SipConnection = null;
if (!this.AutoLogin)
{
this.LoginStep = string.Empty;
}
this.ClearPreLoginThread();
this.Status = status;
}
private void DoGetUri(ref HttpWebRequest req)
{
string uriString;
string mobileNoString;
this.DoGetUri(ref req, string.Empty, out uriString, out mobileNoString);
this._uri = new IicUri(uriString);
this._sid = this._uri.Sid;
if (!string.IsNullOrEmpty(mobileNoString))
{
this.PersonalInfo.MobileNo = mobileNoString;
}
}
private void DoGetUri(ref HttpWebRequest req, string sid, out string uriString, out string mobileNoString)
{
string detail = this.Configuration.SystemSetting.ServerUriSetting.UriGet;
ClientLogger.WriteLogin("获取 URI", 0, detail, 2);
req = ConnectionFactory.CreateHttpWebRequest(detail, this, true, true);
if (string.IsNullOrEmpty(sid))
{
req.ContentLength = 0;
}
else
{
req.ContentType = "application/x-www-form-urlencoded; charset=utf-8";
using (Stream stream = req.GetRequestStream())
{
byte[] bytes = Encoding.UTF8.GetBytes("Sid=" + sid);
stream.Write(bytes, 0, bytes.Length);
}
}
using (HttpWebResponse response = ((HttpWebResponse) req.GetResponse()))
{
using (Stream inStream = response.GetResponseStream())
{
XmlDocument document = new XmlDocument();
try
{
document.Load(inStream);
}
catch (Exception exception)
{
throw exception;
}
ClientLogger.WriteLogin("URI 获取成功", 0, document.OuterXml, 2);
XmlNode node = document.DocumentElement.SelectSingleNode("uri");
uriString = XmlHelper.ReadXmlAttributeString(node, "value");
node = document.DocumentElement.SelectSingleNode("mobile-no");
mobileNoString = (node == null) ? string.Empty : XmlHelper.ReadXmlAttributeString(node, "value");
}
response.Close();
}
}
public static string DoHashPassword(byte[] password)
{
byte[] bytes = BitConverter.GetBytes(Environment.TickCount);
return DoHashPassword(password, bytes);
}
public static string DoHashPassword(byte[] password, byte[] b0)
{
using (SHA1 sha = SHA1.Create())
{
byte[] src = sha.ComputeHash(password);
for (int i = 0; i < password.Length; i++)
{
password[i] = 0;
}
byte[] dst = new byte[b0.Length + src.Length];
System.Buffer.BlockCopy(b0, 0, dst, 0, b0.Length);
System.Buffer.BlockCopy(src, 0, dst, b0.Length, src.Length);
byte[] buffer3 = sha.ComputeHash(dst);
byte[] buffer4 = new byte[b0.Length + buffer3.Length];
System.Buffer.BlockCopy(b0, 0, buffer4, 0, b0.Length);
System.Buffer.BlockCopy(buffer3, 0, buffer4, b0.Length, buffer3.Length);
return ComputeAuthResponse.BinaryToHex(buffer4);
}
}
internal void DoLoadImpsUserConfiguration()
{
this.Configuration.LoadImpsUserCfg();
string defaultMsgHistoryDir = this.Configuration.UserSetting.ConversationSetting.DefaultMsgHistoryDir;
if (!string.IsNullOrEmpty(defaultMsgHistoryDir) && (defaultMsgHistoryDir.Trim().Length > 0))
{
this.PersistentManager.BaseDirForHistory = defaultMsgHistoryDir;
}
}
private void DoLoadSystemConfiguration(ref HttpWebRequest req)
{
string strXml;
try
{
ClientLogger.WriteLoginSuccessed("加载系统配置的本地缓存!", 2);
this.Configuration.LoadSysCfg();
if (!this.NavigateUrl.Equals(this.Configuration.SystemSetting.NavigatorServerUri, 1))
{
ClientLogger.WriteLogin("导航服务器地址发生改变,清除本地缓存", 0, this.Configuration.SystemSetting.NavigatorServerUri + " <==> " + this.NavigateUrl, 2);
this.Configuration.ClearSysCfg();
string userId = this.PersistentManager.UserId.ToString();
this.PersistentManager.DelUserCfgById(userId);
this.PersistentManager.DelUserInfoById(userId);
this.PersistentManager.DelContactsInfoById(userId);
this.PersistentManager.DelPermissionById(userId);
}
ConnectionFactory.Reset();
}
catch (Exception exception)
{
ClientLogger.WriteGeneral("加载系统配置的本地缓存发生错误!", exception.ToString());
}
string s = string.Empty;
using (StringWriter w = new StringWriter())
{
using (XmlTextWriter writer2 = new XmlTextWriter(w))
{
writer2.WriteStartElement("config");
writer2.WriteStartElement("user");
if (string.IsNullOrEmpty(this.MobileNo))
{
writer2.WriteAttributeString("sid", this.Sid.ToString());
}
else
{
writer2.WriteAttributeString("mobile-no", this.MobileNo);
}
writer2.WriteEndElement();
writer2.WriteStartElement("client");
writer2.WriteAttributeString("type", "PC");
writer2.WriteAttributeString("version", Imps.Client.Core.Configuration.FixedClientSetting.Version);
writer2.WriteAttributeString("platform", EnvHelper.GetOsString());
writer2.WriteEndElement();
writer2.WriteStartElement("servers");
writer2.WriteAttributeString("version", this.Configuration.SystemSetting.SvrUriVerion.ToString());
writer2.WriteEndElement();
writer2.WriteStartElement("service-no");
writer2.WriteAttributeString("version", this.Configuration.SystemSetting.SvcNoVerion.ToString());
writer2.WriteEndElement();
writer2.WriteStartElement("parameters");
writer2.WriteAttributeString("version", this.Configuration.SystemSetting.ParamsVerion.ToString());
writer2.WriteEndElement();
writer2.WriteStartElement("hints");
writer2.WriteAttributeString("version", this.Configuration.SystemSetting.HintsVerion.ToString());
writer2.WriteEndElement();
writer2.WriteStartElement("http-applications");
writer2.WriteAttributeString("version", this.Configuration.SystemSetting.HttpAppUriVerion.ToString());
writer2.WriteEndElement();
writer2.WriteEndElement();
}
s = w.ToString();
}
byte[] bytes = Encoding.UTF8.GetBytes(s);
req = ConnectionFactory.CreateHttpWebRequest(this.NavigateUrl, this, true, false);
using (Stream stream = req.GetRequestStream())
{
stream.Write(bytes, 0, bytes.Length);
}
ClientLogger.WriteLogin("从 server 获取最新系统配置", 0, this.NavigateUrl, 2);
using (WebResponse response = req.GetResponse())
{
string text4 = response.Headers["Date"];
if (!string.IsNullOrEmpty(text4))
{
ServerTime = DateTime.Parse(text4);
}
using (Stream stream2 = response.GetResponseStream())
{
StreamReader reader = new StreamReader(stream2);
strXml = reader.ReadToEnd();
reader.Close();
}
response.Close();
}
ClientLogger.WriteLoginSuccessed("获取成功,更新本地存储!", 2);
try
{
this.Configuration.InitSysSetting(strXml);
}
catch (XmlException exception2)
{
throw exception2;
}
}
internal void DoLoginFailed(ImpsErrorEventArgs e)
{
StringBuilder builder = new StringBuilder();
LogHelper.BuildLogTextForImpsError(builder, e);
ClientLogger.WriteLoginFailed(this.LoginStep, builder.ToString(), 0);
if (!this.LoginCancelled)
{
if (this.AutoLogin)
{
this.FireAutoLoginFailedInUiThread(e);
this.DoCancelLogin(null, UserAccountStatus.WaitReconnect, false);
}
else
{
this.FireImpsErrorInUiThread(e);
this.AsyncCancelLogin();
}
}
}
internal void DoLoginFailed(LoginException lex)
{
bool flag = false;
if (!this.LoginCancelled)
{
ImpsErrorEventArgs e = new ImpsErrorEventArgs(lex.PlainText);
e.ErrorCode = lex.ErrorCode;
e.BizCode = lex.BizCode;
if (this.AutoLogin)
{
if (lex.ExType == ExceptionType.SSIAuthException)
{
this.FireImpsErrorInUiThread(e);
}
else if (((lex.PlainText == StringTable.MsgLoginServiceClosed) || (lex.PlainText == StringTable.User.MsgUnauthorization)) || (lex.PlainText == StringTable.MsgLoginNotIicUser))
{
this.FireImpsErrorInUiThread(e);
}
else
{
flag = true;
this.FireAutoLoginFailedInUiThread(e);
}
}
else
{
this.FireImpsErrorInUiThread(e);
}
}
this.AsyncCancelLogin(flag ? UserAccountStatus.WaitReconnect : UserAccountStatus.None);
}
private void DoSsiKeepLogon(int retryTimes)
{
Thread.CurrentThread.Name = "Imps.Client.Pc KeepSsiLogon";
Cookie cookie = null;
try
{
string detail = this.Configuration.SystemSetting.ServerUriSetting.UriSsiAppSignIn;
ClientLogger.WriteLogin("保持 SSI 登录", 0, detail, 0);
using (HttpWebResponse response = ((HttpWebResponse) ConnectionFactory.CreateHttpWebRequest(detail, this, false, true).GetResponse()))
{
cookie = response.Cookies["ssic"];
response.Close();
}
}
catch (Exception exception)
{
ClientLogger.WriteLogin("保持 SSI 登录失败", 20, exception.ToString(), 0);
}
if (cookie != null)
{
this.SsiCredential = cookie.Value;
ClientLogger.WriteLogin("credential 获取成功", 0, this._ssiCredential, 0);
}
else
{
while (!this.TryDoSsiSignin())
{
if (retryTimes-- <= 0)
{
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -