private static void InsertFieldValue(string xmlFileNamePath, FieldGroup thisFieldGroup, string value, bool isMismatched = false) { Array.Resize(ref thisFieldGroup.Values, thisFieldGroup.Values.Length + 1); thisFieldGroup.Values[thisFieldGroup.Values.Length - 1] = new FieldValue(xmlFileNamePath, value) { IsMismatched = isMismatched }; }
private void InsertFieldValueWithBackfill(string xmlFileNamePath, FieldGroup thisFieldGroup, TypeMetadata typeMetadata, string value) { // We want to keep the values array length consistent with the number of results, even for results // that are missing metadata. We do that here. BackfillFieldGroupValuesForMissingMetadata(xmlFileNamePath, thisFieldGroup, typeMetadata); InsertFieldValue(xmlFileNamePath, thisFieldGroup, value); }
private static void DetermineIfMismatchExists(TypeMetadata typeMetadata, FieldGroup thisFieldGroup) { // fieldGroup.Values is sorted by result name; the first element in this array // is considered to be the reference point, regardless if it's a "baseline" or not. if (typeMetadata.FieldGroups.Any(fg => fg.FieldName.Equals(thisFieldGroup.FieldName)) && thisFieldGroup.Values.Length > 0 && thisFieldGroup.Values[thisFieldGroup.Values.Length - 1].Value != thisFieldGroup.Values[0].Value) { thisFieldGroup.Values[thisFieldGroup.Values.Length - 1].IsMismatched = true; } }
private void BackfillFieldGroupValuesForMissingMetadata(string xmlFileNamePath, FieldGroup fieldGroup, TypeMetadata typeMetadata) { if (fieldGroup.Values.Length < typeMetadata.ValidResultCount + typeMetadata.NullResultCount) { while (fieldGroup.Values.Length < typeMetadata.ValidResultCount + typeMetadata.NullResultCount) { Array.Resize(ref fieldGroup.Values, fieldGroup.Values.Length + 1); fieldGroup.Values[fieldGroup.Values.Length - 1] = new FieldValue(xmlFileNamePath, metadataNotAvailable); // fieldGroup.Values is sorted by result name; the first element in this array // is considered to be the reference point, regardless if it's a "baseline" or not. if (fieldGroup.Values[fieldGroup.Values.Length - 1].Value != fieldGroup.Values[0].Value) { fieldGroup.Values[fieldGroup.Values.Length - 1].IsMismatched = true; } } } }
private void ProcessMetaData(string xmlFileNamePath, FieldInfo[] fieldsToProcess, TypeMetadata typeMetadata, Type metadataType, object obj) { foreach (var field in fieldsToProcess) { var fieldName = field.Name; if (!typeMetadata.FieldGroups.Any(fg => fg.FieldName.Equals(fieldName))) { typeMetadata.FieldGroups.Add(new FieldGroup(fieldName)); } var thisFieldGroup = typeMetadata.FieldGroups.First(fg => fg.FieldName.Equals(fieldName)); if (extraMetadataExtractFields.ContainsKey(fieldName)) { foreach (var extractField in extraMetadataExtractFields[fieldName]) { FieldGroup newFieldGroup; if (!typeMetadata.FieldGroups.Any(fg => fg.FieldName.Equals(extractField.ExtractedFieldName))) { newFieldGroup = new FieldGroup(extractField.ExtractedFieldName); typeMetadata.FieldGroups.Add(newFieldGroup); } else { newFieldGroup = typeMetadata.FieldGroups.First(fg => fg.FieldName.Equals(extractField.ExtractedFieldName)); } var value = GetValueBasedOnType(metadataType, field, obj); extractField.ValueExtracted = ExtractValue(extractField.ExtractionRegex, value); InsertFieldValueWithBackfill(xmlFileNamePath, newFieldGroup, typeMetadata, extractField.ValueExtracted); DetermineIfMismatchExists(typeMetadata, newFieldGroup); } InsertFieldValueWithBackfill(xmlFileNamePath, thisFieldGroup, typeMetadata, MetadataNotAvailable); DetermineIfMismatchExists(typeMetadata, thisFieldGroup); } else { var thisValue = GetValueBasedOnType(metadataType, field, obj); InsertFieldValueWithBackfill(xmlFileNamePath, thisFieldGroup, typeMetadata, thisValue); DetermineIfMismatchExists(typeMetadata, thisFieldGroup); } } foreach (var fieldGroup in typeMetadata.FieldGroups.Where(fg => fg.Values.Length < typeMetadata.ValidResultCount + 1)) { while (fieldGroup.Values.Length < typeMetadata.ValidResultCount + 1) { InsertFieldValue(xmlFileNamePath, fieldGroup, MetadataNotAvailable, isMismatched: true); } } typeMetadata.ValidResultCount++; }