📄 changepresenceaction.cs
字号:
namespace Imps.Client.Core
{
using Imps.Client;
using Imps.Common;
using System;
using System.Threading;
public sealed class ChangePresenceAction : LoginAction
{
private const string errorMessage = "修改在线状态的时候发生错误";
private bool result;
private AutoResetEvent waitChange;
public ChangePresenceAction(User user, ILoginListner listener) : base(user, listener)
{
}
public override void Cancel()
{
}
public override void Clear()
{
base.User.Presence.Clear();
}
public override void Dispose()
{
}
public override bool Execute()
{
try
{
base.NotifyMessage("开始设置在线状态");
this.result = false;
AsyncBizOperation op = new AsyncBizOperation(base.User);
op.Successed += new EventHandler(this.op_Successed);
op.ImpsError += new EventHandler<ImpsErrorEventArgs>(this, (IntPtr) this.op_ImpsError);
if (this.waitChange == null)
{
this.waitChange = new AutoResetEvent(false);
}
MainPresence basicPresence = base.GetCurrentLoginPresence();
base.User.Presence.AsyncChangeMainPresence(basicPresence, string.Empty, op);
if (!this.waitChange.WaitOne(this.TimeOut, false))
{
base.NotifyLoginFailed("等待设置状态超时", ExceptionType.SipCException, null);
}
if (this.result)
{
base.User.Status = UserAccountStatus.Logon;
try
{
UserAccounts.SaveToLocal();
UserAccounts.TrySaveLastestAccount(true);
}
catch (Exception exception)
{
base.NotifyException("修改在线状态的时候发生错误", exception);
}
}
base.NotifyMessage("设置在线状态结束");
}
catch (ThreadAbortException exception2)
{
base.NotifyWarning("修改在线状态的时候发生错误", exception2);
}
catch (Exception exception3)
{
base.NotifyLoginFailed("修改在线状态的时候发生错误", ExceptionType.CommonException, exception3);
}
return this.result;
}
private void op_ImpsError(object sender, ImpsErrorEventArgs e)
{
base.NotifyLoginFailed("修改在线状态的时候发生错误", ExceptionType.CommonException, e.ErrorException);
this.result = false;
this.waitChange.Set();
}
private void op_Successed(object sender, EventArgs e)
{
this.result = true;
this.waitChange.Set();
}
public override bool LocalCacheHit
{
get
{
return false;
}
}
public override Imps.Client.Core.LoginStage LoginStage
{
get
{
return Imps.Client.Core.LoginStage.ChangePresence;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -