Esempio n. 1
0
        public static byte[] ToRecurrenceBlob(Properties easCalendarItem, ExDateTime start, ExDateTime end, ExTimeZone targetTimeZone)
        {
            Microsoft.Exchange.Connections.Eas.Model.Response.Calendar.Recurrence recurrence = easCalendarItem.Recurrence;
            RecurrencePattern  pattern            = SyncCalendarUtils.CreateRecurrencePattern(recurrence);
            RecurrenceRange    range              = SyncCalendarUtils.CreateRecurrenceRange(start, recurrence);
            ExDateTime         dt                 = targetTimeZone.ConvertDateTime(start);
            ExDateTime         dt2                = targetTimeZone.ConvertDateTime(end);
            TimeSpan           startOffset        = dt - dt.Date;
            TimeSpan           endOffset          = dt2 - dt2.Date;
            InternalRecurrence internalRecurrence = new InternalRecurrence(pattern, range, null, targetTimeZone, ExTimeZone.UtcTimeZone, startOffset, endOffset);

            if (easCalendarItem.Exceptions != null)
            {
                foreach (Microsoft.Exchange.Connections.Eas.Model.Response.Calendar.Exception ex in easCalendarItem.Exceptions)
                {
                    ExDateTime originalStartTime = SyncCalendarUtils.ToUtcExDateTime(ex.ExceptionStartTime);
                    ExDateTime date = originalStartTime.Date;
                    if (ex.Deleted)
                    {
                        internalRecurrence.TryDeleteOccurrence(date);
                    }
                    else
                    {
                        ModificationType  modificationType  = (ModificationType)0;
                        MemoryPropertyBag memoryPropertyBag = new MemoryPropertyBag();
                        memoryPropertyBag.SetAllPropertiesLoaded();
                        if (ex.Subject != easCalendarItem.CalendarSubject)
                        {
                            modificationType |= ModificationType.Subject;
                            memoryPropertyBag[ItemSchema.Subject] = ex.Subject;
                        }
                        if (ex.Reminder != easCalendarItem.Reminder)
                        {
                            modificationType |= ModificationType.ReminderDelta;
                            memoryPropertyBag[ItemSchema.ReminderMinutesBeforeStartInternal] = ex.Reminder;
                        }
                        if (ex.Location != easCalendarItem.Location)
                        {
                            modificationType |= ModificationType.Location;
                            memoryPropertyBag[CalendarItemBaseSchema.Location] = ex.Location;
                        }
                        if (ex.BusyStatus != easCalendarItem.BusyStatus)
                        {
                            modificationType |= ModificationType.BusyStatus;
                            memoryPropertyBag[CalendarItemBaseSchema.FreeBusyStatus] = ex.BusyStatus;
                        }
                        if (ex.AllDayEvent != easCalendarItem.AllDayEvent)
                        {
                            modificationType |= ModificationType.SubType;
                            memoryPropertyBag[CalendarItemBaseSchema.MapiIsAllDayEvent] = ex.AllDayEvent;
                        }
                        ExDateTime    startTime     = targetTimeZone.ConvertDateTime(SyncCalendarUtils.ToUtcExDateTime(ex.StartTime));
                        ExDateTime    endTime       = targetTimeZone.ConvertDateTime(SyncCalendarUtils.ToUtcExDateTime(ex.EndTime));
                        ExceptionInfo exceptionInfo = new ExceptionInfo(null, date, originalStartTime, startTime, endTime, modificationType, memoryPropertyBag);
                        internalRecurrence.ModifyOccurrence(exceptionInfo);
                    }
                }
            }
            return(internalRecurrence.ToByteArray());
        }
Esempio n. 2
0
 private static RecurrenceRange CreateRecurrenceRange(ExDateTime start, Microsoft.Exchange.Connections.Eas.Model.Response.Calendar.Recurrence easRecurrence)
 {
     if (easRecurrence.Occurrences != 0)
     {
         return(new NumberedRecurrenceRange(start, easRecurrence.Occurrences));
     }
     if (!string.IsNullOrEmpty(easRecurrence.Until))
     {
         ExDateTime endDate = SyncCalendarUtils.ToExDateTime(easRecurrence.Until);
         return(new EndDateRecurrenceRange(start, endDate));
     }
     return(new NoEndRecurrenceRange(start));
 }
Esempio n. 3
0
        private static RecurrencePattern CreateRecurrencePattern(Microsoft.Exchange.Connections.Eas.Model.Response.Calendar.Recurrence easRecurrence)
        {
            try
            {
                EasRecurrenceType type = (EasRecurrenceType)easRecurrence.Type;
                switch (type)
                {
                case EasRecurrenceType.Daily:
                    if (easRecurrence.DayOfWeek != 0)
                    {
                        return(new WeeklyRecurrencePattern((DaysOfWeek)easRecurrence.DayOfWeek));
                    }
                    return(new DailyRecurrencePattern(easRecurrence.Interval));

                case EasRecurrenceType.Weekly:
                    return(new WeeklyRecurrencePattern((DaysOfWeek)easRecurrence.DayOfWeek, easRecurrence.Interval));

                case EasRecurrenceType.Monthly:
                    return(new MonthlyRecurrencePattern(easRecurrence.DayOfMonth, easRecurrence.Interval));

                case EasRecurrenceType.MonthlyTh:
                    {
                        RecurrenceOrderType order = SyncCalendarUtils.RecurrenceOrderTypeFromWeekOfMonth(easRecurrence.WeekOfMonth);
                        return(new MonthlyThRecurrencePattern((DaysOfWeek)easRecurrence.DayOfWeek, order, easRecurrence.Interval));
                    }

                case EasRecurrenceType.Yearly:
                    return(new YearlyRecurrencePattern(easRecurrence.DayOfMonth, easRecurrence.MonthOfYear));

                case EasRecurrenceType.YearlyTh:
                {
                    RecurrenceOrderType order2 = SyncCalendarUtils.RecurrenceOrderTypeFromWeekOfMonth(easRecurrence.WeekOfMonth);
                    return(new YearlyThRecurrencePattern((DaysOfWeek)easRecurrence.DayOfWeek, order2, easRecurrence.MonthOfYear));
                }
                }
                throw new EasFetchFailedPermanentException("Invalid recurrence type: " + type);
            }
            catch (ArgumentOutOfRangeException innerException)
            {
                throw new EasFetchFailedPermanentException("Invalid recurrence", innerException);
            }
            RecurrencePattern result;

            return(result);
        }