📄 permissionmanager.cs
字号:
{
contact.ClearCustimizedPermissions();
continue;
}
contact.SetUpdatePermissionValues(text3, this);
}
}
}
}
if (!string.IsNullOrEmpty(values))
{
this.UpdateAllContactPermissions();
}
}
}
}
private void InnerSaveXmlNode(XmlNode node)
{
if (node.HasChildNodes)
{
node.RemoveAll();
}
XmlNode node2 = node;
if (!string.IsNullOrEmpty(this.PermissionVersion))
{
XmlHelper.SetNodeAttribute(node2, "version", this.PermissionVersion);
}
if (this.UserGlobalPermission != null)
{
string attrVal = this.UserGlobalPermission.ToString();
XmlHelper.SetNodeAttribute(node2, "values", attrVal);
}
lock (this._owner.ContactList.Contacts.SyncRoot)
{
using (IEnumerator<Imps.Client.Core.Contact> enumerator = this._owner.ContactList.Contacts.GetEnumerator())
{
while (enumerator.MoveNext())
{
Imps.Client.Core.Contact contact = enumerator.get_Current();
if (contact.HasCustimizedPermissions)
{
string text2 = contact.Permissions.ToString();
if (!string.IsNullOrEmpty(text2))
{
XmlNode node3 = XmlHelper.AppendChildElement(node2, "permission");
XmlHelper.SetNodeAttribute(node3, "uri", contact.Uri.Raw);
XmlHelper.SetNodeAttribute(node3, "values", text2);
}
}
}
}
}
}
internal void LoadLocalStorage()
{
try
{
this._owner.PersistentManager.LoadPermissions(new PersistentDelegate(this.InnerLoadXmlNode));
}
catch (Exception exception)
{
this.UserGlobalPermission = null;
LogHelper.LogException(exception);
}
}
internal void Notify_Permission(SipRequest req)
{
try
{
XmlDocument document = new XmlDocument();
document.LoadXml(req.Message.Body);
XmlNode node = document.DocumentElement.SelectSingleNode("event").SelectSingleNode("permissions");
this.InnerLoadXmlNode(node);
}
catch (Exception exception)
{
ClientLogger.WriteBizOperation("处理授权改变通知", exception.ToString(), 20, 0);
}
}
public void SaveLocalStorage()
{
try
{
this._owner.PersistentManager.SavePermissions(new PersistentDelegate(this.InnerSaveXmlNode));
}
catch (Exception exception)
{
LogHelper.LogException(exception);
}
}
private void SetContactOrContactsPermission_FinalResponseReceived(object sender, SipResponseReceivedEventArgs e)
{
SipResponse sipMsg = e.Response;
AsyncBizOperation op = sipMsg.Request.Context as AsyncBizOperation;
if (!sipMsg.IsOK)
{
LogHelper.LogReceivedSipMessage(sipMsg);
switch (sipMsg.Message.StatusCode)
{
case 400:
this._owner.FireImpsErrorInUiThread(new ImpsErrorEventArgs(StringTable.Permission.Msg_SetContactPermissionFailed_400), op);
return;
case 0x194:
this._owner.FireImpsErrorInUiThread(new ImpsErrorEventArgs(StringTable.Permission.Msg_SetContactPermissionFailed_404), op);
return;
case 500:
this._owner.FireImpsErrorInUiThread(new ImpsErrorEventArgs(StringTable.Permission.Msg_SetContactPermissionFailed_500), op);
return;
}
this._owner.FireImpsErrorInUiThread(new ImpsErrorEventArgs(StringTable.Permission.Msg_SetContactPermissionFailed), op);
}
else
{
XmlDocument document = new XmlDocument();
document.LoadXml(sipMsg.Message.Body.Trim());
XmlNode node = document.DocumentElement.SelectSingleNode("permissions");
if (node == null)
{
LogHelper.LogReceivedSipMessage(sipMsg);
this._owner.FireImpsErrorInUiThread(new ImpsErrorEventArgs(StringTable.Permission.Msg_SetContactPermissionFailed), op);
}
else
{
string text = XmlHelper.ReadXmlAttributeString(node, "version");
if ((text.Length > 0) && (text != this.PermissionVersion))
{
this.InnerLoadXmlNode(node);
this.SaveLocalStorage();
}
}
}
}
private void SetUserGlobalPermission_FinalResponseReceived(object sender, SipResponseReceivedEventArgs e)
{
SipResponse sipMsg = e.Response;
AsyncBizOperation op = (AsyncBizOperation) sipMsg.Request.Context;
if (!sipMsg.IsOK)
{
LogHelper.LogReceivedSipMessage(sipMsg);
switch (sipMsg.Message.StatusCode)
{
case 400:
this._owner.FireImpsErrorInUiThread(new ImpsErrorEventArgs(StringTable.Permission.Msg_SetUserGlobalPermissionFailed_400), op);
return;
case 0x194:
this._owner.FireImpsErrorInUiThread(new ImpsErrorEventArgs(StringTable.Permission.Msg_SetUserGlobalPermissionFailed_404), op);
return;
case 500:
this._owner.FireImpsErrorInUiThread(new ImpsErrorEventArgs(StringTable.Permission.Msg_SetUserGlobalPermissionFailed_500), op);
return;
}
this._owner.FireImpsErrorInUiThread(new ImpsErrorEventArgs(StringTable.Permission.Msg_GetContactPermissionFailed), op);
}
else
{
XmlDocument document = new XmlDocument();
document.LoadXml(sipMsg.Message.Body);
XmlNode node = document.DocumentElement.SelectSingleNode("permissions");
if (node == null)
{
LogHelper.LogReceivedSipMessage(sipMsg);
this._owner.FireImpsErrorInUiThread(new ImpsErrorEventArgs(StringTable.Permission.Msg_GetContactPermissionFailed), op);
}
else
{
string text = XmlHelper.ReadXmlAttributeString(node, "version");
if ((text.Length > 0) && (text != this.PermissionVersion))
{
this.InnerLoadXmlNode(node);
this.SaveLocalStorage();
}
}
}
}
internal void TryUpdateContactPermissions(Imps.Client.Core.Contact contact)
{
if (contact.HasCustimizedPermissions)
{
using (IEnumerator<PermissionPointValue> enumerator = contact.Permissions.GetEnumerator())
{
while (enumerator.MoveNext())
{
PermissionPointValue ppv = enumerator.get_Current();
this.CalcContactFinalPointValue(contact, ppv);
}
}
}
}
private void UpdateAllContactPermissions()
{
lock (this._owner.ContactList.Contacts.SyncRoot)
{
using (IEnumerator<Imps.Client.Core.Contact> enumerator = this._owner.ContactList.Contacts.GetEnumerator())
{
while (enumerator.MoveNext())
{
Imps.Client.Core.Contact contact = enumerator.get_Current();
this.TryUpdateContactPermissions(contact);
}
}
}
}
internal PermissionSetting FixedPermissionSetting
{
get
{
return this._owner.Configuration.SystemSetting.PermissionSetting;
}
}
public string PermissionVersion
{
get
{
return this._permissionVersion;
}
internal set
{
this._permissionVersion = value;
}
}
public PermissionDict UserGlobalPermission
{
get
{
if (this._globalPermission == null)
{
this._globalPermission = new PermissionDict();
using (IEnumerator<KeyValuePair<PermissionPointName, PermissionPoint>> enumerator = this.FixedPermissionSetting.GetEnumerator())
{
while (enumerator.MoveNext())
{
KeyValuePair<PermissionPointName, PermissionPoint> pair = enumerator.get_Current();
if (pair.get_Value().IsGlobal)
{
PermissionPointValue item = new PermissionPointValue(pair.get_Value());
item.Value = new ProposedData<int>(pair.get_Value().DefaultValue);
this._globalPermission.Add(item);
}
}
}
this._globalPermission.Sort();
}
return this._globalPermission;
}
set
{
this._globalPermission = value;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -