ValidateTargetVersion static method
void
ValidateTargetVersion(
- String? version
)
Validates a new-style version string.
This validation is not as strict as server-side validation.
the version string
Implementation
static void ValidateTargetVersion(String? version) {
const String ParameterSeparator = ';';
const String LegacyVersionPrefix = "Exchange20";
const String ParameterValueSeparator = '=';
const String ParameterName = "minimum";
if (StringUtils.IsNullOrEmpty(version)) {
throw new ArgumentException("Target version must not be empty.");
}
List<String> parts = version!.trim().split(ParameterSeparator);
switch (parts.length) {
case 1:
// Validate the header value. We allow X.Y or Exchange20XX.
String part1 = parts[0].trim();
if (parts[0].startsWith(LegacyVersionPrefix)) {
// Close enough; misses corner cases like "Exchange2001". Server will do complete validation.
} else if (ExchangeService.IsMajorMinor(part1)) {
// Also close enough; misses corner cases like ".5".
} else {
throw new ArgumentException(
"Target version must match X.Y or Exchange20XX.");
}
break;
case 2:
// Validate the optional minimum version parameter, "minimum=X.Y"
String part2 = parts[1].trim();
List<String> minParts = part2.split(ParameterValueSeparator);
if (minParts.length == 2 &&
minParts[0].trim().toLowerCase() == ParameterName.toLowerCase() &&
ExchangeService.IsMajorMinor(minParts[1].trim())) {
String part1 = parts[0].trim();
if (parts[0].startsWith(LegacyVersionPrefix)) {
// Close enough; misses corner cases like "Exchange2001". Server will do complete validation.
} else if (ExchangeService.IsMajorMinor(part1)) {
// Also close enough; misses corner cases like ".5".
} else {
throw new ArgumentException(
"Target version must match X.Y or Exchange20XX.");
}
break;
}
throw new ArgumentException(
"Target version must match X.Y or Exchange20XX.");
default:
throw new ArgumentException("Target version should have the form.");
}
}