0
votes

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 Appointments, 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).

1

1 Answers

0
votes

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.

The EntryId that is returned in the CalendarEventDetails is the Id of the current appointment in the Mailbox you have queried. When you say doesn't match up it doesn't make sense (eg it returning current data from the target mailbox if you have an Id stored that maybe out of date or referring to a different object or mailbox eg the Id you get from the Meeting Room Mailbox won't match the Appointment created in the Organizer mailbox you need to use the Meeting GOID and search in that instance).

Is there a better way to achieve this? Either by switching away from GetUserAvailability to something which returns Appointments, 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).

Your querying exactly the same data no matter which operation (eg using FindItems to query the calendar directly) you use so again this doesn't make logical sense to me.

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.

What does that is not EWS this is a feature of Meeting Room Mailboxes that will replace the subject of the an appointment with the Organiser name for security reasons. This can be disabled on a Meeting Mailbox using Set-CalendarProcessing -AddOrganizerToSubject https://technet.microsoft.com/en-us/library/dd335046(v=exchg.160).aspx