예제 #1
0
        internal static string GetMergedFreeBusyString(EmailAddress emailAddress, CalendarFolder calendarFolder, ExTimeZone timeZone, ExDateTime windowStart, ExDateTime windowEnd)
        {
            CalendarEvent[] calendarEventArray     = null;
            int             mergedFreeBusyInterval = 5;
            bool            exceptionOccurred      = false;

            try
            {
                calendarEventArray = InternalCalendarQuery.GetCalendarEvents(emailAddress, calendarFolder, windowStart, windowEnd, FreeBusyViewType.FreeBusyMerged, true, ExchangeVersionType.Exchange2012);
            }
            catch (ResultSetTooBigException)
            {
                exceptionOccurred = true;
            }
            return(MergedFreeBusy.GenerateMergedFreeBusyString(timeZone, mergedFreeBusyInterval, windowStart, windowEnd, calendarEventArray, exceptionOccurred, null, ExchangeVersionType.Exchange2012));
        }
예제 #2
0
        private FreeBusyQueryResult InternalGetCalendarData(FreeBusyQuery freeBusyQuery, MailboxSession session)
        {
            FreeBusyViewType freeBusyViewType = FreeBusyViewType.None;

            CalendarEvent[] calendarEventArray = null;
            string          mergedFreeBusy     = null;
            WorkingHours    workingHours       = null;
            EmailAddress    email = freeBusyQuery.Email;
            StoreObjectId   associatedFolderId = freeBusyQuery.RecipientData.AssociatedFolderId;
            StoreObjectId   defaultFolderId    = session.GetDefaultFolderId(DefaultFolderType.Calendar);

            if (defaultFolderId == null)
            {
                return(this.HandleException(email, new NoCalendarException()));
            }
            if (associatedFolderId != null && !associatedFolderId.Equals(defaultFolderId))
            {
                return(this.HandleException(email, new NotDefaultCalendarException()));
            }
            session.ExTimeZone = this.clientContext.TimeZone;
            using (CalendarFolder calendarFolder = CalendarFolder.Bind(session, DefaultFolderType.Calendar, CalendarQuery.CalendarFolderQueryProps))
            {
                TimeSpan t = this.deadline - DateTime.UtcNow;
                if (t <= TimeSpan.Zero)
                {
                    return(this.HandleException(email, new TimeoutExpiredException("Determine-Allowed-Access")));
                }
                FreeBusyPermissionLevel freeBusyPermissionLevel = FreeBusyPermission.DetermineAllowedAccess(this.clientContext, session, calendarFolder, freeBusyQuery, this.defaultFreeBusyOnly);
                CalendarQuery.CalendarViewTracer.TraceDebug((long)this.GetHashCode(), "{0}: AccessCheck returned {1} for user {2} on mailbox {3}", new object[]
                {
                    TraceContext.Get(),
                    freeBusyPermissionLevel,
                    this.clientContext,
                    email
                });
                if (freeBusyPermissionLevel == FreeBusyPermissionLevel.None)
                {
                    CalendarQuery.CalendarViewTracer.TraceDebug <object, EmailAddress>((long)this.GetHashCode(), "{0}: No mailbox data will be returned for mailbox {1} since the granted access level to caller is None.", TraceContext.Get(), email);
                    return(new FreeBusyQueryResult(new NoFreeBusyAccessException(44348U)));
                }
                t = this.deadline - DateTime.UtcNow;
                if (t <= TimeSpan.Zero)
                {
                    return(this.HandleException(email, new TimeoutExpiredException("Get-Calendar-View")));
                }
                freeBusyViewType = CalendarQuery.GetReturnView(this.requestedFreeBusyView.RequestedView, freeBusyPermissionLevel);
                ExDateTime windowStart = new ExDateTime(this.clientContext.TimeZone, this.requestedFreeBusyView.TimeWindow.StartTime);
                ExDateTime windowEnd   = new ExDateTime(this.clientContext.TimeZone, this.requestedFreeBusyView.TimeWindow.EndTime);
                try
                {
                    calendarEventArray = InternalCalendarQuery.GetCalendarEvents(email, calendarFolder, windowStart, windowEnd, freeBusyViewType, freeBusyPermissionLevel == FreeBusyPermissionLevel.Owner, this.clientContext.RequestSchemaVersion);
                }
                catch (ResultSetTooBigException e)
                {
                    return(this.HandleException(email, e));
                }
                if (FreeBusyViewOptions.IsMerged(freeBusyViewType))
                {
                    t = this.deadline - DateTime.UtcNow;
                    if (t <= TimeSpan.Zero)
                    {
                        return(this.HandleException(email, new TimeoutExpiredException("Generate-Merged-FreeBusy")));
                    }
                    int mergedFreeBusyIntervalInMinutes = this.requestedFreeBusyView.MergedFreeBusyIntervalInMinutes;
                    mergedFreeBusy = MergedFreeBusy.GenerateMergedFreeBusyString(this.clientContext.TimeZone, mergedFreeBusyIntervalInMinutes, windowStart, windowEnd, calendarEventArray, false, null, this.clientContext.RequestSchemaVersion);
                }
                t = this.deadline - DateTime.UtcNow;
                if (t <= TimeSpan.Zero)
                {
                    return(this.HandleException(email, new TimeoutExpiredException("Getting-Work-Hours")));
                }
                workingHours = this.GetWorkingHours(email, session, calendarFolder);
            }
            return(new FreeBusyQueryResult(freeBusyViewType, calendarEventArray, mergedFreeBusy, workingHours));
        }