private Uri GetAndValidateUrls(string elementName, CultureInfo culture) { Uri result = null; XmlNode xmlNode = this.xmlDoc.SelectSingleNode(this.GetOweXpath(elementName), this.namespaceManager); if (xmlNode != null) { string attributeStringValue = ExtensionData.GetAttributeStringValue(xmlNode, "DefaultValue"); result = SchemaParser.ValidateUrl(this.extensionInstallScope, elementName, attributeStringValue); using (XmlNodeList xmlNodeList = xmlNode.SelectNodes(this.GetOweChildPath("Override"), this.namespaceManager)) { string name = elementName + " " + "Override"; foreach (object obj in xmlNodeList) { XmlNode xmlNode2 = (XmlNode)obj; string attributeStringValue2 = ExtensionData.GetAttributeStringValue(xmlNode2, "Value"); Uri uri = SchemaParser.ValidateUrl(this.extensionInstallScope, name, attributeStringValue2); string attributeStringValue3 = ExtensionData.GetAttributeStringValue(xmlNode2, "Locale"); if (string.Compare(culture.ToString(), attributeStringValue3, StringComparison.OrdinalIgnoreCase) == 0) { result = uri; } } } } return(result); }
private void ValidateSourceLocationUrls(string xpath, string urlAttributeName, string errorMessageName) { using (XmlNodeList xmlNodeList = this.xmlDoc.SelectNodes(xpath, this.namespaceManager)) { foreach (object obj in xmlNodeList) { XmlNode xmlNode = (XmlNode)obj; string attributeStringValue = ExtensionData.GetAttributeStringValue(xmlNode, urlAttributeName); SchemaParser.ValidateUrl(this.extensionInstallScope, errorMessageName, attributeStringValue); } } }
private static void ValidateItemHasKnownEntityRule(XmlNode xmlNode, RequestedCapabilities requestedCapabilities, ref HashSet <string> entitiesRegExNames, ref int regexCount) { if (requestedCapabilities == RequestedCapabilities.Restricted) { XmlAttribute attribute = xmlNode.Attributes["EntityType"]; string item; if (!ExtensionDataHelper.TryGetAttributeValue(attribute, out item) || !SchemaParser.AllowedEntityTypesInRestricted.Contains(item)) { throw new OwaExtensionOperationException(Strings.ErrorInvalidManifestData(Strings.ErrorReasonOnlySelectedEntitiesInRestricted)); } } XmlAttribute attribute2 = xmlNode.Attributes["RegExFilter"]; XmlAttribute attribute3 = xmlNode.Attributes["FilterName"]; string text; bool flag = ExtensionDataHelper.TryGetAttributeValue(attribute3, out text); string regexPattern; bool flag2 = ExtensionDataHelper.TryGetAttributeValue(attribute2, out regexPattern); if (flag != flag2) { throw new OwaExtensionOperationException(Strings.ErrorInvalidManifestData(Strings.ErrorReasonRegExNameAndValueRequiredInEntitiesRules)); } if (!flag) { XmlAttribute attribute4 = xmlNode.Attributes["IgnoreCase"]; string text2; if (ExtensionDataHelper.TryGetAttributeValue(attribute4, out text2)) { throw new OwaExtensionOperationException(Strings.ErrorInvalidManifestData(Strings.ErrorReasonIgnoreCaseWithoutRegExInEntitiesRules)); } return; } else { regexCount++; if (entitiesRegExNames == null) { entitiesRegExNames = new HashSet <string>(); } else if (regexCount > 5) { throw new OwaExtensionOperationException(Strings.ErrorInvalidManifestData(Strings.ErrorReasonTooManyRegexRule(5))); } if (!entitiesRegExNames.Add(text)) { throw new OwaExtensionOperationException(Strings.ErrorInvalidManifestData(Strings.ErrorReasonMultipleRulesWithSameFilterName(text))); } SchemaParser.ValidateRegEx(text, regexPattern, "ItemHasKnownEntity", "RegExFilter"); return; } }
private bool TryCreateActivationRuleInternal(XmlNode node, out ActivationRule activationRule) { activationRule = null; if (node == null || node.Attributes == null) { return(false); } XmlAttribute xmlAttribute = node.Attributes["type", "http://www.w3.org/2001/XMLSchema-instance"]; string a; if (!ExtensionDataHelper.TryGetNameSpaceStrippedAttributeValue(xmlAttribute, out a)) { return(false); } if (!string.Equals(a, "ItemIs", StringComparison.Ordinal)) { if (string.Equals(a, "ItemHasKnownEntity", StringComparison.Ordinal)) { KnownEntityType entityType; if (EnumValidator.TryParse <KnownEntityType>(node.Attributes["EntityType"].Value, EnumParseOptions.Default, out entityType)) { XmlAttribute xmlAttribute2 = node.Attributes["FilterName"]; XmlAttribute xmlAttribute3 = node.Attributes["RegExFilter"]; bool ignoreCase = SchemaParser.ParseBoolFromXmlAttribute(node.Attributes["IgnoreCase"]); activationRule = new ItemHasKnownEntityRule(entityType, (xmlAttribute2 != null) ? xmlAttribute2.Value : null, (xmlAttribute3 != null) ? xmlAttribute3.Value : null, ignoreCase); return(true); } } else if (string.Equals(a, "ItemHasRegularExpressionMatch", StringComparison.Ordinal)) { RegExPropertyName propertyName; if (EnumValidator.TryParse <RegExPropertyName>(node.Attributes["PropertyName"].Value, EnumParseOptions.Default, out propertyName)) { bool ignoreCase2 = SchemaParser.ParseBoolFromXmlAttribute(node.Attributes["IgnoreCase"]); activationRule = new ItemHasRegularExpressionMatchRule(node.Attributes["RegExName"].Value, node.Attributes["RegExValue"].Value, propertyName, ignoreCase2); return(true); } } else { if (string.Equals(a, "ItemHasAttachment", StringComparison.Ordinal)) { activationRule = new ItemHasAttachmentRule(); return(true); } if (node.ChildNodes != null && 0 < node.ChildNodes.Count && string.Equals(a, "RuleCollection", StringComparison.Ordinal)) { ActivationRule[] array = new ActivationRule[node.ChildNodes.Count]; int num = 0; foreach (object obj in node.ChildNodes) { XmlNode xmlNode = (XmlNode)obj; ActivationRule activationRule2; if (this.IsExpectedOweNamespace(xmlNode.NamespaceURI) && string.Equals(xmlNode.LocalName, "Rule", StringComparison.Ordinal) && this.TryCreateActivationRuleInternal(xmlNode, out activationRule2)) { array[num++] = activationRule2; } } xmlAttribute = node.Attributes["Mode"]; activationRule = new CollectionRule((xmlAttribute == null) ? "Or" : xmlAttribute.Value, array); return(true); } } return(false); } ItemIsRuleItemType itemType; if (EnumValidator.TryParse <ItemIsRuleItemType>(node.Attributes["ItemType"].Value, EnumParseOptions.Default, out itemType)) { XmlAttribute xmlAttribute4 = node.Attributes["FormType"]; ItemIsRuleFormType formType; if (xmlAttribute4 == null || !EnumValidator.TryParse <ItemIsRuleFormType>(xmlAttribute4.Value, EnumParseOptions.Default, out formType)) { formType = ItemIsRuleFormType.Read; } bool includeSubClasses = SchemaParser.ParseBoolFromXmlAttribute(node.Attributes["IncludeSubClasses"]); XmlAttribute xmlAttribute5 = node.Attributes["ItemClass"]; activationRule = new ItemIsRule(itemType, (xmlAttribute5 != null) ? xmlAttribute5.Value : null, includeSubClasses, formType); return(true); } return(false); }
public void ValidateRules() { RequestedCapabilities requestedCapabilities = this.GetRequestedCapabilities(); using (XmlNodeList xmlNodeList = this.xmlDoc.SelectNodes(this.GetOweXpath("Rule"), this.namespaceManager)) { int num = 0; int num2 = 0; HashSet <string> hashSet = null; HashSet <string> hashSet2 = null; int num3 = 0; foreach (object obj in xmlNodeList) { XmlNode xmlNode = (XmlNode)obj; XmlAttribute attribute = xmlNode.Attributes["type", "http://www.w3.org/2001/XMLSchema-instance"]; string a; if (ExtensionDataHelper.TryGetNameSpaceStrippedAttributeValue(attribute, out a)) { if (string.Equals(a, "RuleCollection", StringComparison.Ordinal)) { num2++; } else { num++; } if (num > 15 || num2 > 15) { throw new OwaExtensionOperationException(Strings.ErrorInvalidManifestData(Strings.ErrorReasonTooManyRule(15))); } if (string.Equals(a, "ItemIs", StringComparison.Ordinal)) { SchemaParser.ValidateItemIsRule(xmlNode); } else if (string.Equals(a, "ItemHasKnownEntity", StringComparison.Ordinal)) { SchemaParser.ValidateItemHasKnownEntityRule(xmlNode, requestedCapabilities, ref hashSet2, ref num3); } else if (string.Equals(a, "ItemHasRegularExpressionMatch", StringComparison.Ordinal)) { num3++; if (hashSet == null) { hashSet = new HashSet <string>(); } string attributeStringValue = ExtensionData.GetAttributeStringValue(xmlNode, "RegExName"); if (!hashSet.Add(attributeStringValue)) { throw new OwaExtensionOperationException(Strings.ErrorInvalidManifestData(Strings.ErrorReasonMultipleRulesWithSameRegExName(attributeStringValue))); } if (requestedCapabilities == RequestedCapabilities.Restricted) { throw new OwaExtensionOperationException(Strings.ErrorInvalidManifestData(Strings.ErrorReasonNoRegexRuleInRestricted)); } if (num3 > 5) { throw new OwaExtensionOperationException(Strings.ErrorInvalidManifestData(Strings.ErrorReasonTooManyRegexRule(5))); } SchemaParser.ValidateRegEx(attributeStringValue, ExtensionData.GetAttributeStringValue(xmlNode, "RegExValue"), "ItemHasRegularExpressionMatch", "RegExValue"); } } } } }