ReadElementsFromXml method

  1. @override
Future<void> ReadElementsFromXml(
  1. EwsServiceXmlReader reader
)
override
Reads response elements from XML. The reader.

Implementation

@override
Future<void> ReadElementsFromXml(EwsServiceXmlReader reader) async {
  await reader.ReadStartElementWithNamespace(
      XmlNamespace.Messages, XmlElementNames.RootFolder);

  int? totalItemsInView =
      reader.ReadAttributeValue<int>(XmlAttributeNames.TotalItemsInView);
  bool moreItemsAvailable = !reader.ReadAttributeValue<bool>(
      XmlAttributeNames.IncludesLastItemInRange)!;

  // Ignore IndexedPagingOffset attribute if moreItemsAvailable is false.
  int? nextPageOffset = moreItemsAvailable
      ? reader.ReadNullableAttributeValue<int>(
          XmlAttributeNames.IndexedPagingOffset)
      : null;

  if (!this._isGrouped) {
    this._results = new FindItemsResults<TItem>();
    this._results!.TotalCount = totalItemsInView;
    this._results!.NextPageOffset = nextPageOffset;
    this._results!.MoreAvailable = moreItemsAvailable;
    await _InternalReadItemsFromXml(
        reader, this._propertySet, this._results!.Items);
  } else {
    this._groupedFindResults = new GroupedFindItemsResults<TItem>();
    this._groupedFindResults!.TotalCount = totalItemsInView;
    this._groupedFindResults!.NextPageOffset = nextPageOffset;
    this._groupedFindResults!.MoreAvailable = moreItemsAvailable;

    await reader.ReadStartElementWithNamespace(
        XmlNamespace.Types, XmlElementNames.Groups);

    if (!reader.IsEmptyElement) {
      do {
        await reader.Read();

        if (reader.IsStartElementWithNamespace(
            XmlNamespace.Types, XmlElementNames.GroupedItems)) {
          String? groupIndex = await reader.ReadElementValueWithNamespace(
              XmlNamespace.Types, XmlElementNames.GroupIndex);

          List<TItem> itemList = <TItem>[];
          await _InternalReadItemsFromXml(
              reader, this._propertySet, itemList);

          await reader.ReadEndElementWithNamespace(
              XmlNamespace.Types, XmlElementNames.GroupedItems);

          this
              ._groupedFindResults!
              .ItemGroups
              .add(new ItemGroup<TItem>(groupIndex, itemList));
        }
      } while (!reader.IsEndElementWithNamespace(
          XmlNamespace.Types, XmlElementNames.Groups));
    }
  }

  await reader.ReadEndElementWithNamespace(
      XmlNamespace.Messages, XmlElementNames.RootFolder);

  await reader.Read();

  if (reader.IsStartElementWithNamespace(
          XmlNamespace.Messages, XmlElementNames.HighlightTerms) &&
      !reader.IsEmptyElement) {
    do {
      await reader.Read();

      if (reader.NodeType == XmlNodeType.Element) {
        HighlightTerm term = new HighlightTerm();

        await term.LoadFromXmlWithNamespace(
            reader, XmlNamespace.Types, XmlElementNames.HighlightTerm);
        this._results!.HighlightTerms.add(term);
      }
    } while (!reader.IsEndElementWithNamespace(
        XmlNamespace.Messages, XmlElementNames.HighlightTerms));
  }
}