Пример #1
0
        private static bool AreValuesEqual(
            [NotNull] EqualFieldValuesCondition condition,
            [NotNull] IRow row1, int tableIndex1,
            [NotNull] IRow row2, int tableIndex2,
            [CanBeNull] out string message,
            [CanBeNull] HashSet <string> unequalFieldNames = null)
        {
            StringBuilder sb = null;

            foreach (UnequalField unequalField in condition.GetNonEqualFields(
                         row1, tableIndex1,
                         row2, tableIndex2))
            {
                if (sb == null)
                {
                    sb = new StringBuilder();
                }

                sb.AppendFormat(sb.Length == 0
                                                        ? "{0}"
                                                        : ";{0}", unequalField.Message);

                unequalFieldNames?.Add(unequalField.FieldName.ToUpper());
            }

            if (sb != null)
            {
                message = sb.ToString();
                return(false);
            }

            message = null;
            return(true);
        }
Пример #2
0
        GetAttributeConstraintViolations(
            [NotNull] IFeature feature, int classIndex,
            [NotNull] IFeature neighborFeature, int neighborClassIndex,
            [NotNull] RowPairCondition rowPairCondition,
            [NotNull] EqualFieldValuesCondition equalFieldValuesCondition,
            bool reportIndividually = false)
        {
            if (reportIndividually)
            {
                string       message;
                IColumnNames errorColumnNames;
                if (!rowPairCondition.IsFulfilled(feature, classIndex,
                                                  neighborFeature,
                                                  neighborClassIndex,
                                                  out message,
                                                  out errorColumnNames))
                {
                    var affectedFields = new HashSet <string>(
                        errorColumnNames.GetInvolvedColumnNames(),
                        StringComparer.OrdinalIgnoreCase);

                    yield return(new AttributeConstraintViolation(
                                     string.Format(
                                         LocalizableStrings
                                         .EdgeMatchUtils_AttributeConstraints_ConstraintNotFulfilled,
                                         message), affectedFields, message));
                }

                IEnumerable <UnequalField> unequalFields =
                    equalFieldValuesCondition.GetNonEqualFields(feature, classIndex,
                                                                neighborFeature,
                                                                neighborClassIndex);
                foreach (UnequalField unequalField in unequalFields)
                {
                    yield return(new AttributeConstraintViolation(
                                     string.Format(
                                         LocalizableStrings.EdgeMatchUtils_AttributeConstraints_ValuesNotEqual,
                                         unequalField.Message), unequalField.FieldName, unequalField.Message));
                }
            }
            else
            {
                string description;
                string affectedComponents;
                string textValue;
                bool   areConstraintsFulfilled = AreAttributeConstraintsFulfilled(
                    feature, classIndex,
                    neighborFeature, neighborClassIndex,
                    rowPairCondition,
                    equalFieldValuesCondition,
                    out description, out affectedComponents, out textValue);

                if (!areConstraintsFulfilled)
                {
                    yield return(new AttributeConstraintViolation(description,
                                                                  affectedComponents,
                                                                  textValue));
                }
            }
        }
Пример #3
0
        private static bool AreAttributeConstraintsFulfilled(
            [NotNull] IFeature feature, int classIndex,
            [NotNull] IFeature neighborFeature, int neighborClassIndex,
            [NotNull] RowPairCondition rowPairCondition,
            [NotNull] EqualFieldValuesCondition equalFieldValuesCondition,
            [NotNull] out string errorDescription,
            [CanBeNull] out string affectedComponents,
            [NotNull] out string textValue)
        {
            var affectedFields = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            // compare attributes that are required to match
            var          descriptionBuilder = new StringBuilder();
            var          textValueBuilder   = new StringBuilder();
            string       message;
            IColumnNames errorColumnNames;

            if (!rowPairCondition.IsFulfilled(feature, classIndex,
                                              neighborFeature,
                                              neighborClassIndex,
                                              out message,
                                              out errorColumnNames))
            {
                descriptionBuilder.AppendFormat(
                    LocalizableStrings.EdgeMatchUtils_AttributeConstraints_ConstraintNotFulfilled,
                    message);

                foreach (string affectedColumn in errorColumnNames.GetInvolvedColumnNames())
                {
                    affectedFields.Add(affectedColumn);
                }

                textValueBuilder.Append(message);
            }

            IEnumerable <UnequalField> unequalFields =
                equalFieldValuesCondition.GetNonEqualFields(feature, classIndex,
                                                            neighborFeature, neighborClassIndex);

            if (HasUnequalFields(unequalFields, out message, affectedFields))
            {
                if (descriptionBuilder.Length > 0)
                {
                    descriptionBuilder.Append(". ");
                }

                descriptionBuilder.AppendFormat(
                    LocalizableStrings.EdgeMatchUtils_AttributeConstraints_ValuesNotEqual,
                    message);

                if (textValueBuilder.Length > 0)
                {
                    textValueBuilder.Append("|");
                }

                textValueBuilder.Append(message);
            }

            errorDescription   = descriptionBuilder.ToString();
            affectedComponents = FormatAffectedComponents(affectedFields);
            textValue          = textValueBuilder.ToString();

            return(errorDescription.Length == 0);
        }