예제 #1
0
        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 IHttpActionResult Availability(AvailabilityRequest request)
        {
            List<AttendeeInfo> attendees = new List<AttendeeInfo>();

            foreach (var user in request.Users)
            {
                attendees.Add(new AttendeeInfo()
                {
                    SmtpAddress = user,
                    AttendeeType = MeetingAttendeeType.Required
                });
            }

            // Specify availability options.
            AvailabilityOptions myOptions = new AvailabilityOptions();
            myOptions.MeetingDuration = request.DurationMinutes;
            myOptions.RequestedFreeBusyView = FreeBusyViewType.FreeBusy;

            // Return a set of free/busy times.
            var service = ExchangeServer.Open();

            var startTime = DateTime.Parse(request.Start);
            var endTime = DateTime.Parse(request.End);
            GetUserAvailabilityResults freeBusyResults = service.GetUserAvailability(attendees,
                                                                                 new TimeWindow(startTime, endTime),
                                                                                     AvailabilityData.FreeBusy,
                                                                                     myOptions);

            var response = new AvailabilityResponse
            {
                AvailabilityResult = new List<AvailabilityUser>()
            };


            foreach (AttendeeAvailability availability in freeBusyResults.AttendeesAvailability)
            {
                var user = new AvailabilityUser();
                var avail = new List<TimeBlock>();

                foreach (CalendarEvent calendarItem in availability.CalendarEvents)
                {
                    var block = new TimeBlock
                    {
                        Start = calendarItem.StartTime,
                        End = calendarItem.EndTime,
                        StatusEnum = calendarItem.FreeBusyStatus,
                        Status = calendarItem.FreeBusyStatus.ToString()
                    };

                    avail.Add(block);
                }
                user.Availability = avail;
                response.AvailabilityResult.Add(user);
            }

            return Ok(response);
        }
예제 #3
0
        public List<RoomAvability> getAvability(string _roomName)
        {

            List<RoomAvability> avabilityList = new List<RoomAvability>();

            List<AttendeeInfo> attendees = new List<AttendeeInfo>();


            attendees.Add(new AttendeeInfo()
            {
                SmtpAddress = _roomName,
                AttendeeType = MeetingAttendeeType.Required
            });


            // Specify availability options.
            AvailabilityOptions myOptions = new AvailabilityOptions();
            myOptions.MeetingDuration = _meetingDuration;
            myOptions.RequestedFreeBusyView = FreeBusyViewType.FreeBusy;


            GetUserAvailabilityResults freeBusyResults = _service.GetUserAvailability(attendees,
                                                                     new TimeWindow(DateTime.Now, DateTime.Now.AddDays(1)),
                                                                         AvailabilityData.FreeBusy,
                                                                         myOptions);
            foreach (AttendeeAvailability availability in freeBusyResults.AttendeesAvailability)
            {
                Console.WriteLine(availability.Result);
                Console.WriteLine();
                foreach (CalendarEvent calendarItem in availability.CalendarEvents)
                {

                    RoomAvability avability = new RoomAvability();

                    avability.StartTime = calendarItem.StartTime;
                    avability.EndTime = calendarItem.EndTime;
                    avability.FreeBusyStatus = calendarItem.FreeBusyStatus.ToString();

                    if (calendarItem.Details != null)
                    {
                        avability.IsMeeting = calendarItem.Details.IsMeeting;
                        avability.IsPrivate = calendarItem.Details.IsPrivate;
                        avability.Location = calendarItem.Details.Location;
                        avability.Subject = calendarItem.Details.Subject;
                    }
                    avabilityList.Add(avability);

                }
            }

            return avabilityList;



        }
예제 #4
0
        /// <summary>
        /// Get the Outlook calendars for the queue.
        /// <para>This method fetches the calendars for the current user and the rest of the queue members. Only the day specified is retrieved. The calendars are stored in the communication object until <c>getCal</c> is called again.</para>
        /// </summary>
        /// <param name="start">The <see cref=" DateTime"/> value for the day to fetch the calendars</param>
        /// <returns>True or False depending upon the success of finding the calendar.</returns>
        public bool getCal(DateTime start)
        {
            bool result = false;

            try
            {
                //Set up user list
                List <EWS.AttendeeInfo> whoList = new List <EWS.AttendeeInfo>();
                whoList.Add(new EWS.AttendeeInfo()
                {
                    SmtpAddress  = userName,
                    AttendeeType = EWS.MeetingAttendeeType.Required
                });

                foreach (string who in getTASNames())
                {
                    whoList.Add(new EWS.AttendeeInfo()
                    {
                        SmtpAddress  = who,
                        AttendeeType = EWS.MeetingAttendeeType.Required
                    });
                }

                //fetch availability
                EWS.AvailabilityOptions opt = new EWS.AvailabilityOptions();
                opt.MeetingDuration       = ((QueueDef)queueDefList[queueName]).slotDuration;
                opt.RequestedFreeBusyView = EWS.FreeBusyViewType.FreeBusy;
                EWS.TimeWindow tw = new EWS.TimeWindow(start, start.AddDays(1));
                freeBusy = service.GetUserAvailability(whoList, tw, EWS.AvailabilityData.FreeBusy, opt);
                result   = true;
            }
            catch (Exception e)
            {
                Console.WriteLine("{0} Exception caught.", e);
                //throw (e);
            }
            return(result);
        }
예제 #5
0
		private IEnumerable<RoomAvailabilityInfo> GetAvaialilityInternal(IEnumerable<RoomInfo> rooms)
		{
			var roomsArray = rooms.ToArray();
			var attendees =
				roomsArray.Select(
					r => new AttendeeInfo { AttendeeType = MeetingAttendeeType.Room, ExcludeConflicts = false, SmtpAddress = r.RoomId }).ToList();
			var timeWindow = new TimeWindow(DateTime.Now, DateTime.Now.AddDays(1));

			AvailabilityOptions options = new AvailabilityOptions
			{
				MeetingDuration = 30,
				RequestedFreeBusyView = FreeBusyViewType.FreeBusy
			};
			var availabilities = _service.GetUserAvailability(attendees, timeWindow, AvailabilityData.FreeBusy, options);

			Debug.Assert(roomsArray.Length == availabilities.AttendeesAvailability.Count, "Invalid server response");
			return roomsArray.Zip(availabilities.AttendeesAvailability, (room, availability) =>
			{
				var info = Helper.CollapseCalendar(availability.CalendarEvents.Select(x => new TimeInterval(x.StartTime, x.EndTime)));
				return new RoomAvailabilityInfo(info, room);
			});
		}
        private static GetUserAvailabilityResults GetSuggestedMeetingTimesAndFreeBusyInfo(ExchangeService service)
        {
            // Create a collection of attendees. 
            List<AttendeeInfo> attendees = new List<AttendeeInfo>();

            attendees.Add(new AttendeeInfo()
            {
                SmtpAddress = "*****@*****.**", //get the current user email
                AttendeeType = MeetingAttendeeType.Organizer
            });

            attendees.Add(new AttendeeInfo()
            {
                SmtpAddress = "*****@*****.**",
                AttendeeType = MeetingAttendeeType.Required
            });

            // Specify options to request free/busy information and suggested meeting times.
            AvailabilityOptions availabilityOptions = new AvailabilityOptions();
            availabilityOptions.GoodSuggestionThreshold = 49;
            availabilityOptions.MaximumNonWorkHoursSuggestionsPerDay = 0;
            availabilityOptions.MaximumSuggestionsPerDay = 2;
            // Note that 60 minutes is the default value for MeetingDuration, but setting it explicitly for demonstration purposes.
            availabilityOptions.MeetingDuration = 60;
            availabilityOptions.MinimumSuggestionQuality = SuggestionQuality.Good;
            availabilityOptions.DetailedSuggestionsWindow = new TimeWindow(DateTime.Now.AddDays(1), DateTime.Now.AddDays(2));
            availabilityOptions.RequestedFreeBusyView = FreeBusyViewType.FreeBusy;

            // Return free/busy information and a set of suggested meeting times. 
            // This method results in a GetUserAvailabilityRequest call to EWS.
            GetUserAvailabilityResults results = null;
            results = service.GetUserAvailability(attendees,
                                                  availabilityOptions.DetailedSuggestionsWindow,
                                                  AvailabilityData.FreeBusyAndSuggestions,
                                                  availabilityOptions);
            return results;
            #region find the suggestions and availability
            // Display suggested meeting times. 
            //Console.WriteLine("Availability for {0} and {1}", attendees[0].SmtpAddress, attendees[1].SmtpAddress);
            //Console.WriteLine();

            //foreach (Suggestion suggestion in results.Suggestions)
            //{
            //    Console.WriteLine("Suggested date: {0}\n", suggestion.Date.ToShortDateString());
            //    Console.WriteLine("Suggested meeting times:\n");
            //    foreach (TimeSuggestion timeSuggestion in suggestion.TimeSuggestions)
            //    {
            //        Console.WriteLine("\t{0} - {1}\n",
            //                          timeSuggestion.MeetingTime.ToShortTimeString(),
            //                          timeSuggestion.MeetingTime.Add(TimeSpan.FromMinutes(availabilityOptions.MeetingDuration)).ToShortTimeString());



            //    }
            //}

            //int i = 0;

            //// Display free/busy times.
            //foreach (AttendeeAvailability availability in results.AttendeesAvailability)
            //{
            //    Console.WriteLine("Availability information for {0}:\n", attendees[i].SmtpAddress);

            //    foreach (CalendarEvent calEvent in availability.CalendarEvents)
            //    {
            //        Console.WriteLine("\tBusy from {0} to {1} \n", calEvent.StartTime.ToString(), calEvent.EndTime.ToString());
            //    }

            //    i++;
            //}

            #endregion
        }
예제 #7
0
        private void buildCalAgenda(DirectoryEntry result)
        {
            ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
            service.UseDefaultCredentials = true; // Use domain account for connecting 
            //service.Credentials = new WebCredentials("*****@*****.**", "password"); // used if we need to enter a password, but for now we are using domain credentials
            //service.AutodiscoverUrl("*****@*****.**");  //XXX we should use the service user for webmgmt!
            service.Url = new System.Uri("https://mail.aau.dk/EWS/exchange.asmx");

            List<AttendeeInfo> attendees = new List<AttendeeInfo>();



            attendees.Add(new AttendeeInfo()
            {
                SmtpAddress = result.Properties["userPrincipalName"].Value.ToString(),
                AttendeeType = MeetingAttendeeType.Organizer
            });


            // Specify availability options.
            AvailabilityOptions myOptions = new AvailabilityOptions();

            myOptions.MeetingDuration = 30;
            myOptions.RequestedFreeBusyView = FreeBusyViewType.FreeBusy;

            // Return a set of free/busy times.
            DateTime dayBegin = DateTime.Now.Date;
            var window = new TimeWindow(dayBegin, dayBegin.AddDays(1));
            GetUserAvailabilityResults freeBusyResults = service.GetUserAvailability(attendees,
                                                                                 window,
                                                                                     AvailabilityData.FreeBusy,
                                                                                     myOptions);

            var sb = new StringBuilder();
            // Display available meeting times.


            DateTime now = DateTime.Now;
            foreach (AttendeeAvailability availability in freeBusyResults.AttendeesAvailability)
            {

                foreach (CalendarEvent calendarItem in availability.CalendarEvents)
                {
                    if (calendarItem.FreeBusyStatus != LegacyFreeBusyStatus.Free)
                    {

                        bool isNow = false;
                        if (now > calendarItem.StartTime && calendarItem.EndTime > now)
                        {
                            sb.Append("<b>");
                            isNow = true;
                        }
                        sb.Append(string.Format("{0}-{1}: {2}<br/>", calendarItem.StartTime.ToString("HH:mm"), calendarItem.EndTime.ToString("HH:mm"), calendarItem.FreeBusyStatus));

                        if (isNow)
                        {
                            sb.Append("</b>");
                        }
                    }
                }
            }


            lblcalAgenda.Text = sb.ToString();
        }