Here is my code for deleting a set of calendar entries:
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;
}
I then have a method that adds new events into the calendar:
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;
}
As you can see, for each event it calls AddEventToCalendar
. That method, in part, creates the event like this:
// 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
});
Now, I know that Microsoft Graph supports batch mode using JSON. But I am at a loss as to how to implement that with what I have written. It makes sense to try and convert my code into a list of batch operations to reduce the calls.
How do I do this?
Update
I have located this article but I am not sure if it is relevant and what I should do. So I would still appreciate any specific guidance with how to do this. I am sure that other potential users would benefit from this greatly - or be directed to an existing resource that I have missed. Thank you.