Skip to content

Commit

Permalink
TotalItemsInView in ResolutionSet is not reliable, workaround for Off…
Browse files Browse the repository at this point in the history
  • Loading branch information
poizan42 committed Sep 27, 2018
1 parent 3183478 commit bd37171
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
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

0 comments on commit bd37171

Please sign in to comment.