本文介绍了EWS错误:超过了1000个项目的最大数量,可以在一个请求中将其删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用EWS Exchange Sync,在我的一种方法中,这就是说我超过了可以在单个请求中删除的1000个项目的最大数量.是否可以解决此问题,而不是从日历中删除所有内容,而只从今天起删除,而不是及时删除?

i am using EWS Exchange Sync, and in one of my methods, it's saying that i exceeded maximum count of 1000 items that can be deleted in a single request. Can this be solved by instead of deleting everything from the calendar, we only delete from today and onwards, instead of deleting back in time?

造成错误的方法在这里:

The method responsible for the error is here:

        public void DeleteAllSafeAppointments(SCDriftConnection conn, ExchangeService service, SAFEAgent agent) {
        if(conn == null)
            throw new ArgumentNullException("conn");
        if(service == null)
            throw new ArgumentNullException("service");
        if(agent == null)
            throw new ArgumentNullException("agent");

        try {
            var calendar = GetAgentCalendar(service, agent);

            service.DeleteItems(GetAllSafeAppointments(calendar).Select(a => a.Id), DeleteMode.HardDelete, SendCancellationsMode.SendToNone, null);

            var scheduledActivitiesOnAgent = ScheduledActivity.GetScheduleToExchange(new QueryParameters<ScheduledActivity>(s => s.Initials == agent.Initials && s.ExchangeId != null));

            foreach(var schedAct in scheduledActivitiesOnAgent) {
                schedAct.ExchangeId = null;

                schedAct.Save(conn);
            }

            ResetAgentSyncState(calendar, agent);
        } catch(Exception ex) {
            throw new Exception("An error occured while clearing exchange calendar for " + agent.Initials, ex);
        }

        agent.ExchangeSyncronizationSettings.LastSync = DateTime.Now;
        agent.ExchangeSyncronizationSettings.Save(conn);
    }

完整的错误消息在这里:

The full error message is here:

超过了1000个项目的最大数量,可以在一个请求中将其删除. ved Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ProcessWebException(WebException webException) ved Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest请求) ved Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(IEwsHttpWebRequest& request) ved Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest 1.Execute() ved Microsoft.Exchange.WebServices.Data.ExchangeService.InternalDeleteItems(IEnumerable 1 itemIds,DeleteMode deleteMode,Nullable 1 sendCancellationsMode, Nullable 1受影响的TaskOccurrences,ServiceErrorHandling errorHandling,布尔值preventReadReceipts) ved Microsoft.Exchange.WebServices.Data.ExchangeService.DeleteItems(IEnumerable 1 itemIds, DeleteMode deleteMode, Nullable 1 sendCancellationsMode,Nullable`1受影响的TaskOccurrences) ved SafeToExchangeSync.SafeScheduleSyncronizer.DeleteAllSafeAppointments(SCDriftConnection conn,ExchangeService服务,SAFEAgent代理)

Exceeded maximum count of 1000 items that can be deleted in a single request. ved Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ProcessWebException(WebException webException) ved Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest request) ved Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(IEwsHttpWebRequest& request) ved Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest1.Execute() ved Microsoft.Exchange.WebServices.Data.ExchangeService.InternalDeleteItems(IEnumerable1 itemIds, DeleteMode deleteMode, Nullable1 sendCancellationsMode, Nullable1 affectedTaskOccurrences, ServiceErrorHandling errorHandling, Boolean suppressReadReceipts) ved Microsoft.Exchange.WebServices.Data.ExchangeService.DeleteItems(IEnumerable1 itemIds, DeleteMode deleteMode, Nullable1 sendCancellationsMode, Nullable`1 affectedTaskOccurrences) ved SafeToExchangeSync.SafeScheduleSyncronizer.DeleteAllSafeAppointments(SCDriftConnection conn, ExchangeService service, SAFEAgent agent)

推荐答案

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;
            }
        }

这篇关于EWS错误:超过了1000个项目的最大数量,可以在一个请求中将其删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 11:19