LoadFromXml method

Future<void> LoadFromXml(
  1. EwsServiceXmlReader reader,
  2. String xmlElementName
)
Loads response from XML. The reader. Name of the XML element.

Implementation

Future<void> LoadFromXml(
    EwsServiceXmlReader reader, String xmlElementName) async {
  if (!reader.IsStartElementWithNamespace(
      XmlNamespace.Messages, xmlElementName)) {
    await reader.ReadStartElementWithNamespace(
        XmlNamespace.Messages, xmlElementName);
  }

  this._result = reader.ReadAttributeValue<ServiceResult>(
      XmlAttributeNames.ResponseClass);

  if (this._result == ServiceResult.Success ||
      this._result == ServiceResult.Warning) {
    if (this._result == ServiceResult.Warning) {
      this._errorMessage = await reader.ReadElementValueWithNamespace(
          XmlNamespace.Messages, XmlElementNames.MessageText);
    }

    this._errorCode =
        await reader.ReadElementValueWithNamespace<ServiceError>(
            XmlNamespace.Messages, XmlElementNames.ResponseCode);

    if (this._result == ServiceResult.Warning) {
      await reader.ReadElementValueWithNamespace<int>(
          XmlNamespace.Messages, XmlElementNames.DescriptiveLinkKey);
    }

    // If batch processing stopped, EWS returns an empty element. Skip over it.
    if (this.BatchProcessingStopped) {
      do {
        await reader.Read();
      } while (!reader.IsEndElementWithNamespace(
          XmlNamespace.Messages, xmlElementName));
    } else {
      await this.ReadElementsFromXml(reader);

      await reader.ReadEndElementIfNecessary(
          XmlNamespace.Messages, xmlElementName);
    }
  } else {
    this._errorMessage = await reader.ReadElementValueWithNamespace(
        XmlNamespace.Messages, XmlElementNames.MessageText);
    this._errorCode =
        await reader.ReadElementValueWithNamespace<ServiceError>(
            XmlNamespace.Messages, XmlElementNames.ResponseCode);
    await reader.ReadElementValueWithNamespace<int>(
        XmlNamespace.Messages, XmlElementNames.DescriptiveLinkKey);

    while (!reader.IsEndElementWithNamespace(
        XmlNamespace.Messages, xmlElementName)) {
      await reader.Read();

      if (reader.IsStartElement()) {
        if (!await this
            .LoadExtraErrorDetailsFromXml(reader, reader.LocalName)) {
          await reader.SkipCurrentElement();
        }
      }
    }
  }

  this.MapErrorCodeToErrorMessage();

  this.Loaded();
}