Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

TotalItemsInView in ResolutionSet is not reliable. #179

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Misc/NameResolution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,15 @@ internal NameResolution(NameResolutionCollection owner)
/// Loads from XML.
/// </summary>
/// <param name="reader">The reader.</param>
internal void LoadFromXml(EwsServiceXmlReader reader)
/// <param name="allowNoMoreElements">If true the function returns false rather than throw an exception
/// if the last element has been read.</param>
internal bool LoadFromXml(EwsServiceXmlReader reader, bool allowNoMoreElements)
{
reader.ReadStartElement(XmlNamespace.Types, XmlElementNames.Resolution);
reader.Read();
if (allowNoMoreElements && reader.NodeType == System.Xml.XmlNodeType.EndElement)
return false;

reader.EnsureCurrentNodeIsStartElement(XmlNamespace.Types, XmlElementNames.Resolution);

reader.ReadStartElement(XmlNamespace.Types, XmlElementNames.Mailbox);
this.mailbox.LoadFromXml(reader, XmlElementNames.Mailbox);
Expand All @@ -81,6 +87,7 @@ internal void LoadFromXml(EwsServiceXmlReader reader)
{
reader.EnsureCurrentNodeIsEndElement(XmlNamespace.Types, XmlElementNames.Resolution);
}
return true;
}

/// <summary>
Expand Down
12 changes: 7 additions & 5 deletions Misc/NameResolutionCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,21 @@ internal void LoadFromXml(EwsServiceXmlReader reader)
{
reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.ResolutionSet);

int totalItemsInView = reader.ReadAttributeValue<int>(XmlAttributeNames.TotalItemsInView);
// Note: TotalItemsInView is not reliable, https://github.com/OfficeDev/ews-managed-api/issues/177
this.includesAllResolutions = reader.ReadAttributeValue<bool>(XmlAttributeNames.IncludesLastItemInRange);

for (int i = 0; i < totalItemsInView; i++)
NameResolution nameResolution;
while (true)
{
NameResolution nameResolution = new NameResolution(this);
nameResolution = new NameResolution(this);

nameResolution.LoadFromXml(reader);
if (!nameResolution.LoadFromXml(reader, true))
break;

this.items.Add(nameResolution);
}

reader.ReadEndElement(XmlNamespace.Messages, XmlElementNames.ResolutionSet);
reader.EnsureCurrentNodeIsEndElement(XmlNamespace.Messages, XmlElementNames.ResolutionSet);
}

/// <summary>
Expand Down