GetEwsUrlFromResponse method

Uri GetEwsUrlFromResponse(
  1. GetUserSettingsResponse response,
  2. bool isExternal
)
Gets the EWS URL from Autodiscover GetUserSettings response. The response. If true, Autodiscover call was made externally.

Implementation

Uri GetEwsUrlFromResponse(GetUserSettingsResponse response, bool isExternal) {
  OutParam<String> uriStringOutParam = OutParam();

  // Figure out which URL to use: Internal or External.
  // AutoDiscover may not return an external protocol. First try external, then internal.
  // Either protocol may be returned without a configured URL.
  if ((isExternal &&
          response.TryGetSettingValue<String>(
              UserSettingName.ExternalEwsUrl, uriStringOutParam)) &&
      !StringUtils.IsNullOrEmpty(uriStringOutParam.param)) {
    return Uri.parse(uriStringOutParam.param!);
  } else if ((response.TryGetSettingValue<String>(
              UserSettingName.InternalEwsUrl, uriStringOutParam) ||
          response.TryGetSettingValue<String>(
              UserSettingName.ExternalEwsUrl, uriStringOutParam)) &&
      !StringUtils.IsNullOrEmpty(uriStringOutParam.param)) {
    return Uri.parse(uriStringOutParam.param!);
  }

  // If Autodiscover doesn't return an or external EWS URL, throw an exception.
  throw new AutodiscoverLocalException(
      "Strings.AutodiscoverDidNotReturnEwsUrl");
}