Reputation: 3626
and sorry for a poor title of the question
I´m trying to get all free rooms (not booked ones) from my exchange server. The thing is that I also get the rooms I have booked but nobody has accepted.
I would like to exclude them from the list after I book the room.
This is the code I use to book a room
ExchangeService service;
//...code to new-up and config service
var request = new Appointment(service)
{
Subject = booking.Subject,
Start = booking.Start,
End = booking.End,
Location = booking.Room
};
request.RequiredAttendees.Add(booking.Person);
request.RequiredAttendees.Add(booking.Room);
request.Save(SendInvitationsMode.SendOnlyToAll);
To note I have tried to call request.Accept() straight after Save() but without that "realy booking" the room. Pressing accept in Outlook is the only "fix". Needlessly to say I have tried everything I could find about this issue (I do not work with Exchange regularly).
And then the code to get free rooms
var rooms = service.GetRooms(locationAddress);
// all the meeting rooms at location
var rooms= rooms.Select(i => new AttendeeInfo { SmtpAddress = i.Address, AttendeeType = MeetingAttendeeType.Room });
// Get all availabilites from all rooms at given locations
var availability = service.GetUserAvailability(rooms, timeframe, AvailabilityData.FreeBusy);
foreach (var a in availability.AttendeesAvailability)
{
// Here we always get all the free rooms
// including the ones we booked earlier
// UNTIL somebody clicks accept in Outlook and then it does not appear here!?
}
I can´t see that the rooms are marked differently before they are accepted in Outlook so I can´t differentiate between them and pull out them ones I don´t want.
I also really think that those rooms should not be available so there must bee some enum/tick/mark I can put on the room before booking it but I totally missing it.
Edit
I realy don't understand why there is no option for AvailabilityData.Free in the enum in the GetUserAvailability method (only FreeBusy, FreeBusyAndSuggestions and Suggestions but no Free only!?)
Upvotes: 5
Views: 1395
Reputation: 3626
Ok this is rather silly... the code (I inherited) did not include code to actually remove rooms that where taken (busy). I only just noticed this...
The code to fix this is simply this one
var busyRoomToRemove = a.CalendarEvents.ToList().Find(x => x.FreeBusyStatus == LegacyFreeBusyStatus.Busy);
a.CalendarEvents.Remove(busyRoomToRemove);
Sorry for the inconvenience :-)
Upvotes: 2