2 回答
TA贡献1936条经验 获得超6个赞
private IEnumerable<Appointment> GetAllSafeAppointments(Folder calendar) {
ItemView view = new ItemView(512);
view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
SearchFilter filter = new SearchFilter.SearchFilterCollection(LogicalOperator.And,
new SearchFilter.IsEqualTo(SafeAppointmentFlag, true));
while(true) {
var results = SendExchangeRequest(() => calendar.FindItems(filter, view));
foreach(var r in results.OfType<Appointment>())
yield return r;
if(!results.MoreAvailable)
break;
view.Offset = results.NextPageOffset.Value;
}
}
TA贡献1853条经验 获得超9个赞
您可以批量处理请求。我为此编写了一个通用批处理方法:
private IEnumerable<IEnumerable<T>> Batch<T>(IEnumerable<T> input, int batchSize)
{
List<T> items = new List<T>();
foreach (var item in input)
{
items.Add(item);
if (items.Count == batchSize)
{
yield return items;
items = new List<T>();
}
}
if (items.Count > 0)
{
yield return items;
}
}
现在,您可以使用它将您的物品分成几批:
var batches = Batch(GetAllSafeAppointments(calendar).Select(a => a.Id), 1000);
foreach (var batch in batches)
{
service.DeleteItems(batch, DeleteMode.HardDelete, SendCancellationsMode.SendToNone, null);
}
现在最多一次将删除1000个。
- 2 回答
- 0 关注
- 231 浏览
添加回答
举报