/// <summary> /// Gets a list of attribute values from a regular expression match /// </summary> /// <param name="attribute">The attribute to return the values for</param> /// <param name="mapping">The multivalued extract mapping, or null, if this is a single valued attribute</param> /// <param name="match">The regular expression match to extract the values from</param> /// <param name="operation">The current operation being performed</param> /// <returns>A list of values for the specified attribute</returns> private static IList <object> GetAttributeValuesFromMatch(MASchemaAttribute attribute, MultiValueExtract mapping, Match match, ImportOperationBase operation) { List <object> values = new List <object>(); string captureGroupName = mapping == null ? attribute.Name : mapping.CaptureGroupName; Group group = match.Groups[captureGroupName]; if (!group.Success) { return(null); } if (attribute.IsMultiValued) { if (mapping == null) { values.Add(group.Value); return(values); } else { MatchCollection matchCollection = Regex.Matches(group.Value, mapping.MappingRegEx, RegexOptions.Multiline); foreach (Match subMatch in matchCollection) { values.Add(subMatch.Value); } } } else { values.Add(group.Value); } return(values); }
/// <summary> /// Applies a set of transforms to the specified attribute /// </summary> /// <param name="attribute">The definition of the attribute to transform</param> /// <param name="operation">The operation being performed</param> /// <param name="values">The values to transform</param> /// <returns>A list of transformed values</returns> private static IList <object> TransformAttributeValues(MASchemaAttribute attribute, ImportOperationBase operation, IList <object> values) { AttributeTransformation transformation = operation.AttributeTransformations.FirstOrDefault(t => t.Attribute.Name == attribute.Name); if (transformation == null) { return(values); } List <object> newValues = new List <object>(); foreach (object value in values) { string newValue = Regex.Replace(value.ToString(), transformation.RegexFind, transformation.RegexReplace); newValues.Add(newValue); } return(newValues); }
/// <summary> /// Gets an enumeration of expanded attribute value declarations for a multi-valued attribute /// </summary> /// <param name="csentry">The source object</param> /// <param name="multiValuedAttribute">The multi-valued attribute to expand</param> /// <param name="modificationType">Specifies which value modification types to expand during the enumeration</param> /// <returns>An enumeration of expanded declaration strings</returns> public IEnumerable <string> ExpandDeclarationWithMultiValued(CSEntryChange csentry, MASchemaAttribute multiValuedAttribute, ValueModificationType modificationType) { if (csentry == null) { yield return(this.DeclarationText); } string constructedValue = this.DeclarationText; foreach (ReferencedAttribute reference in this.AttributeReferences.Where(t => t.AttributeName != multiValuedAttribute.Name)) { if (MASchema.GetAttributeType(reference.AttributeName) == AttributeType.Reference) { constructedValue = constructedValue.Replace(reference.Declaration, this.GetReferencedDNComponent(csentry, reference)); } else { constructedValue = constructedValue.Replace(reference.Declaration, this.GetSourceAttributeValue(csentry, reference, false, false) ?? string.Empty); } } ReferencedAttribute mvattribute = this.AttributeReferences.FirstOrDefault(t => t.AttributeName == multiValuedAttribute.Name); if (mvattribute != null && csentry.AttributeChanges.Contains(multiValuedAttribute.Name)) { AttributeChange change = csentry.AttributeChanges[multiValuedAttribute.Name]; foreach (string value in this.GetSourceAttributeValues(change, mvattribute, modificationType)) { yield return(constructedValue.Replace(mvattribute.Declaration, value)); } } else { yield return(constructedValue); } yield break; }
/// <summary> /// Extracts a list of attribute values from a regular expression match /// </summary> /// <param name="attribute">The definition of the attribute to extract</param> /// <param name="match">The regular expression match containing the values to extract</param> /// <param name="operation">The operation being performed</param> /// <returns>A list of attribute values extracted from the source</returns> private static IList <object> GetAttributeValuesFromMatch(MASchemaAttribute attribute, Match match, ImportOperationBase operation) { return(GetAttributeValuesFromMatch(attribute, null, match, operation)); }