public void ValidateFieldsMapping(IValidationContext context)
        {
            if (context.Config.FieldReplacements == null)
            {
                return;
            }

            foreach (var sourceToTargetFields in context.Config.FieldReplacements)
            {
                string         sourceField    = sourceToTargetFields.Key;
                TargetFieldMap targetFieldMap = sourceToTargetFields.Value;

                if (context.FieldsThatRequireSourceProjectToBeReplacedWithTargetProject.Contains(sourceField, StringComparer.OrdinalIgnoreCase) || context.FieldsThatRequireSourceProjectToBeReplacedWithTargetProject.Contains(targetFieldMap.FieldReferenceName, StringComparer.OrdinalIgnoreCase))
                {
                    string unsupportedFields = string.Join(", ", context.FieldsThatRequireSourceProjectToBeReplacedWithTargetProject);
                    throw new ValidationException($"Source fields or field-reference-name cannot be set to any of: {unsupportedFields} in the configuration file.");
                }

                if (!context.SourceFields.ContainsKeyIgnoringCase(sourceField))
                {
                    throw new ValidationException($"Source fields do not contain {sourceField} that is specified in the configuration file.");
                }

                if (targetFieldMap.Value != null && targetFieldMap.FieldReferenceName != null)
                {
                    throw new ValidationException($"Under fields in config, for source field: {sourceField}, you must specify value or field-reference-name, but not both.");
                }
                else if (targetFieldMap.Value == null && string.IsNullOrEmpty(targetFieldMap.FieldReferenceName))
                {
                    throw new ValidationException($"Under fields in config, for source field: {sourceField}, you must specify value or field-reference-name.");
                }
                else if (!string.IsNullOrEmpty(targetFieldMap.FieldReferenceName))
                {
                    if (!context.TargetFields.ContainsKeyIgnoringCase(targetFieldMap.FieldReferenceName))
                    {
                        throw new ValidationException($"Target does not contain the field-reference-name you provided: {targetFieldMap.FieldReferenceName}.");
                    }
                }
            }
        }
예제 #2
0
        public static bool TryGetValueIgnoringCase(this IDictionary <string, TargetFieldMap> dictionary, string desiredKeyOfAnyCase, out TargetFieldMap value)
        {
            var key = GetKeyIgnoringCase(dictionary, desiredKeyOfAnyCase);

            if (key != null)
            {
                return(dictionary.TryGetValue(key, out value));
            }
            else
            {
                value = null;
                return(false);
            }
        }