/// <summary> /// Method to check if a export satifies the import requirements and print that result to the user. /// </summary> /// <param name="import">The ImportDefinition that we want to check against.</param> /// <param name="export">The export we want to compare with.</param> /// <returns> /// A Match Result object indicating if there was a sucessful matches along with messages to /// print out to the user. /// </returns> private MatchResult CheckDefinitionMatch(ImportDefinition import, PartExport export) { MatchResult output = new MatchResult(); var exportDetails = export.ExportDetails; // Make sure that the contract name matches output.SucessfulMatch = import.ContractName.Equals(exportDetails.ContractName); if (!output.SucessfulMatch) { string contractConstraint = string.Format( CultureInfo.CurrentCulture, Strings.ContractNameFormat, import.ContractName); string actualValue = string.Format( CultureInfo.CurrentCulture, Strings.ContractNameFormat, exportDetails.ContractName); string contractFailure = string.Format( CultureInfo.CurrentCulture, Strings.ExpectedFoundFormat, contractConstraint, actualValue); output.Messages.Add(contractFailure); return(output); } // Check all the Import Constraints foreach (var constraint in import.ExportConstraints) { if (!constraint.IsSatisfiedBy(exportDetails)) { string constraintMessage = this.GetConstraintString(constraint, export); output.Messages.Add(constraintMessage); output.SucessfulMatch = false; } } if (output.SucessfulMatch) { output.Messages.Add(Strings.ExportMatchingImport); } return(output); }
/// <summary> /// Method to get a basic description of a given constraint for output. /// </summary> /// <param name="constraint">The Constraint which we want information about.</param> /// <param name="export">The export we are matching the constraint against.</param> /// <returns>A string providing some details about the given constraint.</returns> private string GetConstraintString(IImportSatisfiabilityConstraint constraint, PartExport export) { if (constraint == null || export == null) { return(Strings.DoesNotExists); } string constraintString = constraint.ToString() !; string actualValue = export.ToString() !; // Try to treat the constraint as an indentity constraint if (constraint is ExportTypeIdentityConstraint) { var identityConstraint = (ExportTypeIdentityConstraint)constraint; constraintString = string.Format( CultureInfo.CurrentCulture, Strings.TypeFormat, identityConstraint.TypeIdentityName); actualValue = string.Format( CultureInfo.CurrentCulture, Strings.TypeFormat, export.ExportingType); } else if (constraint is ExportMetadataValueImportConstraint) { // Try to treat the constraint as an metadata constraint var metadataConstraint = (ExportMetadataValueImportConstraint)constraint; var exportDetails = export.ExportDetails; string keyName = metadataConstraint.Name; constraintString = string.Format( CultureInfo.CurrentCulture, Strings.MetadataFormat, keyName, metadataConstraint.Value); string pairValue = Strings.MissingKeyText; if (exportDetails.Metadata.ContainsKey(keyName)) { var keyValue = exportDetails.Metadata[keyName]; pairValue = keyValue != null?keyValue.ToString() !: Strings.DoesNotExists; } actualValue = string.Format( CultureInfo.CurrentCulture, Strings.MetadataFormat, keyName, pairValue); } // If it is neither just return the toString text of the two parameters return(string.Format( CultureInfo.CurrentCulture, Strings.ExpectedFoundFormat, constraintString, actualValue)); }