Created
November 29, 2017 21:35
-
-
Save aidapsibr/1751c67e861ad8f44c3e823f6209a193 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async Task<SingleItemExportResponseProperties> ParseResponsePropertiesAsync(XmlReader soapResponse) | |
{ | |
var responseProperties = new SingleItemExportResponseProperties(); | |
while (await soapResponse.ReadAsync().ConfigureAwait(false)) | |
{ | |
if (IsServerVersionElement()) | |
{ | |
// Not currently parsing this element. | |
} | |
else if (IsFaultCodeElement()) | |
responseProperties.FaultCode = soapResponse.ReadString(); | |
else if (IsFaultStringElement()) | |
responseProperties.FaultString = soapResponse.ReadString(); | |
else if (IsResponseCodeElement()) | |
responseProperties.ResponseCode = soapResponse.ReadString(); | |
else if (IsMessageElement()) | |
responseProperties.Message = soapResponse.ReadString(); | |
else if (IsMessageXmlElement()) | |
{ | |
while (soapResponse.Read()) | |
{ | |
if (IsValueElement()) | |
{ | |
var attribute = soapResponse.GetAttribute("Name"); | |
var value = soapResponse.ReadString(); | |
if (attribute != null && attribute == "BackOffMilliseconds" && !string.IsNullOrEmpty(value)) | |
responseProperties.BackOffMilliseconds = long.Parse(value); | |
} | |
if (IsNotMessageXmlEndElement()) | |
await soapResponse.ReadAsync(); | |
else | |
break; | |
} | |
} | |
else if (IsLineElement()) | |
{ | |
var value = soapResponse.ReadString(); | |
if (!string.IsNullOrEmpty(value)) | |
responseProperties.Line = int.Parse(value); | |
} | |
else if (IsPositionElement()) | |
{ | |
var value = soapResponse.ReadString(); | |
if (!string.IsNullOrEmpty(value)) | |
responseProperties.Position = int.Parse(value); | |
} | |
else if (IsDataElement()) | |
{ | |
await soapResponse.ReadAsync().ConfigureAwait(false); | |
break; | |
} | |
} | |
return responseProperties; | |
bool IsServerVersionElement() => | |
soapResponse.IsStartElement() | |
&& soapResponse.LocalName == "ServerVersionInfo" | |
&& soapResponse.NamespaceURI == "http://schemas.microsoft.com/exchange/services/2006/types"; | |
bool IsFaultCodeElement() => | |
soapResponse.IsStartElement() | |
&& soapResponse.LocalName == "faultcode" | |
&& soapResponse.NamespaceURI == ""; | |
bool IsFaultStringElement() => | |
soapResponse.IsStartElement() | |
&& soapResponse.LocalName == "faultstring" | |
&& soapResponse.NamespaceURI == ""; | |
bool IsResponseCodeElement() => | |
soapResponse.IsStartElement() | |
&& soapResponse.LocalName == "ResponseCode" | |
&& soapResponse.NamespaceURI == "http://schemas.microsoft.com/exchange/services/2006/errors"; | |
bool IsMessageElement() => | |
soapResponse.IsStartElement() | |
&& soapResponse.LocalName == "Message" | |
&& soapResponse.NamespaceURI == "http://schemas.microsoft.com/exchange/services/2006/errors"; | |
bool IsMessageXmlElement() => | |
soapResponse.IsStartElement() | |
&& soapResponse.LocalName == "MessageXml" | |
&& soapResponse.NamespaceURI == "http://schemas.microsoft.com/exchange/services/2006/types"; | |
bool IsNotMessageXmlEndElement() => | |
soapResponse.LocalName != "MessageXml" | |
|| soapResponse.NamespaceURI != "http://schemas.microsoft.com/exchange/services/2006/types" | |
|| soapResponse.NodeType != XmlNodeType.EndElement | |
&& !soapResponse.IsEmptyElement; | |
bool IsValueElement() => | |
soapResponse.IsStartElement() | |
&& soapResponse.LocalName == "Value" | |
&& soapResponse.NamespaceURI == "http://schemas.microsoft.com/exchange/services/2006/types"; | |
bool IsLineElement() => | |
soapResponse.IsStartElement() | |
&& soapResponse.LocalName == "Line" | |
&& soapResponse.NamespaceURI == "http://schemas.microsoft.com/exchange/services/2006/errors"; | |
bool IsPositionElement() => | |
soapResponse.IsStartElement() | |
&& soapResponse.LocalName == "Position" | |
&& soapResponse.NamespaceURI == "http://schemas.microsoft.com/exchange/services/2006/errors"; | |
bool IsDataElement() => | |
soapResponse.IsStartElement("Data", ExchangeMessagesNamespace); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment