public static AutoDiscoverProperties GetAutoDiscoverProperties(
ITestSite site,
string server,
string userName,
string domain,
string requestURL,
string transport)
{
HttpStatusCode httpStatusCode = HttpStatusCode.Unused;
XmlDocument doc = new XmlDocument();
XmlNodeList elemList = null;
string requestXML = string.Empty;
string responseXML = string.Empty;
AutoDiscoverProperties autoDiscoverProperties = new AutoDiscoverProperties
{
PrivateMailboxServer = null,
PrivateMailboxProxy = null,
PublicMailboxServer = null,
PublicMailboxProxy = null,
PublicMailStoreUrl = null,
PrivateMailStoreUrl = null,
AddressBookUrl = null
};
// Get auto discover properties for private mailbox
requestXML = "<Autodiscover xmlns=\"http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006\">" +
"<Request><EMailAddress>" + userName + "@" + domain + "</EMailAddress><AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a</AcceptableResponseSchema></Request></Autodiscover>";
if (transport == "mapi_http")
{
httpStatusCode = SendHttpPostRequest(site, userName, domain, requestXML, requestURL, out responseXML, true);
site.Assert.AreEqual<HttpStatusCode>(HttpStatusCode.OK, httpStatusCode, "Http status code should be 200 (OK), the error code is {0}", httpStatusCode);
doc.LoadXml(responseXML);
elemList = doc.GetElementsByTagName("MailStore");
site.Assert.IsTrue(elemList != null && elemList.Count > 0, "MailStore element should exist in response.");
string mailStoreUrl = GetMAPIInternalURLProperty(elemList);
site.Assert.IsFalse(string.IsNullOrEmpty(mailStoreUrl), "The mailstore internal URL should be gotten under MailStore element");
autoDiscoverProperties.PrivateMailStoreUrl = mailStoreUrl; // Add private mailbox server
elemList = doc.GetElementsByTagName("AddressBook");
site.Assert.IsTrue(elemList != null && elemList.Count > 0, "AddressBook element should exist in response.");
string addressBookUri = GetMAPIInternalURLProperty(elemList);
site.Assert.IsFalse(string.IsNullOrEmpty(addressBookUri), "The AddressBook internal URL should be gotten under AddressBook element");
autoDiscoverProperties.AddressBookUrl = addressBookUri;
}
else
{
httpStatusCode = SendHttpPostRequest(site, userName, domain, requestXML, requestURL, out responseXML, false);
site.Assert.AreEqual<HttpStatusCode>(HttpStatusCode.OK, httpStatusCode, "Http status code should be 200 (OK), the error code is {0}", httpStatusCode);
doc.LoadXml(responseXML);
elemList = doc.GetElementsByTagName("PublicFolderInformation");
if (elemList == null || elemList.Count == 0)
{
// Not found PublicFolderInformation means the SUT is not Microsoft Exchange Server 2013, in this case, proxy will not be changed and using original server name.
// For Microsoft Exchange Server 2010 the private mailbox server should be same as public folder server
autoDiscoverProperties.PrivateMailboxServer = server; // Add private mailbox server
autoDiscoverProperties.PublicMailboxServer = server; // Add public mailbox server
return autoDiscoverProperties;
}
// That the PublicFolderInformation is found means that the SUT is Microsoft Exchange Server 2013, in this case, get server name and proxy information for both private mailbox and public folder.
elemList = doc.GetElementsByTagName("Protocol");
site.Assert.IsTrue(elemList != null && elemList.Count > 0, "Protocol element should exist in response.");
string privateMailboxServer = GetServerNameProperty(elemList);
site.Assert.IsFalse(string.IsNullOrEmpty(privateMailboxServer), "The private mailbox server name should be gotten under Protocol element");
string privateMailboxProxy = GetServerProxyProperty(elemList);
site.Assert.IsFalse(string.IsNullOrEmpty(privateMailboxProxy), "The private mailbox server proxy should be gotten under Protocol element");
autoDiscoverProperties.PrivateMailboxServer = privateMailboxServer; // Add private mailbox server
autoDiscoverProperties.PrivateMailboxProxy = privateMailboxProxy; // Add private mailbox proxy
}
// Get auto discover properties for public mailbox
string smtpAddress = "PublicFolderMailbox_" + server + "@" + domain;
requestXML = "<Autodiscover xmlns=\"http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006\">" +
"<Request><EMailAddress>" + smtpAddress + "</EMailAddress><AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a</AcceptableResponseSchema></Request></Autodiscover>";
responseXML = string.Empty;
if (transport == "mapi_http")
{
httpStatusCode = SendHttpPostRequest(site, userName, domain, requestXML, requestURL, out responseXML, true);
site.Assert.AreEqual<HttpStatusCode>(HttpStatusCode.OK, httpStatusCode, "Http status code should be 200 (OK), the error code is {0}", httpStatusCode);
doc.LoadXml(responseXML);
elemList = doc.GetElementsByTagName("MailStore");
site.Assert.IsTrue(elemList != null && elemList.Count > 0, "MailStore element should exist in response.");
string publicMailStoreUrl = GetMAPIInternalURLProperty(elemList);
site.Assert.IsFalse(string.IsNullOrEmpty(publicMailStoreUrl), "The public folder mailbox server name should be gotten under MailStore element");
autoDiscoverProperties.PublicMailStoreUrl = publicMailStoreUrl; // Add public mailbox server
}
else
{
httpStatusCode = SendHttpPostRequest(site, userName, domain, requestXML, requestURL, out responseXML, false);
site.Assert.AreEqual<HttpStatusCode>(HttpStatusCode.OK, httpStatusCode, "Http status code should be 200 (OK), the error code is {0}", httpStatusCode);
doc.LoadXml(responseXML);
elemList = doc.GetElementsByTagName("Protocol");
site.Assert.IsTrue(elemList != null && elemList.Count > 0, "There should be an element called Protocol.");
string publicMailboxServer = GetServerNameProperty(elemList);
site.Assert.IsFalse(string.IsNullOrEmpty(publicMailboxServer), "The public folder mailbox server name should be gotten under Protocol element");
string publicMailboxProxy = GetServerProxyProperty(elemList);
site.Assert.IsFalse(string.IsNullOrEmpty(publicMailboxProxy), "The public folder mailbox server proxy should be gotten under Protocol element");
autoDiscoverProperties.PublicMailboxServer = publicMailboxServer; // Add public mailbox server
autoDiscoverProperties.PublicMailboxProxy = publicMailboxProxy; // Add public mailbox proxy
}
return autoDiscoverProperties;
}