ajaxsettingssectionhandler.cs
来自「AJAX开发工具包」· CS 代码 · 共 146 行
CS
146 行
/*
* MS 06-04-04 added DebugEnabled web.config property <debug enabled="true"/>
* MS 06-04-05 added oldStyle section in web.config
* MS 06-04-12 added urlNamespaceMapping/@useAssemblyQualifiedName
*
*
*
*
*/
using System;
using System.Xml;
using System.Configuration;
namespace AjaxPro
{
internal class AjaxSettingsSectionHandler : IConfigurationSectionHandler
{
#region IConfigurationSectionHandler Members
public object Create(object parent, object configContext, System.Xml.XmlNode section)
{
AjaxSettings settings = new AjaxSettings();
foreach(XmlNode n in section.ChildNodes)
{
if(n.Name == "coreScript")
{
if(n.InnerText != null && n.InnerText.Length > 0)
{
settings.ScriptReplacements.Add("core", n.InnerText);
}
}
else if(n.Name == "scriptReplacements")
{
foreach(XmlNode file in n.SelectNodes("file"))
{
string name = "";
string path = "";
if(file.Attributes["name"] != null)
{
name = file.Attributes["name"].InnerText;
if(file.Attributes["path"] != null) path = file.Attributes["path"].InnerText;
if(settings.ScriptReplacements.ContainsKey(name))
settings.ScriptReplacements[name] = path;
else
settings.ScriptReplacements.Add(name, path);
}
}
}
else if(n.Name == "urlNamespaceMappings")
{
settings.UseAssemblyQualifiedName = n.SelectSingleNode("@useAssemblyQualifiedName[.='true']") != null;
XmlNode ns, url;
foreach(XmlNode e in n.SelectNodes("add"))
{
ns = e.SelectSingleNode("@type");
url = e.SelectSingleNode("@path");
if(ns == null || ns.InnerText == "" || url == null || url.InnerText == "")
continue;
if(settings.UrlNamespaceMappings.Contains(url.InnerText))
throw new Exception("Duplicate namespace mapping '" + url.InnerText + "'.");
settings.UrlNamespaceMappings.Add(url.InnerText, ns.InnerText);
}
}
else if(n.Name == "jsonConverters")
{
XmlNodeList jsonConverters = n.SelectNodes("add");
foreach(XmlNode j in jsonConverters)
{
XmlNode t = j.SelectSingleNode("@type");
if(t == null)
continue;
Type type = Type.GetType(t.InnerText);
if(type == null)
{
// throw new ArgumentException("Could not find type " + t.InnerText + ".");
continue;
}
if (!typeof(IJavaScriptConverter).IsAssignableFrom(type))
{
// throw new ArgumentException("Type " + t.InnerText + " does not inherit from JavaScriptObjectConverter.");
continue;
}
IJavaScriptConverter c = (IJavaScriptConverter)Activator.CreateInstance(type);
c.Initialize();
settings.JavaScriptConverters.Add(c);
}
}
else if(n.Name == "encryption")
{
string cryptType = n.SelectSingleNode("@cryptType") != null ? n.SelectSingleNode("@cryptType").InnerText : null;
string keyType = n.SelectSingleNode("@keyType") != null ? n.SelectSingleNode("@keyType").InnerText : null;
if(cryptType == null || keyType == null)
continue;
AjaxEncryption enc = new AjaxEncryption(cryptType, keyType);
if(!enc.Init())
throw new Exception("Ajax.NET Professional encryption configuration failed.");
settings.Encryption = enc;
}
else if(n.Name == "token")
{
settings.TokenEnabled = n.SelectSingleNode("@enabled") != null && n.SelectSingleNode("@enabled").InnerText == "true";
settings.TokenSitePassword = n.SelectSingleNode("@sitePassword") != null ? n.SelectSingleNode("@sitePassword").InnerText : settings.TokenSitePassword;
}
else if (n.Name == "debug")
{
if (n.SelectSingleNode("@enabled") != null && n.SelectSingleNode("@enabled").InnerText == "true")
settings.DebugEnabled = true;
}
else if (n.Name == "oldStyle")
{
if (n.SelectSingleNode("objectExtendPrototype") != null)
{
if (!settings.OldStyle.Contains("objectExtendPrototype"))
settings.OldStyle.Add("objectExtendPrototype");
}
}
}
return settings;
}
#endregion
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?