protected override void ProcessRecord() { AttendeeInfo attendee = new AttendeeInfo(this.EmailAddress, MeetingAttendeeType.Required, false); List<AttendeeInfo> attendeeList = new List<AttendeeInfo>(); attendeeList.Add(attendee); AvailabilityOptions options = new AvailabilityOptions(); options.MeetingDuration = 30; options.RequestedFreeBusyView = FreeBusyViewType.FreeBusy; GetUserAvailabilityResults freeBusyAvailability = this.EwsSession.GetUserAvailability( attendeeList, new TimeWindow(this.StartTime, this.EndTime), AvailabilityData.FreeBusy, options ); foreach ( AttendeeAvailability availability in freeBusyAvailability.AttendeesAvailability ) { if (availability.Result == ServiceResult.Success) this.WriteObject(availability.CalendarEvents, true); else this.WriteObject(availability); } }
public static List<CalendarEvent> GetRoomAvailability(string roomAddress) { //short cache just to prevent crazy accesses //it is recommended to keep this cache shorter than the page refresh //otherwise the frequent refresh doesn't do any good string RoomEventsKey = GetRoomEventsKey(roomAddress); var returnValue = (List<CalendarEvent>)_memoryCache.Get(RoomEventsKey); if (returnValue == null) { var attendee = new AttendeeInfo(roomAddress, MeetingAttendeeType.Room, false); var results = _exchangeService.GetUserAvailability(new List<AttendeeInfo>() { attendee }, new TimeWindow(DateTime.Today, DateTime.Today.AddDays(1)), AvailabilityData.FreeBusy); returnValue = results.AttendeesAvailability.SelectMany(a => a.CalendarEvents).Select(e => new CalendarEvent() { Subject = e.Details.Subject, StartTime = e.StartTime, EndTime = e.EndTime, Status = e.FreeBusyStatus.ToString() }).OrderBy(e => e.StartTime).ToList(); //add the pending item if necessary var pendingItem = (CalendarEvent)_memoryCache.Get(GetRoomPendingEventKey(roomAddress)); //match on StartTime/EndTime because we know its unique for a given room if (pendingItem != null && !returnValue.Any(c => c.EndTime.Equals(pendingItem.EndTime) && c.StartTime.Equals(pendingItem.StartTime))) { returnValue.Add(pendingItem); } _memoryCache.Add(RoomEventsKey, returnValue, DateTime.Now.AddSeconds(45)); } return returnValue; //if we need attendee details in the future - use this // var appointments = exchangeService.FindAppointments(new FolderId(WellKnownFolderName.Calendar,new Mailbox(roomAddress)), // new CalendarView(DateTime.Today, DateTime.Today.AddDays(4))); }