📄 secutil.cs
字号:
p = new SqlParameter("@Feature", feature);
cmd.Parameters.Add(p);
p = new SqlParameter("@CompatibleSchemaVersion", version);
cmd.Parameters.Add(p);
p = new SqlParameter("@ReturnValue", SqlDbType.Int);
p.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(p);
cmd.ExecuteNonQuery();
iStatus = ((p.Value != null) ? ((int)p.Value) : -1);
if (iStatus != 0) {
schemaVersionCheck = -1;
throw new ProviderException(SR.GetString(SR.Provider_Schema_Version_Not_Match, provider.ToString(), version));
}
}
schemaVersionCheck = 1;
}
}
}
}
internal static XmlNode GetAndRemoveBooleanAttribute(XmlNode node, string attrib, ref bool val) {
return GetAndRemoveBooleanAttributeInternal(node, attrib, false /*fRequired*/, ref val);
}
// input.Xml cursor must be at a true/false XML attribute
private static XmlNode GetAndRemoveBooleanAttributeInternal(XmlNode node, string attrib, bool fRequired, ref bool val) {
XmlNode a = GetAndRemoveAttribute(node, attrib, fRequired);
if (a != null) {
if (a.Value == "true") {
val = true;
}
else if (a.Value == "false") {
val = false;
}
else {
throw new ConfigurationErrorsException(
SR.GetString(SR.Invalid_boolean_attribute, a.Name),
a);
}
}
return a;
}
private static XmlNode GetAndRemoveAttribute(XmlNode node, string attrib, bool fRequired) {
XmlNode a = node.Attributes.RemoveNamedItem(attrib);
// If the attribute is required and was not present, throw
if (fRequired && a == null) {
throw new ConfigurationErrorsException(
SR.GetString(SR.Missing_required_attribute, attrib, node.Name),
node);
}
return a;
}
internal static XmlNode GetAndRemoveNonEmptyStringAttribute(XmlNode node, string attrib, ref string val) {
return GetAndRemoveNonEmptyStringAttributeInternal(node, attrib, false /*fRequired*/, ref val);
}
private static XmlNode GetAndRemoveNonEmptyStringAttributeInternal(XmlNode node, string attrib, bool fRequired, ref string val) {
XmlNode a = GetAndRemoveStringAttributeInternal(node, attrib, fRequired, ref val);
if (a != null && val.Length == 0) {
throw new ConfigurationErrorsException(
SR.GetString(SR.Empty_attribute, attrib),
a);
}
return a;
}
private static XmlNode GetAndRemoveStringAttributeInternal(XmlNode node, string attrib, bool fRequired, ref string val) {
XmlNode a = GetAndRemoveAttribute(node, attrib, fRequired);
if (a != null) {
val = a.Value;
}
return a;
}
internal static void CheckForUnrecognizedAttributes(XmlNode node) {
if (node.Attributes.Count != 0) {
throw new ConfigurationErrorsException(
SR.GetString(SR.Config_base_unrecognized_attribute, node.Attributes[0].Name),
node.Attributes[0]);
}
}
internal static void CheckForNonCommentChildNodes(XmlNode node) {
foreach (XmlNode childNode in node.ChildNodes) {
if (childNode.NodeType != XmlNodeType.Comment) {
throw new ConfigurationErrorsException(
SR.GetString(SR.Config_base_no_child_nodes),
childNode);
}
}
}
internal static XmlNode GetAndRemoveStringAttribute(XmlNode node, string attrib, ref string val) {
return GetAndRemoveStringAttributeInternal(node, attrib, false /*fRequired*/, ref val);
}
internal static void CheckForbiddenAttribute(XmlNode node, string attrib) {
XmlAttribute attr = node.Attributes[attrib];
if (attr != null) {
throw new ConfigurationErrorsException(
SR.GetString(SR.Config_base_unrecognized_attribute, attrib),
attr);
}
}
// Returns whether the virtual path is relative. Note that this returns true for
// app relative paths (e.g. "~/sub/foo.aspx")
internal static bool IsRelativeUrl(string virtualPath) {
// If it has a protocol, it's not relative
if (virtualPath.IndexOf(":", StringComparison.Ordinal) != -1)
return false;
return !IsRooted(virtualPath);
}
internal static bool IsRooted(String basepath) {
return (String.IsNullOrEmpty(basepath) || basepath[0] == '/' || basepath[0] == '\\');
}
internal static void GetAndRemoveStringAttribute(NameValueCollection config, string attrib, string providerName, ref string val) {
val = config.Get(attrib);
config.Remove(attrib);
}
internal static void CheckUnrecognizedAttributes(NameValueCollection config, string providerName) {
if (config.Count > 0) {
string attribUnrecognized = config.GetKey(0);
if (!String.IsNullOrEmpty(attribUnrecognized))
throw new ConfigurationErrorsException(
SR.GetString(SR.Unexpected_provider_attribute, attribUnrecognized, providerName));
}
}
internal static string GetStringFromBool(bool flag) {
return flag ? "true" : "false";
}
internal static void GetAndRemovePositiveOrInfiniteAttribute(NameValueCollection config, string attrib, string providerName, ref int val)
{
GetPositiveOrInfiniteAttribute(config, attrib, providerName, ref val);
config.Remove(attrib);
}
internal static void GetPositiveOrInfiniteAttribute(NameValueCollection config, string attrib, string providerName, ref int val)
{
string s = config.Get(attrib);
int t;
if (s == null)
{
return;
}
if (s == "Infinite")
{
t = Infinite;
}
else
{
try
{
t = Convert.ToInt32(s, CultureInfo.InvariantCulture);
}
catch (Exception e)
{
if (e is ArgumentException || e is FormatException || e is OverflowException)
{
throw new ConfigurationErrorsException(
SR.GetString(SR.Invalid_provider_positive_attributes, attrib, providerName));
}
else
{
throw;
}
}
if (t < 0)
{
throw new ConfigurationErrorsException(
SR.GetString(SR.Invalid_provider_positive_attributes, attrib, providerName));
}
}
val = t;
}
internal static void GetAndRemovePositiveAttribute(NameValueCollection config, string attrib, string providerName, ref int val)
{
GetPositiveAttribute(config, attrib, providerName, ref val);
config.Remove(attrib);
}
internal static void GetPositiveAttribute(NameValueCollection config, string attrib, string providerName, ref int val)
{
string s = config.Get(attrib);
int t;
if (s == null)
{
return;
}
try
{
t = Convert.ToInt32(s, CultureInfo.InvariantCulture);
}
catch (Exception e)
{
if (e is ArgumentException || e is FormatException || e is OverflowException)
{
throw new ConfigurationErrorsException(
SR.GetString(SR.Invalid_provider_positive_attributes, attrib, providerName));
}
else
{
throw;
}
}
if (t < 0)
{
throw new ConfigurationErrorsException(
SR.GetString(SR.Invalid_provider_positive_attributes, attrib, providerName));
}
val = t;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -