Exemplo n.º 1
0
        /// <summary>
        /// Check to see if a specific user is available.
        /// <para>Queue members calendars are stored in a 0-based integer list. Use <see cref=" queueMemberCount"/> to determine number of members.</para>
        /// </summary>
        /// <param name="shiftStart">DateTime format for starting time.</param>
        /// <param name="member">Integer value of member to check</param>
        /// <returns></returns>
        public bool isAvailable(DateTime shiftStart, int member)
        {
            bool result = true;

            try
            {
                //Okay, I lied. The group members are 1-based, not 0-based. The 0th element is actually the user, so we need to offset by 1.
                EWS.AttendeeAvailability avail = freeBusy.AttendeesAvailability.ElementAt(member + 1);
                foreach (EWS.CalendarEvent cal in avail.CalendarEvents)
                {
                    //look for conditions where the calendar should be busy.
                    DateTime shiftEnd = shiftStart.AddMinutes(((QueueDef)queueDefList[queueName]).slotDuration);
                    if (((shiftStart == cal.StartTime) ||
                         ((shiftStart < cal.EndTime) && (cal.EndTime <= shiftEnd)) ||
                         ((shiftStart <= cal.StartTime) && (cal.StartTime < shiftEnd)) ||
                         ((cal.StartTime < shiftStart) && (cal.EndTime > shiftStart))) &&
                        ((cal.FreeBusyStatus == EWS.LegacyFreeBusyStatus.Busy) ||
                         (cal.FreeBusyStatus == EWS.LegacyFreeBusyStatus.OOF)))
                    {
                        result = false;
                    }
                }
            }
            catch
            {
                throw new Exception("Couldn't access calendar from attendee list");
            }
            return(result);
        }
        /// <summary>
        /// Parses the response.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>Response object.</returns>
        internal override object ParseResponse(EwsServiceXmlReader reader)
        {
            GetUserAvailabilityResults serviceResponse = new GetUserAvailabilityResults();

            if (this.IsFreeBusyViewRequested)
            {
                serviceResponse.AttendeesAvailability = new ServiceResponseCollection <AttendeeAvailability>();

                reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.FreeBusyResponseArray);

                do
                {
                    reader.Read();

                    if (reader.IsStartElement(XmlNamespace.Messages, XmlElementNames.FreeBusyResponse))
                    {
                        AttendeeAvailability freeBusyResponse = new AttendeeAvailability();

                        freeBusyResponse.LoadFromXml(reader, XmlElementNames.ResponseMessage);

                        if (freeBusyResponse.ErrorCode == ServiceError.NoError)
                        {
                            freeBusyResponse.LoadFreeBusyViewFromXml(reader, this.Options.RequestedFreeBusyView);
                        }

                        serviceResponse.AttendeesAvailability.Add(freeBusyResponse);
                    }
                }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.FreeBusyResponseArray));
            }

            if (this.IsSuggestionsViewRequested)
            {
                serviceResponse.SuggestionsResponse = new SuggestionsResponse();

                reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.SuggestionsResponse);

                serviceResponse.SuggestionsResponse.LoadFromXml(reader, XmlElementNames.ResponseMessage);

                if (serviceResponse.SuggestionsResponse.ErrorCode == ServiceError.NoError)
                {
                    serviceResponse.SuggestionsResponse.LoadSuggestedDaysFromXml(reader);
                }

                reader.ReadEndElement(XmlNamespace.Messages, XmlElementNames.SuggestionsResponse);
            }

            return(serviceResponse);
        }
        /// <summary>
        /// Parses the response.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>Response object.</returns>
        internal override object ParseResponse(EwsServiceXmlReader reader)
        {
            GetUserAvailabilityResults serviceResponse = new GetUserAvailabilityResults();

            if (this.IsFreeBusyViewRequested)
            {
                serviceResponse.AttendeesAvailability = new ServiceResponseCollection<AttendeeAvailability>();

                reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.FreeBusyResponseArray);

                do
                {
                    reader.Read();

                    if (reader.IsStartElement(XmlNamespace.Messages, XmlElementNames.FreeBusyResponse))
                    {
                        AttendeeAvailability freeBusyResponse = new AttendeeAvailability();

                        freeBusyResponse.LoadFromXml(reader, XmlElementNames.ResponseMessage);

                        if (freeBusyResponse.ErrorCode == ServiceError.NoError)
                        {
                            freeBusyResponse.LoadFreeBusyViewFromXml(reader, this.Options.RequestedFreeBusyView); 
                        }

                        serviceResponse.AttendeesAvailability.Add(freeBusyResponse);
                    }
                }
                while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.FreeBusyResponseArray));
            }

            if (this.IsSuggestionsViewRequested)
            {
                serviceResponse.SuggestionsResponse = new SuggestionsResponse();

                reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.SuggestionsResponse);

                serviceResponse.SuggestionsResponse.LoadFromXml(reader, XmlElementNames.ResponseMessage);

                if (serviceResponse.SuggestionsResponse.ErrorCode == ServiceError.NoError)
                {
                    serviceResponse.SuggestionsResponse.LoadSuggestedDaysFromXml(reader);
                }

                reader.ReadEndElement(XmlNamespace.Messages, XmlElementNames.SuggestionsResponse);
            }

            return serviceResponse;
        }