/// <summary> /// Match either side of a : delimited string or all of the string including the delimiter /// </summary> /// <param name="hashSet">List of strings</param> /// <param name="foreignKeyValue">string to match</param> /// <returns>true if a match, false if none</returns> private bool PickListMatch(COBieColumnRelationship reference, COBieCell cell) { if (cell.CellValue == Constants.DEFAULT_STRING) { return(false); } if (reference.HasKeyMatch(cell.CellValue)) { return(true); } // There are no current cases where PickLists can have Many to Many mappings - only One to Many. So don't worry about MultipleValues. // Due to the way some Categories/Classifications in Pick lists are compound keys (e.g. 11-11 11 14: Exhibition Hall ... where the code and name are stored separately in IFC) // we need to special case partial matches, since we may have the code, name, or code:name (perhaps with differing white space) if (cell.CellValue.Contains(":")) //assume category split { return(reference.HasPartialMatch(cell.CellValue, ':')); } return(false); }
/// <summary> /// Validate the existence of the Foreign Key value on the referencing sheet, if not add error /// </summary> /// <param name="context">COBieContext object holding global values for this model</param> private void ValidateForeignKeys(COBieWorkbook workbook, ICOBieSheetValidationTemplate SheetValidator) { int rowIndex = 1; foreach (COBieRow row in Rows) { foreach (COBieColumn foreignKeyColumn in ForeignKeyColumns) { // TODO: COBieColumn should own the relationship rather than creating a new one each time. COBieColumnRelationship cobieReference = new COBieColumnRelationship(workbook, foreignKeyColumn); if ((SheetValidator == null) || (SheetValidator.IsRequired.ContainsKey(foreignKeyColumn.ColumnOrder) && SheetValidator.IsRequired[foreignKeyColumn.ColumnOrder]) ) { if (!string.IsNullOrEmpty(foreignKeyColumn.ReferenceColumnName)) { COBieCell cell = row[foreignKeyColumn.ColumnOrder]; string foreignKeyValue = cell.CellValue; // Don't validate nulls. Will be reported by the Foreign Key null value check, so just skip here if (!string.IsNullOrEmpty(foreignKeyValue)) { bool isValid = false; bool isPickList = (cobieReference.SheetName == Constants.WORKSHEET_PICKLISTS); if (isPickList) { isValid = PickListMatch(cobieReference, cell); } else { isValid = ForeignKeyMatch(cobieReference, cell); } //report no match if (!isValid) { string errorDescription = BuildErrorMessage(cobieReference, isPickList); COBieError.ErrorTypes errorType = isPickList == true ? COBieError.ErrorTypes.PickList_Violation : COBieError.ErrorTypes.ForeignKey_Violation; COBieError error = new COBieError(SheetName, foreignKeyColumn.ColumnName, errorDescription, errorType, COBieError.ErrorLevels.Error, row.InitialRowHashValue, foreignKeyColumn.ColumnOrder, rowIndex); _errors.Add(error); } } } } } rowIndex++; } }
private static string BuildErrorMessage(COBieColumnRelationship cobieReference, bool isPickList) { string errFieldName = cobieReference.ColumnName; //get the correct Pick list column name depending on template for the category columns only, for now if (isPickList && (cobieReference.ColumnName.Contains("Category"))) { errFieldName = ErrorDescription.ResourceManager.GetString(cobieReference.ColumnName.Replace("-", "")); //strip out the "-" to get the resource, (resource did not like the '-' in the name) } if (string.IsNullOrEmpty(errFieldName)) //if resource not found then reset back to field name { errFieldName = cobieReference.ColumnName; } string errorDescription = String.Format(ErrorDescription.PickList_Violation, cobieReference.SheetName, errFieldName); return(errorDescription); }
/// <summary> /// Match the Foreign Key with the primary key field /// </summary> /// <param name="reference">The COBie Index to cross reference</param> /// <param name="cell">The COBie Cell to validate</param> /// <returns>bool</returns> private bool ForeignKeyMatch(COBieColumnRelationship reference, COBieCell cell) { if (reference.HasKeyMatch(cell.CellValue)) { return(true); } if (cell.COBieColumn.AllowsMultipleValues == true) { foreach (string value in cell.CellValues) { if (!reference.HasKeyMatch(value)) { return(false); } } return(true); } return(false); }