Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get truly free rooms from Exchange EWS

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!?)

like image 811
Sturla Avatar asked Oct 31 '22 10:10

Sturla


1 Answers

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 :-)

like image 196
Sturla Avatar answered Nov 15 '22 04:11

Sturla