Hi, I'm using the code below to retrieve a list of items from an EWS hosted mailbox that contains 5000+ items.
It does this once a minute on a polled cycle.
On 2 occasions in the last month, it has failed to read all of the items, once stopping after a single page of 1000 items and the second time after 5 pages of 1000 items, both times giving no error at all, just an abbreviated list with an incorrect count, which has caused havoc for our synchronization logic, as the next time we look, the mails are back in the list.
It would appear to me that the PageResult.IsLastPage is reporting that it is the last page when there are more pages left, I can't see any other way out of the loop.
Rebex.Ews.dll is version 1.0.5759.2
Code below;
// We must do this in pages so that we don't hit any server throttling limits on EWS
EwsMessageCollection ewsMessageCollection=new EwsMessageCollection();
int offset = 0;
int pageSize = 1000;
//EwsMessageCollection ewsMessageCollection2 = mailBoxMonitor.ExchangeWS.GetMessageList(new EwsFolderId(mailBoxMonitor.MailBoxSettings.Folder), EwsItemFields.Fast);
while (true)
{
// get items of next page
EwsMessageCollection thisPageOfMessages =
mailBoxMonitor.ExchangeWS.GetMessageList(
new EwsFolderId(mailBoxMonitor.MailBoxSettings.Folder),
EwsPageView.CreateIndexed(offset, pageSize));
// add this page of items to our master list, bu tonly the items that are actually messages
// we could see calendar invites and the like
foreach (EwsMessageInfo thisItem in thisPageOfMessages)
{
if (thisItem.MessageType == EwsMessageType.Message)
{
ewsMessageCollection.Add(thisItem);
}
}
// break if this is the last page
if (thisPageOfMessages.PageResult.IsLastPage)
break;
// set next offset
if (thisPageOfMessages.PageResult.NextOffset.HasValue)
offset = thisPageOfMessages.PageResult.NextOffset.Value;
else
offset += pageSize;
}
//EwsMessageCollection ewsMessageCollection = mailBoxMonitor.ExchangeWS.GetMessageList(new EwsFolderId(mailBoxMonitor.MailBoxSettings.Folder), EwsItemFields.Fast);
DateTime retrieveEnd = DateTime.UtcNow;
TimeSpan retrievalTime = retrieveEnd - retrieveStart;
infoLogMessage += "Retrieved " + ewsMessageCollection.Count.ToString() + " Unique Ids from EWS provider, total retrieval call time = " + retrievalTime.ToString() + Environment.NewLine;