📄 permissionaction.cs
字号:
namespace Imps.Client.Core
{
using Imps.Client.Core.Login;
using Imps.Utils;
using System;
using System.Threading;
public sealed class PermissionAction : LoginAction
{
private const string errorMessage = "获取权限的时候发生错误";
private bool? localCacheHit;
private bool result;
private AutoResetEvent waitPermission;
public PermissionAction(User user, ILoginListner listner) : base(user, listner)
{
}
public override void Cancel()
{
}
public override void Clear()
{
base.User.PermissionManager.Clear();
}
public override void Dispose()
{
}
public override bool Execute()
{
try
{
if (!string.IsNullOrEmpty(base.User.PermissionManager.PermissionVersion) && string.Equals(base.User.PermissionManager.PermissionVersion, base.User.Reg2Result.PermissionVer))
{
return true;
}
this.result = false;
base.NotifyMessage("开始从服务器获取权限信息");
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.waitPermission == null)
{
this.waitPermission = new AutoResetEvent(false);
}
base.User.PermissionManager.AsyncInitialize(op, false);
if (!this.waitPermission.WaitOne(this.TimeOut, false))
{
ReflectionHelper.ClearAllEvents(op);
base.NotifyLoginFailed("获取权限的时候发生错误", ExceptionType.CommonException, null);
}
base.NotifyMessage("从服务器获取权限信息结束");
}
catch (ThreadAbortException exception)
{
base.NotifyWarning("获取权限的时候发生错误", exception);
}
catch (Exception exception2)
{
base.NotifyLoginFailed("获取权限的时候发生错误", ExceptionType.CommonException, exception2);
}
return this.result;
}
private void op_ImpsError(object sender, ImpsErrorEventArgs e)
{
base.NotifyLoginFailed("获取权限的时候发生错误", ExceptionType.CommonException, null);
this.result = false;
this.waitPermission.Set();
}
private void op_Successed(object sender, EventArgs e)
{
this.result = true;
this.waitPermission.Set();
}
public override void Retry(RetryResult result)
{
base.User.PermissionManager.AsyncRetry(result);
}
public override bool LocalCacheHit
{
get
{
if (!this.localCacheHit.get_HasValue())
{
try
{
base.NotifyMessage("开始加载权限本地缓存");
base.User.PersistentManager.LoadPermissions(new PersistentDelegate(base.User.PermissionManager.InnerLoadXmlNode));
this.localCacheHit = true;
base.NotifyMessage("加载权限本地缓存结束");
}
catch (Exception exception)
{
base.User.PermissionManager.UserGlobalPermission = null;
this.localCacheHit = false;
base.NotifyException("加载权限本地缓存的时候发生错误", exception);
}
}
return this.localCacheHit.get_Value();
}
}
public override Imps.Client.Core.LoginStage LoginStage
{
get
{
return Imps.Client.Core.LoginStage.GetPermission;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -