📄 user.cs
字号:
namespace Imps.Client.Core
{
using Imps.Base.Sipc;
using Imps.Client;
using Imps.Client.Base;
using Imps.Client.Base.Comm;
using Imps.Client.Core.CustomEmotion;
using Imps.Client.Core.History;
using Imps.Client.Core.P2P;
using Imps.Client.Core.P2P.FileTransportor;
using Imps.Client.Resource;
using Imps.Client.Utils;
using Imps.Client.Utils.Cryptography;
using Imps.Common;
using Imps.Utils;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.NetworkInformation;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Xml;
public class User
{
private volatile bool _autoLogin;
private bool _beenSubscribed;
private Imps.Client.Core.BlackList _blackList;
private ICustomEmotionManager _ceManager;
private Imps.Client.Core.Configuration _config;
private Imps.Client.Core.ContactList _contactList;
private Imps.Client.Core.ConversationManager _convMgr;
private UserAccounts.AccountData _currentAccount;
private static DateTime _dtServerBase = DateTime.MinValue;
private readonly RandomEncryptor _encryptor;
private ManualResetEvent _evtExit;
private int _expiredSeconds;
private int _expiredSecondsSsi;
private UserInfo _info;
private MainPresence _initPresence;
private bool _isRetryPreLoggin;
internal UserLastPresence _lastPresence;
private volatile bool _loginCancelled;
private ILoginListner _loginListner;
private string _loginStep;
private IHistoryManager _manager;
private Imps.Client.Core.AdManager _mgrAd;
private Imps.Client.Core.IVRManager _mgrIvr;
private Imps.Client.Core.PermissionManager _mgrPermission;
private IPersistentManager _mgrPersistent;
private Imps.Client.Core.MobileMailInfo _mobileMailInfo;
private readonly Imps.Client.Core.P2P.FileTransportor.P2PManager _p2pManager;
private string _password;
private List<SipRequestReceivedEventArgs> _pendingSipRequestReceived;
private Imps.Client.Core.PersonalGroupManager _pGroupMgr;
private PersonalGroupCollection _pGroups;
private PortraitHelper _portraitDownloader;
private UserPresence _presence;
private UserProvisionStatus _provisionStatus;
private readonly Imps.Client.Core.Reg2Result _reg2Result;
private long _regCallId;
private int _regCSeq;
private Imps.Client.Core.ScoreInfo _scoreInfo;
private Dictionary<string, ImpsService> _services;
private string _serviceVersion;
private long _sid;
private ISipConnection _sipConnection;
private string _ssiCredential;
private string _ssicUrlEncoded;
private ScheduleSmsManager _ssmsMgr;
private volatile UserAccountStatus _status;
private bool _subscribePresenceOK;
private object _syncObjConnection;
private object _syncObjLogin;
private object _syncObjPendingSipRequestReceived;
private object _syncObjPreLoginThread;
private static object _syncObjServerTime = new object();
private object _syncObjSsiCredential;
private Thread _threadPreLogin;
private static int _tickServerBase = 0;
private ITransportManager _transportManager;
private IicUri _uri;
private const int KeepSigninOffset = 180;
private const string NoNetworkErrorDetial = "当前没有可用的网络连接,请检查您的网络。";
private const string NoNetworkErrorSummary = "网络不可用,错误码:10001800";
public CheckDelegate PreLoginCheck;
public event EventHandler<ImpsErrorEventArgs> AutoLoginFailed;
public event EventHandler<ExServiceEventArgs> ExServicesStatusChanged;
public event EventHandler<ImpsErrorEventArgs> ImpsError;
public event EventHandler LoginStepChanged;
internal event EventHandler<UserSatusChangedEventArgs> RealtimeStatusChanged;
public event EventHandler<ImpsNotifyEventArgs> RegistrationNotifyReceived;
internal event EventHandler<SipRequestReceivedEventArgs> SipNotifyReceived;
internal event EventHandler<SipRequestReceivedEventArgs> SipRequestReceived;
public event EventHandler<UserSatusChangedEventArgs> StatusChanged;
internal User()
{
this._syncObjSsiCredential = new object();
this._evtExit = new ManualResetEvent(true);
this._reg2Result = new Imps.Client.Core.Reg2Result();
this._provisionStatus = UserProvisionStatus.Unknown;
this._syncObjPreLoginThread = new object();
this._syncObjConnection = new object();
this._syncObjLogin = new object();
this._encryptor = new RandomEncryptor();
this._syncObjPendingSipRequestReceived = new object();
this._serviceVersion = string.Empty;
this._status = 0;
this._loginStep = string.Empty;
this._config = new Imps.Client.Core.Configuration(this);
this._info = new UserInfo(this);
this._presence = new UserPresence(this);
this._blackList = new Imps.Client.Core.BlackList(this);
this._mgrPermission = new Imps.Client.Core.PermissionManager(this);
this._contactList = new Imps.Client.Core.ContactList(this);
this._pGroups = new PersonalGroupCollection(this);
this._mgrAd = new Imps.Client.Core.AdManager(this);
this._services = new Dictionary<string, ImpsService>();
this._portraitDownloader = new PortraitHelper(this);
this._scoreInfo = new Imps.Client.Core.ScoreInfo(this);
this._mobileMailInfo = new Imps.Client.Core.MobileMailInfo(this);
this.InitExServices();
this._pGroupMgr = new Imps.Client.Core.PersonalGroupManager(this);
this._p2pManager = Imps.Client.Core.P2P.FileTransportor.P2PManager.Instace;
this.InitP2PManager();
}
public User(IPersistentManager persistentManager) : this()
{
this._mgrPersistent = persistentManager;
UserAccounts.SetPersistentManager(this._mgrPersistent);
UserAccounts.LoadFromLocal();
}
public void AsyncCancelLogin()
{
this.AsyncCancelLogin(UserAccountStatus.None);
}
private void AsyncCancelLogin(UserAccountStatus userStatus)
{
if (this.Status != UserAccountStatus.Logon)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(this.DoCancelLogin), userStatus);
this._loginCancelled = true;
}
}
public bool AsyncChangePassword(string oldPassword, string newPassword, AsyncBizOperation op)
{
if (!this.IsPasswordCorrect(oldPassword))
{
this.FireImpsErrorInUiThread(new ImpsErrorEventArgs(Imps.Client.Resource.StringTable.PersonalInfo.OldPasswordNotCorrect), op);
LogHelper.LogError("AsyncChangePassword,oldPassword不对");
return false;
}
if (newPassword.Length == 0)
{
this.FireImpsErrorInUiThread(new ImpsErrorEventArgs(Imps.Client.Resource.StringTable.PersonalInfo.NewPasswordNotEmpty), op);
LogHelper.LogError("AsyncChangePassword,newPassword为空");
return false;
}
SipRequest req = this.CreateSipRequest("S");
req.Message.AddHeader(new SipcEventHeader("SetPassword"));
req.Context = op;
op.ContextForBiz = newPassword;
StringWriter tw = new StringWriter();
XmlHelper.CreateXmlWriterForSipRequest(tw, null, delegate (XmlWriter writer, object context) {
writer.WriteStartElement("password");
string text = SecurityHelper.EncryptPass(this.Sid.ToString(), this.Domain, oldPassword, newPassword);
writer.WriteAttributeString("encrypted-value", text);
writer.WriteEndElement();
});
req.Message.Body = tw.ToString();
ErrorHelper.HandleSendRequestErrorAndTimeout(req);
req.FinalResponseReceived += new EventHandler<SipResponseReceivedEventArgs>(this, (IntPtr) this.reqChangePassword_FinalResponseReceived);
ClientLogger.WriteBizOperation("修改密码", req.Message.ToString(), 0, 0);
this.SendSipMessage(req);
return true;
}
public void AsyncLogin(MainPresence presence, bool auto)
{
this._initPresence = presence;
this.AutoLogin = auto;
if ((presence == MainPresence.OfflineLogin) || this.CheckNetworkInterface(auto))
{
if (this.SipConnection == null)
{
ClientLogger.WriteLogin(string.Format("开始登录: Auto={0}", auto), 0, string.Empty, 0);
this.Status = UserAccountStatus.Loginning;
this.AsyncPreLogin();
}
else if (auto)
{
this.Status = UserAccountStatus.Loginning;
this.AsyncPreLogin(true);
}
else
{
this.SipConnection = null;
this.AsyncLogin(presence, auto);
}
}
}
public void AsyncLogout()
{
this.AsyncLogout(SignoutMode.Normal);
}
public void AsyncLogout(SignoutMode mode)
{
this.AsyncLogout(mode, null);
}
public void AsyncLogout(SignoutMode mode, AutoResetEvent are)
{
try
{
UserAccountStatus status = this.Status;
ClientLogger.WriteLogin("准备退出登录……", 0, string.Format("UserStatus={0}", status), 0);
this.ClearBeforeLogout();
switch (status)
{
case UserAccountStatus.Initialized:
case UserAccountStatus.Loginning:
case UserAccountStatus.Disconnected:
this.AsyncCancelLogin();
return;
case UserAccountStatus.Logon:
break;
case UserAccountStatus.Logouting:
case UserAccountStatus.Logoff:
case UserAccountStatus.WaitReconnect:
case UserAccountStatus.StandBy:
return;
case UserAccountStatus.OfflineLogon:
try
{
this.Status = UserAccountStatus.Logouting;
Thread.Sleep(0x3e8);
this.DoAfterLogout(SignoutMode.Normal);
if (are != null)
{
are.Set();
}
}
catch (Exception exception)
{
Trace.WriteLine(exception);
}
this.DoAfterLogout(SignoutMode.Normal);
return;
default:
return;
}
this.Status = UserAccountStatus.Logouting;
this.AsyncSsiSignout();
this._evtExit.Reset();
try
{
this.AsyncSipcSignout(mode);
}
catch (Exception)
{
this._evtExit.Set();
}
finally
{
bool flag = this._evtExit.WaitOne(0x1770, true);
ClientLogger.WriteLogin("等待退出Event……", 0, string.Format("Result={0}", flag), 1);
if (!flag)
{
this.DoAfterLogout(mode);
}
try
{
if (are != null)
{
are.Set();
}
}
catch (Exception)
{
}
}
}
catch (Exception exception2)
{
ClientLogger.WriteBizOperation("注销出错", exception2.ToString(), 20);
this.DoAfterLogout(SignoutMode.Normal);
}
}
private void AsyncPreLogin()
{
this.AsyncPreLogin(false);
}
private void AsyncPreLogin(bool sipcOnly)
{
this.ClearPreLoginThread();
if (this._threadPreLogin == null)
{
lock (this._syncObjPreLoginThread)
{
if (this._threadPreLogin == null)
{
this._threadPreLogin = new Thread(new ParameterizedThreadStart(this, (IntPtr) this.StartAsyncLogin));
this._threadPreLogin.Name = "Imps.Client.Pc PreLogin";
this._threadPreLogin.Start(sipcOnly);
}
}
}
}
private void AsyncSipcKeepLogon()
{
SipRequest msg = this.CreateSipRequest("R", this._regCallId, ++this._regCSeq);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -