📄 contactlistaction.cs
字号:
namespace Imps.Client.Core
{
using Imps.Common;
using System;
using System.Threading;
public sealed class ContactListAction : LoginAction
{
private const string errorMessage = "获取联系人相关信息出现错误";
private bool? IsLocalCacheValid;
private bool result;
private AutoResetEvent waitContactList;
public ContactListAction(User user, ILoginListner listener) : base(user, listener)
{
}
public override void Cancel()
{
}
public override void Clear()
{
base.User.ContactList.Clear();
}
public override void Dispose()
{
}
public override bool Execute()
{
try
{
if (!string.IsNullOrEmpty(base.User.ContactList.Version) && string.Equals(base.User.ContactList.Version, base.User.Reg2Result.ContactVer))
{
return true;
}
base.NotifyMessage("开始获取联系人相关信息");
this.result = false;
if (this.waitContactList == null)
{
this.waitContactList = new AutoResetEvent(false);
}
this.InnerExecute(base.User);
if (!this.waitContactList.WaitOne(this.TimeOut, false))
{
base.NotifyLoginFailed("获取联系人相关信息超时", ExceptionType.SipCException, null);
}
base.NotifyMessage("获取联系人相关信息结束");
}
catch (ThreadAbortException exception)
{
base.NotifyWarning("获取联系人相关信息出现错误", exception);
}
catch (Exception exception2)
{
base.NotifyLoginFailed("获取联系人相关信息出现错误", ExceptionType.CommonException, exception2);
}
return this.result;
}
private void InnerExecute(object state)
{
try
{
User contextForUi = state as User;
if (contextForUi == null)
{
throw new NullReferenceException("state object should be User and can not be null");
}
AsyncBizOperation op = new AsyncBizOperation(contextForUi);
op.Successed += new EventHandler(this.op_Successed);
op.ImpsError += new EventHandler<ImpsErrorEventArgs>(this, (IntPtr) this.op_ImpsError);
contextForUi.ContactList.SubscribeExpiredSeconds = 120;
contextForUi.ContactList.AsyncGetContactList(op, true);
}
catch (Exception exception)
{
base.NotifyLoginFailed("获取联系人相关信息出现错误", ExceptionType.CommonException, exception);
this.result = false;
this.waitContactList.Set();
}
}
private void op_ImpsError(object sender, ImpsErrorEventArgs e)
{
base.NotifyLoginFailed("获取联系人相关信息出现错误", ExceptionType.CommonException, null);
this.result = false;
this.waitContactList.Set();
}
private void op_Successed(object sender, EventArgs e)
{
this.result = true;
this.waitContactList.Set();
}
public override bool LocalCacheHit
{
get
{
if (!this.IsLocalCacheValid.get_HasValue())
{
try
{
base.NotifyMessage("开始加载联系人列表本地缓存");
this.IsLocalCacheValid = new bool?(base.User.ContactList.IsLocalCacheHit);
base.NotifyMessage("加载联系人列表本地缓存结束");
}
catch (Exception exception)
{
base.NotifyException("加载联系人列表本地缓存过程中出现错误", exception);
this.IsLocalCacheValid = false;
}
}
MainPresence initPresence = base.User.InitPresence;
if ((base.User._lastPresence != null) && base.User._lastPresence.IsForCurrentUser(base.User))
{
initPresence = base.User._lastPresence._presence;
}
return ((initPresence == MainPresence.OfflineLogin) || this.IsLocalCacheValid.get_Value());
}
}
public override Imps.Client.Core.LoginStage LoginStage
{
get
{
return Imps.Client.Core.LoginStage.GetContactsList;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -