public override void Parse <T>(T rules)
        {
            if (rules is OutlookRecurrencePattern)
            {
                Log.Info("Parsing OutlookRecurrencePattern...");
                var outlookRp = rules as OutlookRecurrencePattern;
                Log.Info(String.Format("Recurrence type is [{0}]", outlookRp.RecurrenceType));
                switch (outlookRp.RecurrenceType)
                {
                case OlRecurrenceType.olRecursDaily:
                {
                    Pattern = new DDay.iCal.RecurrencePattern(FrequencyType.Daily, outlookRp.Interval)
                    {
                        FirstDayOfWeek  = DayOfWeek.Monday,
                        RestrictionType = RecurrenceRestrictionType.Default
                    };
                    if (outlookRp.Occurrences > 0)
                    {
                        Pattern.Count = outlookRp.Occurrences;
                    }
                    else if (outlookRp.PatternEndDate > DateTime.Now)
                    {
                        Pattern.Until = outlookRp.PatternEndDate;
                    }
                }
                break;

                case OlRecurrenceType.olRecursWeekly:
                {
                    Pattern = new DDay.iCal.RecurrencePattern(FrequencyType.Weekly, outlookRp.Interval)
                    {
                        FirstDayOfWeek  = DayOfWeek.Monday,
                        RestrictionType = RecurrenceRestrictionType.NoRestriction
                    };
                    if (outlookRp.Occurrences > 0)
                    {
                        Pattern.Count = outlookRp.Occurrences;
                    }
                    else if (outlookRp.PatternEndDate > DateTime.Now)
                    {
                        Pattern.Until = outlookRp.PatternEndDate;
                    }
                    Pattern.ByDay = ExtractDaysOfWeek(outlookRp.DayOfWeekMask);
                }
                break;

                case OlRecurrenceType.olRecursMonthly:
                {
                    // warning: untested
                    // see also: http://msdn.microsoft.com/en-us/library/office/aa211012(v=office.11).aspx
                    Pattern = new DDay.iCal.RecurrencePattern(FrequencyType.Monthly, outlookRp.Interval)
                    {
                        FirstDayOfWeek  = DayOfWeek.Monday,
                        RestrictionType = RecurrenceRestrictionType.NoRestriction
                    };
                    // how many times this is going to occur
                    if (outlookRp.Occurrences > 0)
                    {
                        Pattern.Count = outlookRp.Occurrences;
                    }
                    else if (outlookRp.DayOfMonth > 0)
                    {
                        Pattern.ByMonthDay = new List <int> {
                            outlookRp.DayOfMonth
                        };
                    }
                }
                break;

                case OlRecurrenceType.olRecursMonthNth:
                {
                    // see also: http://msdn.microsoft.com/en-us/library/office/aa211012(v=office.11).aspx
                    Pattern = new DDay.iCal.RecurrencePattern(FrequencyType.Monthly, outlookRp.Interval)
                    {
                        FirstDayOfWeek  = DayOfWeek.Monday,
                        RestrictionType = RecurrenceRestrictionType.NoRestriction
                    };
                    // how many times this is going to occur
                    if (outlookRp.Occurrences > 0)
                    {
                        Pattern.Count = outlookRp.Occurrences;
                    }
                    // instance states e.g.: "The Nth Tuesday"
                    if (outlookRp.Instance > 0)
                    {
                        Pattern.BySetPosition = new List <int> {
                            outlookRp.Instance
                        };
                    }
                    if (outlookRp.DayOfWeekMask > 0)
                    {
                        Pattern.ByDay = ExtractDaysOfWeek(outlookRp.DayOfWeekMask);
                    }
                }
                break;

                case OlRecurrenceType.olRecursYearly:
                {
                    // warning: untested
                    Pattern = new DDay.iCal.RecurrencePattern(FrequencyType.Yearly, outlookRp.Interval)
                    {
                        FirstDayOfWeek  = DayOfWeek.Monday,
                        RestrictionType = RecurrenceRestrictionType.NoRestriction
                    };
                    if (outlookRp.Occurrences > 0)
                    {
                        Pattern.Count = outlookRp.Occurrences;
                    }
                    else if (outlookRp.PatternEndDate > DateTime.Now)
                    {
                        Pattern.Until = outlookRp.PatternEndDate;
                    }
                    if (outlookRp.DayOfWeekMask > 0)
                    {
                        Pattern.ByDay = ExtractDaysOfWeek(outlookRp.DayOfWeekMask);
                    }
                    else if (outlookRp.DayOfMonth > 0)
                    {
                        Pattern.ByMonthDay = new List <int> {
                            outlookRp.DayOfMonth
                        };
                    }
                }
                break;

                case OlRecurrenceType.olRecursYearNth:
                {
                    // warning: untested
                    Pattern = new DDay.iCal.RecurrencePattern(FrequencyType.Yearly, outlookRp.Interval)
                    {
                        FirstDayOfWeek  = DayOfWeek.Monday,
                        RestrictionType = RecurrenceRestrictionType.NoRestriction
                    };
                    if (outlookRp.Occurrences > 0)
                    {
                        Pattern.Count = outlookRp.Occurrences;
                    }
                    else if (outlookRp.PatternEndDate > DateTime.Now)
                    {
                        Pattern.Until = outlookRp.PatternEndDate;
                    }
                    if (outlookRp.DayOfWeekMask > 0)
                    {
                        Pattern.ByDay = ExtractDaysOfWeek(outlookRp.DayOfWeekMask);
                    }
                    else if (outlookRp.DayOfMonth > 0)
                    {
                        Pattern.ByMonthDay = new List <int> {
                            outlookRp.DayOfMonth
                        };
                    }
                }
                break;
                }
                Log.Debug(String.Format("iCalendar recurrence pattern is [{0}]", Pattern));
            }
            else
            {
                throw new RecurrenceParseException("OutlookRecurrence: Unsupported type.", typeof(T));
            }
        }
Пример #2
0
        private IRecurrencePattern ProcessRecurrencePattern(IDateTime referenceDate)
        {
            var r = new RecurrencePattern();

            r.CopyFrom(Pattern);

            // Convert the UNTIL value to one that matches the same time information as the reference date
            if (r.Until != DateTime.MinValue)
            {
                r.Until = DateUtil.MatchTimeZone(referenceDate, new iCalDateTime(r.Until)).Value;
            }

            if (r.Frequency > FrequencyType.Secondly &&
                r.BySecond.Count == 0 &&
                referenceDate.HasTime /* NOTE: Fixes a bug where all-day events have BySecond/ByMinute/ByHour added incorrectly */)
            {
                r.BySecond.Add(referenceDate.Second);
            }
            if (r.Frequency > FrequencyType.Minutely &&
                r.ByMinute.Count == 0 &&
                referenceDate.HasTime /* NOTE: Fixes a bug where all-day events have BySecond/ByMinute/ByHour added incorrectly */)
            {
                r.ByMinute.Add(referenceDate.Minute);
            }
            if (r.Frequency > FrequencyType.Hourly &&
                r.ByHour.Count == 0 &&
                referenceDate.HasTime /* NOTE: Fixes a bug where all-day events have BySecond/ByMinute/ByHour added incorrectly */)
            {
                r.ByHour.Add(referenceDate.Hour);
            }

            // If BYDAY, BYYEARDAY, or BYWEEKNO is specified, then
            // we don't default BYDAY, BYMONTH or BYMONTHDAY
            if (r.ByDay.Count == 0)
            {
                // If the frequency is weekly, use the original date's day of week.
                // NOTE: fixes WeeklyCount1() and WeeklyUntil1() handling
                // If BYWEEKNO is specified and BYMONTHDAY/BYYEARDAY is not specified,
                // then let's add BYDAY to BYWEEKNO.
                // NOTE: fixes YearlyByWeekNoX() handling
                if (r.Frequency == FrequencyType.Weekly ||
                    (
                        r.ByWeekNo.Count > 0 &&
                        r.ByMonthDay.Count == 0 &&
                        r.ByYearDay.Count == 0
                    ))
                {
                    r.ByDay.Add(new WeekDay(referenceDate.DayOfWeek));
                }

                // If BYMONTHDAY is not specified,
                // default to the current day of month.
                // NOTE: fixes YearlyByMonth1() handling, added BYYEARDAY exclusion
                // to fix YearlyCountByYearDay1() handling
                if (r.Frequency > FrequencyType.Weekly &&
                    r.ByWeekNo.Count == 0 &&
                    r.ByYearDay.Count == 0 &&
                    r.ByMonthDay.Count == 0)
                {
                    r.ByMonthDay.Add(referenceDate.Day);
                }

                // If BYMONTH is not specified, default to
                // the current month.
                // NOTE: fixes YearlyCountByYearDay1() handling
                if (r.Frequency > FrequencyType.Monthly &&
                    r.ByWeekNo.Count == 0 &&
                    r.ByYearDay.Count == 0 &&
                    r.ByMonth.Count == 0)
                {
                    r.ByMonth.Add(referenceDate.Month);
                }
            }

            return(r);
        }
        private IRecurrencePattern ProcessRecurrencePattern(IDateTime referenceDate)
        {
            RecurrencePattern r = new RecurrencePattern();

            r.CopyFrom(Pattern);

            // Convert the UNTIL value to a local date/time based on the time zone information that
            // is in the reference date
            if (r.Until != DateTime.MinValue)
            {
                // Build an iCalDateTime with the correct time zone & calendar
                var until = new iCalDateTime(r.Until, referenceDate.TZID);
                until.AssociatedObject = referenceDate.AssociatedObject;

                // Convert back to local time so time zone comparisons match
                r.Until = until.Local;
            }

            if (r.Frequency > FrequencyType.Secondly &&
                r.BySecond.Count == 0 &&
                referenceDate.HasTime /* NOTE: Fixes a bug where all-day events have BySecond/ByMinute/ByHour added incorrectly */)
            {
                r.BySecond.Add(referenceDate.Second);
            }
            if (r.Frequency > FrequencyType.Minutely &&
                r.ByMinute.Count == 0 &&
                referenceDate.HasTime /* NOTE: Fixes a bug where all-day events have BySecond/ByMinute/ByHour added incorrectly */)
            {
                r.ByMinute.Add(referenceDate.Minute);
            }
            if (r.Frequency > FrequencyType.Hourly &&
                r.ByHour.Count == 0 &&
                referenceDate.HasTime /* NOTE: Fixes a bug where all-day events have BySecond/ByMinute/ByHour added incorrectly */)
            {
                r.ByHour.Add(referenceDate.Hour);
            }

            // If BYDAY, BYYEARDAY, or BYWEEKNO is specified, then
            // we don't default BYDAY, BYMONTH or BYMONTHDAY
            if (r.ByDay.Count == 0)
            {
                // If the frequency is weekly, use the original date's day of week.
                // NOTE: fixes WeeklyCount1() and WeeklyUntil1() handling
                // If BYWEEKNO is specified and BYMONTHDAY/BYYEARDAY is not specified,
                // then let's add BYDAY to BYWEEKNO.
                // NOTE: fixes YearlyByWeekNoX() handling
                if (r.Frequency == FrequencyType.Weekly ||
                    (
                        r.ByWeekNo.Count > 0 &&
                        r.ByMonthDay.Count == 0 &&
                        r.ByYearDay.Count == 0
                    ))
                {
                    r.ByDay.Add(new WeekDay(referenceDate.DayOfWeek));
                }

                // If BYMONTHDAY is not specified,
                // default to the current day of month.
                // NOTE: fixes YearlyByMonth1() handling, added BYYEARDAY exclusion
                // to fix YearlyCountByYearDay1() handling
                if (r.Frequency > FrequencyType.Weekly &&
                    r.ByWeekNo.Count == 0 &&
                    r.ByYearDay.Count == 0 &&
                    r.ByMonthDay.Count == 0)
                {
                    r.ByMonthDay.Add(referenceDate.Day);
                }

                // If BYMONTH is not specified, default to
                // the current month.
                // NOTE: fixes YearlyCountByYearDay1() handling
                if (r.Frequency > FrequencyType.Monthly &&
                    r.ByWeekNo.Count == 0 &&
                    r.ByYearDay.Count == 0 &&
                    r.ByMonth.Count == 0)
                {
                    r.ByMonth.Add(referenceDate.Month);
                }
            }

            return(r);
        }
        private void MapRecurrance1To2(TaskItem source, ITodo target, iCalTimeZone localIcalTimeZone)
        {
            if (source.IsRecurring)
            {
                using (var sourceRecurrencePatternWrapper = GenericComObjectWrapper.Create(source.GetRecurrencePattern()))
                {
                    var sourceRecurrencePattern = sourceRecurrencePatternWrapper.Inner;
                    IRecurrencePattern targetRecurrencePattern = new RecurrencePattern();
                    if (!sourceRecurrencePattern.NoEndDate)
                    {
                        targetRecurrencePattern.Count = sourceRecurrencePattern.Occurrences;
                        //Until must not be set if count is set, since outlook always sets Occurrences
                        //but sogo wants it as utc end time of the last event not only the enddate at 0000
                        //targetRecurrencePattern.Until = sourceRecurrencePattern.PatternEndDate.Add(sourceRecurrencePattern.EndTime.TimeOfDay).ToUniversalTime();
                    }
                    targetRecurrencePattern.Interval = (sourceRecurrencePattern.RecurrenceType == OlRecurrenceType.olRecursYearly ||
                                                        sourceRecurrencePattern.RecurrenceType == OlRecurrenceType.olRecursYearNth) ? sourceRecurrencePattern.Interval / 12 : sourceRecurrencePattern.Interval;

                    switch (sourceRecurrencePattern.RecurrenceType)
                    {
                    case OlRecurrenceType.olRecursDaily:
                        targetRecurrencePattern.Frequency = FrequencyType.Daily;
                        break;

                    case OlRecurrenceType.olRecursWeekly:
                        targetRecurrencePattern.Frequency = FrequencyType.Weekly;
                        CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay);
                        break;

                    case OlRecurrenceType.olRecursMonthly:
                        targetRecurrencePattern.Frequency = FrequencyType.Monthly;
                        targetRecurrencePattern.ByMonthDay.Add(sourceRecurrencePattern.DayOfMonth);
                        break;

                    case OlRecurrenceType.olRecursMonthNth:
                        targetRecurrencePattern.Frequency = FrequencyType.Monthly;

                        if (sourceRecurrencePattern.Instance == 5)
                        {
                            targetRecurrencePattern.BySetPosition.Add(-1);
                            CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay);
                        }
                        else if (sourceRecurrencePattern.Instance > 0)
                        {
                            targetRecurrencePattern.BySetPosition.Add(sourceRecurrencePattern.Instance);
                            CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay);
                        }
                        else
                        {
                            CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay);
                        }
                        break;

                    case OlRecurrenceType.olRecursYearly:
                        targetRecurrencePattern.Frequency = FrequencyType.Yearly;
                        targetRecurrencePattern.ByMonthDay.Add(sourceRecurrencePattern.DayOfMonth);
                        targetRecurrencePattern.ByMonth.Add(sourceRecurrencePattern.MonthOfYear);
                        break;

                    case OlRecurrenceType.olRecursYearNth:
                        targetRecurrencePattern.Frequency = FrequencyType.Yearly;
                        if (sourceRecurrencePattern.Instance == 5)
                        {
                            targetRecurrencePattern.BySetPosition.Add(-1);
                            CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay);
                        }
                        else if (sourceRecurrencePattern.Instance > 0)
                        {
                            targetRecurrencePattern.BySetPosition.Add(sourceRecurrencePattern.Instance);
                            CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay);
                        }
                        else
                        {
                            CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay);
                        }
                        targetRecurrencePattern.ByMonth.Add(sourceRecurrencePattern.MonthOfYear);
                        break;
                    }

                    target.RecurrenceRules.Add(targetRecurrencePattern);
                }
            }
        }
        private void MapRecurrance1To2(TaskItem source, ITodo target, iCalTimeZone localIcalTimeZone)
        {
            if (source.IsRecurring)
            {
                using (var sourceRecurrencePatternWrapper = GenericComObjectWrapper.Create(source.GetRecurrencePattern()))
                {
                    var sourceRecurrencePattern = sourceRecurrencePatternWrapper.Inner;

                    // Recurring task must have a DTSTART according to the RFC but Outlook may have no task start date set, use PatternStartDate in this case
                    if (source.StartDate == OutlookUtility.OUTLOOK_DATE_NONE)
                    {
                        target.Start = new iCalDateTime(sourceRecurrencePattern.PatternStartDate.Year,
                                                        sourceRecurrencePattern.PatternStartDate.Month, sourceRecurrencePattern.PatternStartDate.Day, true);
                        if (!_configuration.MapStartAndDueAsFloating)
                        {
                            target.Start.SetTimeZone(localIcalTimeZone);
                        }
                    }
                    IRecurrencePattern targetRecurrencePattern = new RecurrencePattern();

                    // Don't set Count if pattern has NoEndDate or invalid Occurences for some reason.
                    if (!sourceRecurrencePattern.NoEndDate && sourceRecurrencePattern.Occurrences > 0)
                    {
                        targetRecurrencePattern.Count = sourceRecurrencePattern.Occurrences;
                        //Until must not be set if count is set, since outlook always sets Occurrences
                        //but sogo wants it as utc end time of the last event not only the enddate at 0000
                        //targetRecurrencePattern.Until = sourceRecurrencePattern.PatternEndDate.Add(sourceRecurrencePattern.EndTime.TimeOfDay).ToUniversalTime();
                    }
                    targetRecurrencePattern.Interval = (sourceRecurrencePattern.RecurrenceType == OlRecurrenceType.olRecursYearly ||
                                                        sourceRecurrencePattern.RecurrenceType == OlRecurrenceType.olRecursYearNth) ? sourceRecurrencePattern.Interval / 12 : sourceRecurrencePattern.Interval;

                    switch (sourceRecurrencePattern.RecurrenceType)
                    {
                    case OlRecurrenceType.olRecursDaily:
                        targetRecurrencePattern.Frequency = FrequencyType.Daily;
                        break;

                    case OlRecurrenceType.olRecursWeekly:
                        targetRecurrencePattern.Frequency = FrequencyType.Weekly;
                        CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay);
                        break;

                    case OlRecurrenceType.olRecursMonthly:
                        targetRecurrencePattern.Frequency = FrequencyType.Monthly;
                        targetRecurrencePattern.ByMonthDay.Add(sourceRecurrencePattern.DayOfMonth);
                        break;

                    case OlRecurrenceType.olRecursMonthNth:
                        targetRecurrencePattern.Frequency = FrequencyType.Monthly;

                        if (sourceRecurrencePattern.Instance == 5)
                        {
                            targetRecurrencePattern.BySetPosition.Add(-1);
                            CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay);
                        }
                        else if (sourceRecurrencePattern.Instance > 0)
                        {
                            targetRecurrencePattern.BySetPosition.Add(sourceRecurrencePattern.Instance);
                            CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay);
                        }
                        else
                        {
                            CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay);
                        }
                        break;

                    case OlRecurrenceType.olRecursYearly:
                        targetRecurrencePattern.Frequency = FrequencyType.Yearly;
                        targetRecurrencePattern.ByMonthDay.Add(sourceRecurrencePattern.DayOfMonth);
                        targetRecurrencePattern.ByMonth.Add(sourceRecurrencePattern.MonthOfYear);
                        break;

                    case OlRecurrenceType.olRecursYearNth:
                        targetRecurrencePattern.Frequency = FrequencyType.Yearly;
                        if (sourceRecurrencePattern.Instance == 5)
                        {
                            targetRecurrencePattern.BySetPosition.Add(-1);
                            CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay);
                        }
                        else if (sourceRecurrencePattern.Instance > 0)
                        {
                            targetRecurrencePattern.BySetPosition.Add(sourceRecurrencePattern.Instance);
                            CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay);
                        }
                        else
                        {
                            CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay);
                        }
                        targetRecurrencePattern.ByMonth.Add(sourceRecurrencePattern.MonthOfYear);
                        break;
                    }

                    target.RecurrenceRules.Add(targetRecurrencePattern);
                }
            }
        }
    /// <summary>
    /// Creates a Recurrence Rule in RadScheduler-friendly format from the RRule of the specified Recurring component.
    /// </summary>
    /// <param name="startDate">The Start Date of the Recurring component.</param>
    /// <param name="endDate">The End Date of the Recurring component.</param>
    /// <param name="recurringComponent">The Recurring component.</param>
    /// <returns>A <see cref="string"/> representation of the RRule in RadScheduler-friendly format.</returns>
    private static string GetSchedulerRecurrenceRule(DateTime startDate, DateTime endDate, RecurringComponent recurringComponent)
    {
        string recurrenceRuleString = String.Empty;

        if ((recurringComponent.RecurrenceRules != null) &&
            (recurringComponent.RecurrenceRules[0] != null))
        {
            RecurrenceRange schedulerRange = new RecurrenceRange();
            schedulerRange.Start         = startDate;
            schedulerRange.EventDuration = endDate - startDate;
            DDay.iCal.RecurrencePattern iCalPattern = (DDay.iCal.RecurrencePattern)recurringComponent.RecurrenceRules[0];
            if (iCalPattern.Count > 0)
            {
                schedulerRange.MaxOccurrences = iCalPattern.Count;
            }
            else if ((iCalPattern.Until != null))//&&   (iCalPattern.IsValidDate(iCalPattern.Until))
            {
                schedulerRange.RecursUntil = iCalPattern.Until.ToLocalTime();
            }
            RecurrenceRule schedulerRRule         = null;
            int            iCallPatternInterval   = iCalPattern.Interval;
            RecurrenceDay  schedulerRecurrenceDay = GetSchedulerRecurrenceDay(iCalPattern.ByDay);
            switch (iCalPattern.Frequency)
            {
            case FrequencyType.Hourly:
                schedulerRRule =
                    new HourlyRecurrenceRule(iCallPatternInterval, schedulerRange);
                break;

            case FrequencyType.Daily:
                if (schedulerRecurrenceDay == RecurrenceDay.None)
                {
                    schedulerRRule =
                        new DailyRecurrenceRule(iCallPatternInterval, schedulerRange);
                }
                else
                {
                    schedulerRRule =
                        new DailyRecurrenceRule(schedulerRecurrenceDay, schedulerRange);
                }
                break;

            case FrequencyType.Weekly:
                if (schedulerRecurrenceDay == RecurrenceDay.None)
                {
                    schedulerRRule =
                        new WeeklyRecurrenceRule(
                            iCallPatternInterval,
                            (RecurrenceDay)startDate.DayOfWeek,
                            schedulerRange,
                            iCalPattern.FirstDayOfWeek);
                }
                else
                {
                    schedulerRRule =
                        new WeeklyRecurrenceRule(
                            iCallPatternInterval,
                            schedulerRecurrenceDay,
                            schedulerRange,
                            iCalPattern.FirstDayOfWeek);
                }
                break;

            case FrequencyType.Monthly:
                if (iCalPattern.ByMonthDay.Count > 0)
                {
                    schedulerRRule = new MonthlyRecurrenceRule(
                        iCalPattern.ByMonthDay[0],
                        iCallPatternInterval,
                        schedulerRange);
                }
                else if (iCalPattern.BySetPosition.Count > 0)
                {
                    schedulerRRule = new MonthlyRecurrenceRule(
                        iCalPattern.BySetPosition[0],
                        schedulerRecurrenceDay,
                        iCallPatternInterval,
                        schedulerRange);
                }
                else
                {
                    schedulerRRule = new MonthlyRecurrenceRule(
                        startDate.Day,
                        iCallPatternInterval,
                        schedulerRange);
                }
                break;

            case FrequencyType.Yearly:
                if (iCalPattern.ByMonth.Count > 0)
                {
                    if (iCalPattern.ByMonthDay.Count > 0)
                    {
                        schedulerRRule = new YearlyRecurrenceRule(
                            (RecurrenceMonth)iCalPattern.ByMonth[0],
                            iCalPattern.ByMonthDay[0],
                            schedulerRange);
                    }
                    else if (iCalPattern.BySetPosition.Count > 0)
                    {
                        schedulerRRule = new YearlyRecurrenceRule(
                            iCalPattern.BySetPosition[0],
                            (RecurrenceMonth)iCalPattern.ByMonth[0],
                            schedulerRecurrenceDay,
                            schedulerRange);
                    }
                    else
                    {
                        schedulerRRule = new YearlyRecurrenceRule(
                            (RecurrenceMonth)iCalPattern.ByMonth[0],
                            startDate.Day,
                            schedulerRange);
                    }
                }
                else
                {
                    schedulerRRule = new YearlyRecurrenceRule(
                        (RecurrenceMonth)startDate.Month,
                        startDate.Day,
                        schedulerRange);
                }
                break;

            default:
                break;
            }
            if (schedulerRRule != null)
            {
                AddRecurrenceExceptions(schedulerRRule, recurringComponent);
                recurrenceRuleString = schedulerRRule.ToString();
            }
        }
        return(recurrenceRuleString);
    }