这是我删除一组日历条目的代码:
public async Task<bool> DeleteCalendarEvents(SettingsBase oSettings)
{
try
{
var oEvents = await _graphClient
.Me
.Calendars[oSettings.CalendarID]
.Events
.Request()
.Select("Start,Subject,Id")
.Top(50)
.Filter(oSettings.GetFilterString())
.OrderBy("start/DateTime")
.GetAsync();
List<Event> listEvents = new List<Event>();
listEvents.AddRange(oEvents);
while (oEvents.NextPageRequest != null)
{
oEvents = await oEvents.NextPageRequest.GetAsync();
listEvents.AddRange(oEvents);
}
foreach (Event oEvent in listEvents)
{
await _graphClient.Me.Events[oEvent.Id].Request().DeleteAsync();
}
}
catch (Exception ex)
{
SimpleLog.Log(ex);
Console.WriteLine("DeleteCalendarEvents: See error log.");
return false;
}
return true;
}
然后我有一个方法可以将新事件添加到日历中:
public async Task<bool> AddEventsToCalendar(MWBData.MWBCalendarData oData)
{
if (oData.SettingsMWB.CalendarEntryType != "CLM_MidweekMeeting")
{
SimpleLog.Log("AddEventsToCalendar: CalendarEntryType is not set to CLM_MidweekMeeting.", SimpleLog.Severity.Error);
Console.WriteLine("AddEventsToCalendar: See error log.");
return false;
}
try
{
// Now create the new events
foreach (EventWeek oWeek in oData.Weeks)
{
bool bSuccess = await AddEventToCalendar(oWeek, oData.SettingsMWB);
if(bSuccess)
{
// Now create any Weekend Meeting events
if(oWeek.WeekendMeeting.Included)
{
bSuccess = await AddEventToCalendar(oWeek.WeekendMeeting, oData.SettingsMWB);
if(!bSuccess)
{
Console.WriteLine("AddEventsToCalendar: See error log.");
return false;
}
}
}
else
{
Console.WriteLine("AddEventToCalendar: See error log.");
return false;
}
}
}
catch (Exception ex)
{
SimpleLog.Log(ex);
Console.WriteLine("AddEventsToCalendar: See error log.");
return false;
}
return true;
}
如您所见,对于它调用的每个事件AddEventToCalendar
。该方法部分地创建了这样的事件:
// Add the event
Event createdEvent = await _graphClient.Me.Calendars[oSettings.CalendarID].Events.Request().AddAsync(new Event
{
Subject = oEvent.GetSubject(),
Body = body,
Start = startTime,
End = endTime,
IsAllDay = oEvent.IsAllDayEvent(),
IsReminderOn = bSetReminder,
ReminderMinutesBeforeStart = bSetReminder ? iReminderMinutes : (int?)null,
Location = location,
SingleValueExtendedProperties = extendedProperties,
Sensitivity = oSettings.SetCalendarPrivate ? Sensitivity.Private : Sensitivity.Normal
});
现在,我知道 Microsoft Graph 支持使用 JSON 的批处理模式。但是我不知道如何用我写的东西来实现它。尝试将我的代码转换为批处理操作列表以减少调用是有意义的。
我该怎么做呢?
更新
我找到了这篇文章,但我不确定它是否相关以及我应该做什么。因此,我仍然希望获得有关如何执行此操作的任何具体指导。我确信其他潜在用户将从中受益匪浅——或者被引导到我错过的现有资源。谢谢你。