Example #1
0
 public FreeBusyQueryResult(FreeBusyViewType view, CalendarEvent[] calendarEventArray, string mergedFreeBusy, WorkingHours workingHours)
 {
     this.view = view;
     this.calendarEventArray = calendarEventArray;
     this.mergedFreeBusy     = mergedFreeBusy;
     this.workingHours       = workingHours;
 }
        /// <summary>
        /// Loads the free busy view from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="viewType">Type of free/busy view.</param>
        internal void LoadFreeBusyViewFromXml(EwsServiceXmlReader reader, FreeBusyViewType viewType)
        {
            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.FreeBusyView);

            string viewTypeString = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.FreeBusyViewType);

            this.viewType = (FreeBusyViewType)Enum.Parse(typeof(FreeBusyViewType), viewTypeString, false);

            do
            {
                reader.Read();

                if (reader.IsStartElement())
                {
                    switch (reader.LocalName)
                    {
                    case XmlElementNames.MergedFreeBusy:
                        string mergedFreeBusy = reader.ReadElementValue();

                        for (int i = 0; i < mergedFreeBusy.Length; i++)
                        {
                            this.mergedFreeBusyStatus.Add((LegacyFreeBusyStatus)Byte.Parse(mergedFreeBusy[i].ToString()));
                        }

                        break;

                    case XmlElementNames.CalendarEventArray:
                        do
                        {
                            reader.Read();

                            if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.CalendarEvent))
                            {
                                CalendarEvent calendarEvent = new CalendarEvent();

                                calendarEvent.LoadFromXml(reader, XmlElementNames.CalendarEvent);

                                this.calendarEvents.Add(calendarEvent);
                            }
                        }while (!reader.IsEndElement(XmlNamespace.Types, XmlElementNames.CalendarEventArray));

                        break;

                    case XmlElementNames.WorkingHours:
                        this.workingHours = new WorkingHours();
                        this.workingHours.LoadFromXml(reader, reader.LocalName);

                        break;
                    }
                }
            }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.FreeBusyView));
        }
        /// <summary>
        /// Loads the free busy view from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="viewType">Type of free/busy view.</param>
        internal void LoadFreeBusyViewFromXml(EwsServiceXmlReader reader, FreeBusyViewType viewType)
        {
            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.FreeBusyView);

            string viewTypeString = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.FreeBusyViewType);

            this.viewType = (FreeBusyViewType)Enum.Parse(typeof(FreeBusyViewType), viewTypeString, false);

            do
            {
                reader.Read();

                if (reader.IsStartElement())
                {
                    switch (reader.LocalName)
                    {
                        case XmlElementNames.MergedFreeBusy:
                            string mergedFreeBusy = reader.ReadElementValue();

                            for (int i = 0; i < mergedFreeBusy.Length; i++)
                            {
                                this.mergedFreeBusyStatus.Add((LegacyFreeBusyStatus)Byte.Parse(mergedFreeBusy[i].ToString()));
                            }

                            break;
                        case XmlElementNames.CalendarEventArray:
                            do
                            {
                                reader.Read();

                                if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.CalendarEvent))
                                {
                                    CalendarEvent calendarEvent = new CalendarEvent();

                                    calendarEvent.LoadFromXml(reader, XmlElementNames.CalendarEvent);

                                    this.calendarEvents.Add(calendarEvent);
                                }
                            }
                            while (!reader.IsEndElement(XmlNamespace.Types, XmlElementNames.CalendarEventArray));

                            break;
                        case XmlElementNames.WorkingHours:
                            this.workingHours = new WorkingHours();
                            this.workingHours.LoadFromXml(reader, reader.LocalName);

                            break;
                    }
                }
            }
            while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.FreeBusyView));
        }
Example #4
0
        private static FreeBusyViewType GetReturnView(FreeBusyViewType requestedView, FreeBusyPermissionLevel freeBusyPermissionLevel)
        {
            FreeBusyViewType freeBusyViewType = FreeBusyViewType.None;

            switch (freeBusyPermissionLevel)
            {
            case FreeBusyPermissionLevel.None:
                freeBusyViewType = FreeBusyViewType.None;
                break;

            case FreeBusyPermissionLevel.Simple:
                freeBusyViewType = FreeBusyViewType.FreeBusy;
                break;

            case FreeBusyPermissionLevel.Detail:
            case FreeBusyPermissionLevel.Owner:
                freeBusyViewType = FreeBusyViewType.Detailed;
                break;
            }
            bool flag = FreeBusyViewOptions.IsMerged(requestedView);
            int  num;
            int  num2;

            if (flag)
            {
                num  = (int)(requestedView | FreeBusyViewType.MergedOnly);
                num2 = (int)(freeBusyViewType | FreeBusyViewType.MergedOnly);
            }
            else
            {
                num  = (int)requestedView;
                num2 = (int)freeBusyViewType;
            }
            int result;

            if (num <= num2)
            {
                result = num;
            }
            else
            {
                result = num2;
            }
            return((FreeBusyViewType)result);
        }
Example #5
0
        internal static CalendarEvent CreateFromQueryData(EmailAddress mailbox, object[] properties, FreeBusyViewType allowedView, bool isCallerMailboxOwner, ExchangeVersionType exchangeVersion)
        {
            CalendarEvent calendarEvent = new CalendarEvent();

            calendarEvent.viewType       = allowedView;
            calendarEvent.globalObjectId = CalendarEvent.GetPropertyValue <byte[]>(properties, QueryPropertyIndexes.GlobalObjectId);
            calendarEvent.StartTime      = DateTime.SpecifyKind((DateTime)CalendarEvent.GetPropertyValue <ExDateTime>(properties, QueryPropertyIndexes.StartTime, ExDateTime.MinValue), DateTimeKind.Unspecified);
            calendarEvent.EndTime        = DateTime.SpecifyKind((DateTime)CalendarEvent.GetPropertyValue <ExDateTime>(properties, QueryPropertyIndexes.EndTime, ExDateTime.MinValue), DateTimeKind.Unspecified);
            BusyType busyType = CalendarEvent.GetPropertyValue <BusyType>(properties, QueryPropertyIndexes.BusyStatus, BusyType.Busy);

            if (busyType < BusyType.Free || busyType > BusyType.NoData)
            {
                CalendarEvent.CalendarViewTracer.TraceError((long)calendarEvent.GetHashCode(), "{0}: Calendar event with start time {1} and end time {2} in mailbox {3} has invalid busy type: {4}. This is being returned as BusyType.Tentative", new object[]
                {
                    TraceContext.Get(),
                    calendarEvent.StartTime,
                    calendarEvent.EndTime,
                    mailbox,
                    busyType
                });
                calendarEvent.BusyType = BusyType.Tentative;
            }
            else
            {
                if (exchangeVersion < ExchangeVersionType.Exchange2012 && busyType == BusyType.WorkingElsewhere)
                {
                    busyType = BusyType.Free;
                }
                calendarEvent.BusyType = busyType;
            }
            Sensitivity propertyValue = CalendarEvent.GetPropertyValue <Sensitivity>(properties, QueryPropertyIndexes.Sensitivity, Sensitivity.Normal);

            if (propertyValue < Sensitivity.Normal || propertyValue > Sensitivity.CompanyConfidential)
            {
                CalendarEvent.CalendarViewTracer.TraceError((long)calendarEvent.GetHashCode(), "{0}: Calendar event with start time {1} and end time {2} in mailbox {3} has invalid sensitivity value: {4}.", new object[]
                {
                    TraceContext.Get(),
                    calendarEvent.StartTime,
                    calendarEvent.EndTime,
                    mailbox,
                    propertyValue
                });
            }
            VersionedId propertyValue2 = CalendarEvent.GetPropertyValue <VersionedId>(properties, QueryPropertyIndexes.EntryId);
            ByteArray   byteArray      = new ByteArray(propertyValue2.ObjectId.ProviderLevelItemId);

            if (allowedView != FreeBusyViewType.Detailed && allowedView != FreeBusyViewType.DetailedMerged)
            {
                return(calendarEvent);
            }
            calendarEvent.CalendarEventDetails = new CalendarEventDetails();
            CalendarEventDetails calendarEventDetails = calendarEvent.CalendarEventDetails;

            calendarEventDetails.IsPrivate = (propertyValue != Sensitivity.Normal);
            if (calendarEventDetails.IsPrivate && !isCallerMailboxOwner)
            {
                CalendarEvent.CalendarViewTracer.TraceError((long)calendarEvent.GetHashCode(), "{0}: Calendar event with start time {1} and end time {2} in mailbox {3} is a private item. Detail data will not be included.", new object[]
                {
                    TraceContext.Get(),
                    calendarEvent.StartTime,
                    calendarEvent.EndTime,
                    mailbox
                });
                return(calendarEvent);
            }
            calendarEventDetails.ID            = byteArray.ToString();
            calendarEventDetails.Subject       = CalendarEvent.GetPropertyValue <string>(properties, QueryPropertyIndexes.Subject);
            calendarEventDetails.Location      = CalendarEvent.GetPropertyValue <string>(properties, QueryPropertyIndexes.Location);
            calendarEventDetails.IsReminderSet = CalendarEvent.GetPropertyValue <bool>(properties, QueryPropertyIndexes.IsReminderSet, false);
            AppointmentStateFlags propertyValue3 = CalendarEvent.GetPropertyValue <AppointmentStateFlags>(properties, QueryPropertyIndexes.AppointmentState, AppointmentStateFlags.None);

            calendarEventDetails.IsMeeting = ((propertyValue3 & AppointmentStateFlags.Meeting) > AppointmentStateFlags.None);
            CalendarItemType propertyValue4 = CalendarEvent.GetPropertyValue <CalendarItemType>(properties, QueryPropertyIndexes.CalendarItemType, CalendarItemType.Single);

            if (propertyValue4 == CalendarItemType.Occurrence)
            {
                calendarEventDetails.IsRecurring = true;
            }
            if (propertyValue4 == CalendarItemType.Exception)
            {
                calendarEventDetails.IsException = true;
                calendarEventDetails.IsRecurring = true;
            }
            return(calendarEvent);
        }
Example #6
0
    /// <summary>
    /// Loads the free busy view from XML.
    /// </summary>
    /// <param name="reader">The reader.</param>
    /// <param name="viewType">Type of free/busy view.</param>
    void LoadFreeBusyViewFromXml(EwsServiceXmlReader reader, FreeBusyViewType viewType)
    {
        reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.FreeBusyView);

        String viewTypeString = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.FreeBusyViewType);

        this.viewType = (FreeBusyViewType)Enum.Parse(typeof(FreeBusyViewType), viewTypeString, false);

        do
        {
            reader.Read();

            if (reader.IsStartElement())
            {
                switch (reader.LocalName)
                {
                case XmlElementNames.MergedFreeBusy:
                    String mergedFreeBusy = reader.ReadElementValue <String>();

                    for (int i = 0; i < mergedFreeBusy.Length; i++)
                    {
                        this.mergedFreeBusyStatus.Add((LegacyFreeBusyStatus)Byte.Parse(mergedFreeBusy[i].ToString()));
                    }

                    break;

                case XmlElementNames.CalendarEventArray:
                    do
                    {
                        reader.Read();

                        // Sometimes Exchange Online returns blank CalendarEventArray tag like bellow.
                        // <CalendarEventArray xmlns="http://schemas.microsoft.com/exchange/services/2006/types" />
                        // So we have to check the end of CalendarEventArray tag.
                        if (reader.LocalName == XmlElementNames.FreeBusyView)
                        {
                            // There is no the end tag of CalendarEventArray, but the reader is reading the end tag of FreeBusyView.
                            break;
                        }
                        else if (reader.LocalName == XmlElementNames.WorkingHours)
                        {
                            // There is no the end tag of CalendarEventArray, but the reader is reading the start tag of WorkingHours.
                            goto case XmlElementNames.WorkingHours;
                        }

                        if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.CalendarEvent))
                        {
                            CalendarEvent calendarEvent = new CalendarEvent();

                            calendarEvent.LoadFromXml(reader, XmlElementNames.CalendarEvent);

                            this.calendarEvents.Add(calendarEvent);
                        }
                    }while (!reader.IsEndElement(XmlNamespace.Types, XmlElementNames.CalendarEventArray));

                    break;

                case XmlElementNames.WorkingHours:
                    this.workingHours = new WorkingHours();
                    this.workingHours.LoadFromXml(reader, reader.LocalName);

                    break;
                }
            }
        }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.FreeBusyView));
    }
Example #7
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));
        }
 internal static bool IsMerged(FreeBusyViewType viewType)
 {
     return((viewType & FreeBusyViewType.MergedOnly) > FreeBusyViewType.None);
 }
 public FreeBusyViewOptions(Duration timeWindow, int mergedFreeBusyIntervalInMinutes, FreeBusyViewType requestedView)
 {
     this.Init();
     this.timeWindow = timeWindow;
     this.mergedFreeBusyIntervalInMinutes = mergedFreeBusyIntervalInMinutes;
     this.requestedView = requestedView;
     this.Validate();
 }
        internal static CalendarEvent[] GetCalendarEvents(EmailAddress emailAddress, CalendarFolder calendarFolder, ExDateTime windowStart, ExDateTime windowEnd, FreeBusyViewType accessAllowed, bool canActAsMailboxOwner, ExchangeVersionType exchangeVersion)
        {
            CalendarEvent[] array = null;
            int             num   = 0;

            object[][] calendarView = calendarFolder.GetCalendarView(windowStart, windowEnd, InternalCalendarQuery.CalendarQueryProperties);
            InternalCalendarQuery.CalendarViewTracer.TraceDebug(0L, "{0}: Query for {1} found {2} appointment entries between {3} and {4}", new object[]
            {
                TraceContext.Get(),
                emailAddress,
                calendarView.Length,
                windowStart,
                windowEnd
            });
            num += calendarView.Length;
            if (num > Configuration.MaximumResultSetSize)
            {
                LocalizedException ex = new ResultSetTooBigException(Configuration.MaximumResultSetSize, num);
                InternalCalendarQuery.CalendarViewTracer.TraceError <object, EmailAddress, LocalizedException>(0L, "{0}: Query for {1} got exception getting Calendar Data. Exception: {2}", TraceContext.Get(), emailAddress, ex);
                throw ex;
            }
            int length = calendarView.GetLength(0);

            if (length > 0)
            {
                array = new CalendarEvent[length];
                for (int i = 0; i < length; i++)
                {
                    object[] properties = calendarView[i];
                    array[i] = CalendarEvent.CreateFromQueryData(emailAddress, properties, accessAllowed, canActAsMailboxOwner, exchangeVersion);
                }
            }
            return(array);
        }