Beispiel #1
0
        private static bool ShouldCreateOccurrence(ScheduleRecurrenceType recurenceType, DateTime currentDate, DateTime?endDate, long currentNumberOfOccurences, long?maxOccurrences)
        {
            if (recurenceType == ScheduleRecurrenceType.RecurrenceWithLimitedOccurrences)
            {
                if (maxOccurrences.HasValue == false)
                {
                    throw new ArgumentNullException("MaxOccurrences value is not provided. ScheduleRecurrenceType is RecurrenceWithLimitedOccurrences", "maxOccurrences");
                }

                return(currentNumberOfOccurences < maxOccurrences.Value);
            }
            else if (recurenceType == ScheduleRecurrenceType.RecurrenceWithLimitedPeriod || recurenceType == ScheduleRecurrenceType.RecurrenceWithoutEndSpecified)
            {
                if (endDate.HasValue == false)
                {
                    throw new ArgumentNullException("EndDate value is not provided. ScheduleRecurrenceType is RecurrenceWithLimitedPeriod or RecurrenceWithoutEndSpecified", "endDate");
                }

                return(currentDate <= endDate.Value);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// Function: Convert ScheduleRecurrenceType to PWRecurrenceInfo
        /// Author  : Jerry Xu
        /// Date    : 2008-12-6
        /// </summary>
        /// <param name="recurrence">PWRecurrenceInfo</param>
        /// <returns>ScheduleRecurrenceType</returns>
        private ScheduleRecurrenceType ConvertRecurrence(PWRecurrenceInfo recurrence)
        {
            ScheduleRecurrenceType item = new ScheduleRecurrenceType();

            //TODO:
            if (recurrence.Type == PWRecurrenceType.Daily)
            {
                item.DailyPattern = recurrence.Periodicity;
            }
            if (recurrence.Type == PWRecurrenceType.Weekly)
            {
                item.WeeklyPattern = ConvertWeeklyPattern(recurrence);
            }
            if (recurrence.Range == PWRecurrenceRange.NoEndDate)
            {
                item.NoEndDateRange = true;
            }
            if (recurrence.Range == PWRecurrenceRange.EndByDate)
            {
                item.EndByDateRange = recurrence.End.ToString("yyyy-MM-dd");
            }
            if (recurrence.Range == PWRecurrenceRange.OccurrenceCount)
            {
                item.EndAfterByOccurenceRange = recurrence.OccurrenceCount;
            }

            //item.Pattern = null;
            //item.Range = recurrence.Range;

            return(item);
        }