/// <summary> /// Populates the object based on an XML representation /// </summary> /// <param name="node">The XML representation of the object</param> private void FromXml(XmlNode node) { XmlAttribute attributeNameAttribute = node.Attributes["attribute"]; XmlAttribute regexFindAttibute = node.Attributes["regex-find"]; XmlAttribute regexReplaceAttribute = node.Attributes["regex-replace"]; if (attributeNameAttribute == null || string.IsNullOrWhiteSpace(attributeNameAttribute.Value)) { throw new ArgumentNullException("An attribute attribute must be specified"); } else { MASchema.ThrowOnMissingAttribute(attributeNameAttribute.Value); this.Attribute = MASchema.Attributes[attributeNameAttribute.Value]; } if (regexFindAttibute == null || string.IsNullOrWhiteSpace(regexFindAttibute.Value)) { throw new ArgumentNullException("A regex-find attribute must be specified"); } else { this.RegexFind = regexFindAttibute.Value; } if (regexReplaceAttribute == null || string.IsNullOrWhiteSpace(regexReplaceAttribute.Value)) { throw new ArgumentNullException("A regex-replace attribute must be specified"); } else { this.RegexReplace = regexReplaceAttribute.Value; } }
/// <summary> /// Populates the rule based on an XML representation of the object /// </summary> /// <param name="node">The XmlNode representation of the object</param> protected override void FromXml(XmlNode node) { base.FromXml(node); XmlAttribute attributeNameAttribute = node.Attributes["attribute"]; XmlAttribute triggerAttribute = node.Attributes["triggers"]; if (attributeNameAttribute == null || triggerAttribute == null) { throw new ArgumentException("The attribute name and trigger must be specified"); } MASchema.ThrowOnMissingAttribute(attributeNameAttribute.Value); this.AttributeName = attributeNameAttribute.Value; TriggerEvents events; if (Enum.TryParse(triggerAttribute.Value, true, out events)) { this.TriggerEvents = events; } else { throw new ArgumentException("The trigger value is unknown or unsupported"); } }
/// <summary> /// Populates the RuleSet object from an XML representation /// </summary> /// <param name="node">The XML representation of the object</param> protected override void FromXml(XmlNode node) { base.FromXml(node); XmlAttribute attributeNameAttribute = node.Attributes["attribute"]; XmlAttribute operatorAttribute = node.Attributes["operator"]; XmlAttribute valueAttribute = node.Attributes["value"]; if (attributeNameAttribute == null) { throw new ArgumentNullException("The 'attribute' attribute must be specified"); } else { MASchema.ThrowOnMissingAttribute(attributeNameAttribute.Value); this.AttributeName = attributeNameAttribute.Value; } ValueOperator valueOperator = ValueOperator.Equals; if (Enum.TryParse(operatorAttribute.Value, true, out valueOperator)) { this.Operator = valueOperator; } else { throw new ArgumentException(string.Format("The value operator '{0}' is unknown", operatorAttribute.Value)); } if (valueAttribute != null) { this.Value = valueAttribute.Value; } }
/// <summary> /// Populates the object from an XML representation /// </summary> /// <param name="node">The XML representation of the object</param> private void FromXml(XmlNode node) { XmlAttribute attributeNameAttribute = node.Attributes["attribute"]; XmlAttribute operatorAttribute = node.Attributes["operator"]; if (attributeNameAttribute == null) { throw new ArgumentNullException("The 'attribute' attribute must be specified"); } else { MASchema.ThrowOnMissingAttribute(attributeNameAttribute.Value); this.Attribute = MASchema.Attributes[attributeNameAttribute.Value]; } ValueOperator valueOperator = ValueOperator.Equals; if (Enum.TryParse(operatorAttribute.Value, true, out valueOperator)) { this.Operator = valueOperator; } else { throw new ArgumentException(string.Format("The value operator '{0}' is unknown", operatorAttribute.Value)); } this.Value = node.InnerText; }
/// <summary> /// Initializes a new instance of the MASchemaObject class /// </summary> /// <param name="node">The XML representation of the object</param> public MASchemaObject(XmlNode node) : this() { XmlAttribute objectClassAttribute = node.Attributes["object-class"]; if (objectClassAttribute == null || string.IsNullOrWhiteSpace(objectClassAttribute.Value)) { throw new ArgumentException("The schema-entry element must have a 'object-class' attribute"); } this.ObjectClass = objectClassAttribute.Value; XmlNode dnConstructor = node.SelectSingleNode("dn-format"); this.DNFormat = new ValueDeclaration(dnConstructor); if (string.IsNullOrWhiteSpace(this.DNFormat.DeclarationText) || this.DNFormat.AttributeReferences.Count == 0) { throw new ArgumentNullException("A dn-format attribute must be specified and contain at least one attribute reference"); } foreach (XmlNode child in node.SelectNodes("attributes/attribute")) { MASchema.ThrowOnMissingAttribute(child.InnerText); this.Attributes.Add(MASchema.Attributes[child.InnerText]); if (MASchema.Attributes[child.InnerText].CanResurrect) { this.ResurrectionAttributes.Add(MASchema.Attributes[child.InnerText]); } } }
/// <summary> /// Populates the object from its XML representation /// </summary> /// <param name="node">The XML representation of the object</param> private void FromXml(XmlNode node) { XmlAttribute captureGroupAttribute = node.Attributes["capture-group-name"]; XmlAttribute attributeNameAttribute = node.Attributes["attribute"]; if (attributeNameAttribute == null || string.IsNullOrWhiteSpace(attributeNameAttribute.Value)) { throw new ArgumentNullException("The 'attribute' attribute must be specified"); } else { MASchema.ThrowOnMissingAttribute(attributeNameAttribute.Value); this.Attribute = MASchema.Attributes[attributeNameAttribute.Value]; } if (captureGroupAttribute == null || string.IsNullOrWhiteSpace(captureGroupAttribute.Value)) { throw new ArgumentNullException("The 'capture-group-name' attribute must be specified"); } else { this.CaptureGroupName = captureGroupAttribute.Value; } if (string.IsNullOrWhiteSpace(node.InnerText)) { throw new ArgumentNullException("A regular expression capture must be specified"); } this.MappingRegEx = node.InnerText; }
/// <summary> /// Extracts the reference declarations referenced in the specified text /// </summary> /// <param name="value">The string to extract the attributes from</param> private void ExtractAttributeReferences(string value) { this.AttributeReferences.Clear(); Regex regex = new Regex(@"\[(?<preText>[^\]\[]*?)\{((?<referenceAttributeName>\w+)->)?(?<attributeName>\w+)(\:(?<modifier>([^\d]))?(?<count>\d?))?\}(?<postText>.*?)\]|\{((?<referenceAttributeName>\w+)->)?(?<attributeName>(sshma\:)?\w+)(\:(?<modifier>([^\d]))?(?<count>\d?))?\}", RegexOptions.ExplicitCapture); MatchCollection matches = regex.Matches(value); foreach (Match match in matches) { ReferencedAttribute reference = new ReferencedAttribute(); if (match.Groups["attributeName"] != null) { MASchema.ThrowOnMissingAttribute(match.Groups["attributeName"].Value); reference.AttributeName = match.Groups["attributeName"].Value; if (match.Groups["count"] != null && !string.IsNullOrWhiteSpace(match.Groups["count"].Value)) { if (MASchema.GetAttributeType(reference.AttributeName) != AttributeType.Reference) { throw new ArgumentException("A count value is only valid on a 'dn' or reference attribute"); } reference.Count = int.Parse(match.Groups["count"].Value); } if (match.Groups["modifier"] != null && !string.IsNullOrWhiteSpace(match.Groups["modifier"].Value)) { if (MASchema.GetAttributeType(reference.AttributeName) != AttributeType.Reference) { throw new ArgumentException("A modifier value is only valid on a 'dn' or reference attribute"); } reference.Modifier = match.Groups["modifier"].Value; } if (match.Groups["referenceAttributeName"] != null && !string.IsNullOrWhiteSpace(match.Groups["referenceAttributeName"].Value)) { throw new NotSupportedException("This MA does not support referenced attribute declarations"); } if (match.Groups["preText"] != null) { reference.PreReferenceString = match.Groups["preText"].Value; } if (match.Groups["postText"] != null) { reference.PostReferenceString = match.Groups["postText"].Value; } reference.Declaration = match.Value; this.AttributeReferences.Add(reference); } } }
/// <summary> /// Populates the object from an XML representation /// </summary> /// <param name="node">The XML representation of the object</param> private void FromXml(XmlNode node) { XmlAttribute successCodes = node.Attributes["success-codes"]; XmlAttribute forEachAttribute = node.Attributes["for-each"]; XmlAttribute valueModificationTypeAttribute = node.Attributes["value-modification"]; XmlAttribute hasObjectsAttribute = node.Attributes["result-has-objects"]; if (hasObjectsAttribute != null && !string.IsNullOrWhiteSpace(hasObjectsAttribute.Value)) { bool hasObjects = false; if (bool.TryParse(hasObjectsAttribute.Value, out hasObjects)) { this.HasObjects = hasObjects; } else { throw new ArgumentException("The boolean value could not be parsed: " + hasObjectsAttribute.Value); } } if (forEachAttribute != null && !string.IsNullOrWhiteSpace(forEachAttribute.Value)) { MASchema.ThrowOnMissingAttribute(forEachAttribute.Value); this.ForEachAttribute = MASchema.Attributes[forEachAttribute.Value]; } if (successCodes != null) { string[] split = successCodes.Value.Split(','); foreach (string value in split) { int result = 0; if (int.TryParse(value, out result)) { this.SuccessCodes.Add(result); } else { throw new ArgumentException("The specified success code value cannot be converted to an integer: " + value); } } } if (this.SuccessCodes.Count == 0) { this.SuccessCodes.Add(0); } if (valueModificationTypeAttribute == null || string.IsNullOrWhiteSpace(valueModificationTypeAttribute.Value)) { this.ForEachValueModificationType = ValueModificationType.Unconfigured; } else { ValueModificationType valueModificationType = ValueModificationType.Unconfigured; if (Enum.TryParse(valueModificationTypeAttribute.Value, true, out valueModificationType)) { this.ForEachValueModificationType = valueModificationType; } else { throw new ArgumentException("The value modification type is unknown: " + valueModificationTypeAttribute.Value); } } this.Command = new ValueDeclaration(node); }