📄 geturiaction.cs
字号:
namespace Imps.Client.Core
{
using Imps.Client;
using Imps.Client.Base;
using Imps.Common;
using Imps.Utils;
using System;
using System.Net;
using System.Threading;
using System.Xml;
using System.Xml.XPath;
public sealed class GetUriAction : LoginAction
{
private const string AN_Uri = "uri";
private const string errorMessage = "获取Uri发生错误";
private string getUriUrl;
private bool? localCacheHit;
private const string NN_MobileNoe = "mobile-no";
private const string NN_Uri = "uri";
private const string regUri = "";
private const string SsiCookieKey = "ssic";
private bool userConfigLoaded;
public GetUriAction(User user, ILoginListner listener) : base(user, listener)
{
}
public override void Cancel()
{
}
public override void Clear()
{
base.User.Uri = new IicUri(string.Empty);
}
public override void Dispose()
{
}
public override bool Execute()
{
bool flag = false;
try
{
this.GetUriFromServer();
base.SaveUri();
flag = true;
base.NotifyMessage("获取Uri完成");
}
catch (WebException exception)
{
if ((--base.tryTimes > 0) && ExceptionHandler.IsRetryNeeded(exception))
{
base.NotifyException("获取Uri发生错误", exception);
this.Execute();
return flag;
}
HttpWebResponse response = exception.Response as HttpWebResponse;
if (response != null)
{
if (response.StatusCode == HttpStatusCode.NotFound)
{
string b = LoginAction.GetResultCode(LoginAction.GetResponseDOM(response));
if (!string.Equals("404", b))
{
base.NotifyLoginFailed("获取Uri发生错误", ExceptionType.CommonException, exception);
return false;
}
if (base.User.Sid > 0)
{
base.ClearUri();
this.Execute();
return flag;
}
base.NotifyLoginFailed("获取Uri发生错误", ExceptionType.WebException, exception);
return flag;
}
base.NotifyLoginFailed("获取Uri发生错误", ExceptionType.WebException, exception);
return flag;
}
base.NotifyLoginFailed("获取Uri发生错误", ExceptionType.WebException, exception);
}
catch (XmlException exception2)
{
base.NotifyLoginFailed("获取Uri发生错误", ExceptionType.XmlException, exception2);
}
catch (XPathException exception3)
{
base.NotifyLoginFailed("获取Uri发生错误", ExceptionType.XPathException, exception3);
}
catch (ThreadAbortException exception4)
{
base.NotifyWarning("获取Uri发生错误", exception4);
}
catch (Exception exception5)
{
base.NotifyLoginFailed("获取Uri发生错误", ExceptionType.CommonException, exception5);
}
finally
{
this.LoadUserConfig();
}
return flag;
}
private void GetUriFromServer()
{
if (((base.User.ProvisionStatus != UserProvisionStatus.Unknown) && !new IicUri(string.Empty).Equals(base.User.Uri)) && !string.IsNullOrEmpty(base.User.MobileNo))
{
base.NotifyMessage("已经在SSIAction中成功获取Uri等属性");
}
else
{
XmlDocument responseDOM;
base.NotifyMessage("开始获取Uri");
this.Init();
HttpWebRequest request = ConnectionFactory.CreateHttpWebRequest(this.getUriUrl, base.User, true, true);
request.ContentLength = 0;
request.KeepAlive = false;
using (HttpWebResponse response = ((HttpWebResponse) request.GetResponse()))
{
responseDOM = LoginAction.GetResponseDOM(response);
}
XmlNode node = responseDOM.DocumentElement.SelectSingleNode("uri");
XmlNode node2 = responseDOM.DocumentElement.SelectSingleNode("mobile-no");
base.User.Uri = new IicUri(XmlHelper.ReadXmlAttributeString(node, "value"));
if (node2 != null)
{
string text = XmlHelper.ReadXmlAttributeString(node2, "value");
if (!string.IsNullOrEmpty(text))
{
base.User.PersonalInfo.MobileNo = text;
}
}
}
}
private void Init()
{
this.getUriUrl = base.User.Configuration.SystemSetting.ServerUriSetting.UriGet;
if (string.IsNullOrEmpty(this.getUriUrl))
{
throw new NullReferenceException("getUriUri should not be null!");
}
}
private void LoadUserConfig()
{
if (!this.userConfigLoaded)
{
try
{
base.User.DoLoadImpsUserConfiguration();
this.userConfigLoaded = true;
}
catch (Exception exception)
{
base.NotifyException("获取Uri发生错误", exception);
}
}
}
public override bool PostLoginExecute()
{
return true;
}
public override bool LocalCacheHit
{
get
{
if (!this.localCacheHit.get_HasValue())
{
try
{
if (base.User.Sid > 0)
{
base.NotifyMessage("开始加载用户个人信息,获取Uri的本地缓存");
bool hit = false;
base.User.PersistentManager.LoadUserInfo(delegate (XmlNode node) {
XmlNode parentNode = node.ParentNode;
if ((parentNode != null) && (parentNode.Attributes["uri"] != null))
{
IicUri uri = new IicUri(parentNode.Attributes["uri"].Value);
if (uri.IsValid)
{
this.User.Uri = uri;
hit = true;
}
}
this.User.PersonalInfo.LoadPersonalXmlNode(node);
});
base.User.PersistentManager.LoadSubscribedServiceInfos(new PersistentDelegate(base.User.LoadServicesNode));
this.localCacheHit = new bool?(hit);
base.NotifyMessage("加载用户个人信息,获取Uri的本地缓存结束");
}
else
{
this.localCacheHit = false;
}
}
catch (Exception exception)
{
this.localCacheHit = false;
base.NotifyException("加载用户个人信息,获取Uri的本地缓存结束过程中出错", exception);
}
}
if (this.localCacheHit.get_Value())
{
this.LoadUserConfig();
}
return this.localCacheHit.get_Value();
}
}
public override Imps.Client.Core.LoginStage LoginStage
{
get
{
return Imps.Client.Core.LoginStage.RetriveUri;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -