Currently I've a bit of code we're using to retrieve the calendar for a mailbox address (specifically a mailbox for a Room contact) for the whole day:
var attendees = new List<AttendeeInfo> {
new AttendeeInfo {
SmtpAddress = emailAddress,
AttendeeType = MeetingAttendeeType.Room
}
};
var start = currentDate.Date.ToUniversalTime();
var results = this._Service.GetUserAvailability(attendees, new TimeWindow(start, start.AddHours(24)), AvailabilityData.FreeBusy);
var availability = results.AttendeesAvailability[0].CalendarEvents;
// Do some manipulation across the events…
This is all working fine, I'm now coming to a point where I need to be able to add meetings onto the mailbox, using the following:
var meeting = new Appointment(this._Service) {
Subject = subject,
Start = startDate,
End = endDate
};
if (null != roomToUse) {
meeting.Location = roomToUse.Name;
meeting.Resources.Add(roomToUse.EmailAddress);
}
var organiser = meeting.RequiredAttendees.Add(this._User);
// Save the meeting to the Calendar folder and send the meeting request.
meeting.Save(
new FolderId(WellKnownFolderName.Calendar, organiser.Address),
SendInvitationsMode.SendOnlyToAll
);
Which also works fine, however what I need to do now is get the CalendarEvent
for the new Appointment, to return the same bits of information in the same structure (because CalendarEvent
does some things like turning the subject into [Organiser First Name] [Organiser Last Name] [Subject]
, which we're internally handling breaking back out into the name and subject.
I could just duplicate that bit of logic, but seems a bit unreliable, ideally I'd just like to re-use the same class.
So my next thought was to re-get the availability for the mailbox, and just loop it to find the correct CalendarEvent
, however I can't see a reliable way to correctly identify which CalendarEvent
is the same as the one I've just made. I could go off the start and end date/times, checking against the subject, but that seems a bit brittle.
The new meeting does have an Id saved against it, and so does the CalendarEventDetails
on each CalendarEvent
, however (after converting the new ID IdFormat.EwsId
to IdFormat.HexEntryId
) the two do not match up, so I'm presuming that's not the correct way to go about it.
Is there a better way to achieve this? Either by switching away from GetUserAvailability
to something which returns Appointment
s, however (and it was a while since I wrote that bit of code) I remember it not being that simple to get all the appointments for a given day (but more than happy to be showed otherwise).