0
votes

I'm using the EWS Managed API to load appointments for a specific room resource, and publish it via WCF to be consumed by a tablet device.

I'd like to cancel the meeting room booking if the organizer doesn't perform a specific action after 15mins that the meeting is scheduled to start.

Because the tablet device only has the StoreId property to identify the event from, I implemented the following code:

public bool CancelMeeting(string appointmentId, string roomEmail)
    {
        try
        {
            var service = GetExchangeService();
            var ai = new AlternateId[1];
            ai[0] = new AlternateId();
            ai[0].UniqueId = appointmentId;
            ai[0].Format = IdFormat.HexEntryId;
            ai[0].Mailbox = roomEmail;
            ServiceResponseCollection<ConvertIdResponse> cvtresp = service.ConvertIds(ai, IdFormat.EwsId);
            var appointment = Appointment.Bind(service, ((AlternateId)cvtresp[0].ConvertedId).UniqueId);

            if (appointment.Resources.Count != 0)
                appointment.Resources.RemoveAt(0);

            appointment.Location = string.Empty;

            appointment.Save(SendInvitationsMode.SendOnlyToAll);
            return true;
        }
        catch (Exception ex)
        {
            return false;
        }
    }

However,

if (appointment.Resources.Count != 0)
    appointment.Resources.RemoveAt(0);

in this code appointment.Resources.Count is always 0. As per this post (Can't Retrieve Resources (rooms) from Exchange Web Services) you need to tell EWS to specifically include the Resources. How do you specify to include the resources when using Appointment.Bind?

1

1 Answers

2
votes

In much the same way as that post you linked. Create a property set with the AppointmentSchema.Resources property and pass it to the Bind method.

PropertySet includeResources = new PropertySet(BasePropertySet.FirstClassProperties, AppointmentSchema.Resources);
var appointment = Appointment.Bind(service, ((AlternateId)cvtresp[0].ConvertedId).UniqueId, includeResources);

UPDATE:

It looks like you're accessing the room's calendar, not the organizer. In the room's calendar you won't see the resources. Resources are only visible in the organizer's calendar. This is because they are implemented as BCC recipients. Also bear in mind that removing something from the room's copy of the appointment would not remove it from the appointment in anyone else's mailbox, so this probably isn't the best approach. Instead, you would want to decline the meeting, which would send a decline notice back to the organizer and remove the meeting from the room's calendar.