GetSettings<TGetSettingsResponseCollection, TSettingName> method
Future<TGetSettingsResponseCollection>
GetSettings<TGetSettingsResponseCollection, TSettingName>(
- List<
String> identities, - List<
TSettingName> settings, - ExchangeVersion? requestedVersion,
- GetSettingsMethod<
TGetSettingsResponseCollection, TSettingName> getSettingsMethod, - GetDomainCallback getDomainMethod,
Implementation
/// </summary>
/// <typeparam name="TGetSettingsResponseCollection">Type of response collection to return.</typeparam>
/// <typeparam name="TSettingName">Type of setting name.</typeparam>
/// <param name="identities">Either the domains or the SMTP addresses of the users.</param>
/// <param name="settings">The settings.</param>
/// <param name="requestedVersion">Requested version of the Exchange service.</param>
/// <param name="getSettingsMethod">The method to use.</param>
/// <param name="getDomainMethod">The method to calculate the domain value.</param>
/// <returns></returns>
/* private */
Future<TGetSettingsResponseCollection>
GetSettings<TGetSettingsResponseCollection, TSettingName>(
List<String> identities,
List<TSettingName> settings,
ExchangeVersion? requestedVersion,
GetSettingsMethod<TGetSettingsResponseCollection, TSettingName>
getSettingsMethod,
GetDomainCallback getDomainMethod) async {
TGetSettingsResponseCollection response;
// Autodiscover service only exists in E14 or later.
if (this.RequestedServerVersion.index <
_MinimumRequestVersionForAutoDiscoverSoapService.index) {
throw new ServiceVersionException("""string.Format(
Strings.AutodiscoverServiceIncompatibleWithRequestVersion,
MinimumRequestVersionForAutoDiscoverSoapService)""");
}
// If Url is specified, call service directly.
if (this.Url != null) {
OutParam<Uri> autodiscoverUrl = OutParam();
autodiscoverUrl.param = this.Url;
response = await getSettingsMethod(
identities, settings, requestedVersion, autodiscoverUrl);
this.Url = autodiscoverUrl.param;
return response;
}
// If Domain is specified, determine endpoint Url and call service.
else if (!StringUtils.IsNullOrEmpty(this.Domain)) {
OutParam<String> hostOutParam = OutParam()..param = this.Domain;
OutParam<Uri> autodiscoverUrl = OutParam();
autodiscoverUrl.param =
await this._GetAutodiscoverEndpointUrl(hostOutParam);
this.Domain = hostOutParam.param;
response = await getSettingsMethod(
identities, settings, requestedVersion, autodiscoverUrl);
// If we got this far, response was successful, set Url.
this.Url = autodiscoverUrl.param;
return response;
}
// No Url or Domain specified, need to figure out which endpoint(s) to try.
else {
// Assume caller is not inside the Intranet, regardless of whether SCP Urls
// were returned or not. SCP Urls are only relevent if one of them returns
// valid Autodiscover settings.
this.IsExternal = true;
OutParam<Uri> autodiscoverUrlOutParam = OutParam();
String domainName = getDomainMethod();
OutParam<int> scpHostCountOutParam = OutParam();
List<String> hosts = await this
.GetAutodiscoverServiceHosts(domainName, scpHostCountOutParam);
if (hosts.length == 0) {
throw new ServiceValidationException(
"Strings.AutodiscoverServiceRequestRequiresDomainOrUrl");
}
for (int currentHostIndex = 0;
currentHostIndex < hosts.length;
currentHostIndex++) {
OutParam<String> hostOutParam = OutParam()
..param = hosts[currentHostIndex];
bool isScpHost = currentHostIndex < scpHostCountOutParam.param!;
if (await this._TryGetAutodiscoverEndpointUrl(
hostOutParam, autodiscoverUrlOutParam)) {
try {
response = await getSettingsMethod(identities, settings,
requestedVersion, autodiscoverUrlOutParam);
// If we got this far, the response was successful, set Url.
this.Url = autodiscoverUrlOutParam.param;
// Not external if Autodiscover endpoint found via SCP returned the settings.
if (isScpHost) {
this.IsExternal = false;
}
return response;
} catch (AutodiscoverResponseException) {
// skip
} catch (ServiceRequestException) {
// skip
}
}
}
// Next-to-last chance: try unauthenticated GET over HTTP to be redirected to appropriate service endpoint.
autodiscoverUrlOutParam.param = await this._GetRedirectUrl(domainName);
if ((autodiscoverUrlOutParam.param != null) &&
this.CallRedirectionUrlValidationCallback(
autodiscoverUrlOutParam.param.toString()) &&
await this._TryGetAutodiscoverEndpointUrl(
OutParam()..param = autodiscoverUrlOutParam.param!.host,
autodiscoverUrlOutParam)) {
response = await getSettingsMethod(
identities, settings, requestedVersion, autodiscoverUrlOutParam);
// If we got this far, the response was successful, set Url.
this.Url = autodiscoverUrlOutParam.param;
return response;
}
// Last Chance: try to read autodiscover SRV Record from DNS. If we find one, use
// the hostname returned to construct an Autodiscover endpoint URL.
// TODO: Implement SVR Record from DNS
// autodiscoverUrl = this.GetRedirectionUrlFromDnsSrvRecord(domainName);
// if ((autodiscoverUrl != null) &&
// this.CallRedirectionUrlValidationCallback(autodiscoverUrl.ToString()) &&
// this.TryGetAutodiscoverEndpointUrl(autodiscoverUrl.Host, out autodiscoverUrl))
// {
// response = getSettingsMethod(
// identities,
// settings,
// requestedVersion,
// ref autodiscoverUrl);
//
// // If we got this far, the response was successful, set Url.
// this.Url = autodiscoverUrl;
//
// return response;
// }
// else
// {
throw new AutodiscoverLocalException(
"Strings.AutodiscoverCouldNotBeLocated");
// }
}
}