如何使用Exchange Web服务CalendarView进行分页 [英] How to do paging with Exchange Web Services CalendarView

查看:138
本文介绍了如何使用Exchange Web服务CalendarView进行分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我这样做:

_calendar = (CalendarFolder)Folder.Bind(_service, WellKnownFolderName.Calendar);

var findResults = _calendar.FindAppointments(
    new CalendarView(startDate.Date, endDate.Date)
);

有时我会发现发现太多物品的例外情况.

I sometimes get an exception that too many items were found.

您已超出查找操作可以返回的最大对象数量.使用分页减小结果大小,然后重试您的请求."

"You have exceeded the maximum number of objects that can be returned for the find operation. Use paging to reduce the result size and try your request again."

CalendarView支持一个允许我指定MaxItemsReturned的构造函数,但是我无法弄清楚如何再次指定它,并指定offset进行分页. ItemView具有此构造函数:

CalendarView supports a constructor that will let me specify MaxItemsReturned, but I can't figure out how I would call it again, specifying the offset for paging. ItemView has this constructor:

 public ItemView(int pageSize, int offset)

它的用法很明显.

CalendarView呢?如何使用CalendarView进行分页?

What about CalendarView? How does one do paging with a CalendarView?

我可以将日期范围缩小到较短的时间范围,但是仍然无法确定日期范围是否可以肯定地工作.

I could reduce the date range to be a shorter span, but there's still no way of determining if it will work for sure.

推荐答案

PagedView ,因此无法实现您期望的所有分页逻辑. MaxItemsReturned的上限大于页面大小.返回的错误与PagedView派生的视图类型更相关.

CalendarView is not actually derived from PagedView, so all of the paging logic that you expect isn't possible. MaxItemsReturned is more of an upper limit than a page size. The error that's returned is more relevant to the PagedView derived view types.

我玩了一些PowerShell,通过根据返回的最后一项滚动CalendarView窗口来模拟分页,但是不幸的是,CalendarView和Appointment扩展背后的逻辑使得无法准确获得所需的内容.基本上,随着扩展的进行,它会在"N"个项目处停止,但是您可能有多个约会恰好在同一时间开始,并且可能会给您一个约会,但不会给您剩下的约会.另外,与窗口重叠的所有约会都将包括在内,因此,如果日历上有50个约会且开始时间都相同,则下面的代码将陷入无限循环.

I played around with some PowerShell to emulate paging by rolling the CalendarView window based on the last item returned, but unfortunately the logic behind the CalendarView and Appointment expansion make it impossible to get exactly what you need. Basically as it does the expansion, it's going to stop at "N" items, but you might have more than one appointment that starts at the exact same time and it may give you one, but not the rest. Also, any appointments that overlap the window will get included, so the below code would go into an infinite loop if you had 50 appointments on the calendar that all had the same start time.

Add-Type -Path "C:\Program Files\Microsoft\Exchange\Web Services\1.2\Microsoft.Exchange.WebServices.dll"

$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService
$cred = New-Object Microsoft.Exchange.WebServices.Data.WebCredentials ($user , $passwd)
$service.UseDefaultCredentials = $false
$service.Credentials = $cred
$service.AutodiscoverUrl($user)

$num=50
$total=0
$propsetfc = [Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties
$calfolder = [Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar

$service.UserAgent = "EWSCalViewTest"
$calview = New-Object Microsoft.Exchange.WebServices.Data.CalendarView("1/1/2012","12/31/2012", $num)
$calview.PropertySet = $propsetfc

do {
    $findresults = $service.FindAppointments($calfolder,$calview)
    write-host  "Found:" $findresults.Items.Count "of" $findresults.TotalCount
    $calview.StartDate = $findresults.Items[$findresults.Items.Count-1].Start
    $total+=$findresults.Items.Count
} while($findresults.MoreAvailable)
write-host $total "total found (including dups)"

不幸的是,扩展和重叠逻辑意味着您将以这种方式获得重复项,每次通话之后,至少要有一个重复项.

Unfortunately the expansion and overlap logic mean you'll get duplicates this way, at least one duplicate for each call beyond the first.

如果必须使用CalendarView编写代码,则可能会使用MaxItemsReturned为1000(如果未指定MaxItemsReturned,这也是使您陷入错误状态的限制).如果一口气把它们都搞定,那就太好了.如果您必须打第二个电话,那么您将不得不做一些额外的工作来简化结果集.我还尝试通过在CalendarView中使用尽可能窄的日期窗口来限制服务器的负担,因为您是在要求Exchange在整个时间范围内计算重复约会的扩展.对于服务器来说,这可能是一个相当昂贵的操作.

If I had to write code using CalendarView, I'd probably use a MaxItemsReturned of 1000 (this is also the limit that throws you into the error condition if you don't specify MaxItemsReturned). If you get them all in one call, you're good. If you have to make a second call, then you'll have to do some extra work to dedup the result set. I'd also try to limit the burden on the server by using as narrow of a date window as possible in the CalendarView since you're asking Exchange to calculate the expansion of recurring appointments across the entire time span. It can be a fairly expensive operation for the server.

这篇关于如何使用Exchange Web服务CalendarView进行分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆