Example #1
0
        private RecurrencePattern CreateYearlyRecurrence(Recurrence icalRecurrence, ExDateTime start, bool isLeapMonth, CalendarType calendarType)
        {
            RecurrencePattern result = null;

            if (icalRecurrence.ByDayList == null && icalRecurrence.BySetPosition == null)
            {
                int dayOfMonth = (icalRecurrence.ByMonthDay != null) ? icalRecurrence.ByMonthDay[0] : start.Day;
                int month      = (icalRecurrence.ByMonth != null) ? icalRecurrence.ByMonth[0] : start.Month;
                result = new YearlyRecurrencePattern(dayOfMonth, month, isLeapMonth, icalRecurrence.Interval, calendarType);
            }
            else if (icalRecurrence.ByDayList != null && icalRecurrence.ByMonthDay == null)
            {
                int                 month2              = (icalRecurrence.ByMonth != null) ? icalRecurrence.ByMonth[0] : start.Month;
                DaysOfWeek          daysOfWeek          = VItemBase.DaysOfWeekFromByDayList(icalRecurrence.ByDayList, start);
                RecurrenceOrderType?recurrenceOrderType = null;
                int                 occurrenceNumber    = icalRecurrence.ByDayList[0].OccurrenceNumber;
                if (occurrenceNumber == 0 && icalRecurrence.BySetPosition != null)
                {
                    recurrenceOrderType = new RecurrenceOrderType?((RecurrenceOrderType)icalRecurrence.BySetPosition[0]);
                }
                else if (occurrenceNumber != 0 && icalRecurrence.BySetPosition == null)
                {
                    recurrenceOrderType = new RecurrenceOrderType?((RecurrenceOrderType)occurrenceNumber);
                }
                if (recurrenceOrderType != null)
                {
                    result = new YearlyThRecurrencePattern(daysOfWeek, recurrenceOrderType.Value, month2, isLeapMonth, icalRecurrence.Interval, calendarType);
                }
            }
            return(result);
        }
Example #2
0
        public override bool Equals(RecurrencePattern value, bool ignoreCalendarTypeAndIsLeapMonth)
        {
            if (!(value is YearlyThRecurrencePattern))
            {
                return(false);
            }
            YearlyThRecurrencePattern yearlyThRecurrencePattern = (YearlyThRecurrencePattern)value;

            return(yearlyThRecurrencePattern.DaysOfWeek == this.DaysOfWeek && yearlyThRecurrencePattern.Month == this.Month && yearlyThRecurrencePattern.Order == this.Order && (ignoreCalendarTypeAndIsLeapMonth || yearlyThRecurrencePattern.CalendarType == this.CalendarType) && (ignoreCalendarTypeAndIsLeapMonth || yearlyThRecurrencePattern.IsLeapMonth == this.IsLeapMonth));
        }
Example #3
0
		private void SetPatternSpecificProperties(RecurrencePattern pattern)
		{
			if (pattern is DailyRecurrencePattern)
			{
				DailyRecurrencePattern dailyRecurrencePattern = (DailyRecurrencePattern)pattern;
				this.Group = RecurrenceGroup.Daily;
				this.Type = RecurrenceTypeInBlob.Minute;
				this.Period = dailyRecurrencePattern.RecurrenceInterval * 24 * 60;
				return;
			}
			if (pattern is WeeklyRecurrencePattern)
			{
				WeeklyRecurrencePattern weeklyRecurrencePattern = (WeeklyRecurrencePattern)pattern;
				this.Group = RecurrenceGroup.Weekly;
				this.Type = RecurrenceTypeInBlob.Week;
				this.Period = weeklyRecurrencePattern.RecurrenceInterval;
				this.DayMask = weeklyRecurrencePattern.DaysOfWeek;
				this.FirstDayOfWeek = (int)((WeeklyRecurrencePattern)pattern).FirstDayOfWeek;
				return;
			}
			if (pattern is MonthlyRecurrencePattern)
			{
				MonthlyRecurrencePattern monthlyRecurrencePattern = (MonthlyRecurrencePattern)pattern;
				this.Group = RecurrenceGroup.Monthly;
				this.Type = ((monthlyRecurrencePattern.CalendarType == CalendarType.Hijri) ? RecurrenceTypeInBlob.HjMonth : RecurrenceTypeInBlob.Month);
				this.Period = monthlyRecurrencePattern.RecurrenceInterval;
				this.DayOfMonth = monthlyRecurrencePattern.DayOfMonth;
				return;
			}
			if (pattern is YearlyRecurrencePattern)
			{
				YearlyRecurrencePattern yearlyRecurrencePattern = (YearlyRecurrencePattern)pattern;
				this.Group = RecurrenceGroup.Yearly;
				this.Type = ((yearlyRecurrencePattern.CalendarType == CalendarType.Hijri) ? RecurrenceTypeInBlob.HjMonth : RecurrenceTypeInBlob.Month);
				this.DayOfMonth = yearlyRecurrencePattern.DayOfMonth;
				this.Period = 12;
				return;
			}
			if (pattern is MonthlyThRecurrencePattern)
			{
				MonthlyThRecurrencePattern monthlyThRecurrencePattern = (MonthlyThRecurrencePattern)pattern;
				this.Group = RecurrenceGroup.Monthly;
				this.Type = ((monthlyThRecurrencePattern.CalendarType == CalendarType.Hijri) ? RecurrenceTypeInBlob.HjMonthNth : RecurrenceTypeInBlob.MonthNth);
				this.DayMask = monthlyThRecurrencePattern.DaysOfWeek;
				this.NthOccurrence = monthlyThRecurrencePattern.Order;
				this.Period = monthlyThRecurrencePattern.RecurrenceInterval;
				return;
			}
			if (pattern is YearlyThRecurrencePattern)
			{
				YearlyThRecurrencePattern yearlyThRecurrencePattern = (YearlyThRecurrencePattern)pattern;
				this.Group = RecurrenceGroup.Yearly;
				this.Type = ((yearlyThRecurrencePattern.CalendarType == CalendarType.Hijri) ? RecurrenceTypeInBlob.HjMonthNth : RecurrenceTypeInBlob.MonthNth);
				this.DayMask = yearlyThRecurrencePattern.DaysOfWeek;
				this.NthOccurrence = yearlyThRecurrencePattern.Order;
				this.MonthOfYear = yearlyThRecurrencePattern.Month;
				this.Period = 12;
				return;
			}
			if (pattern is DailyRegeneratingPattern)
			{
				DailyRegeneratingPattern dailyRegeneratingPattern = (DailyRegeneratingPattern)pattern;
				this.Type = RecurrenceTypeInBlob.Minute;
				this.Group = RecurrenceGroup.Daily;
				this.Period = dailyRegeneratingPattern.RecurrenceInterval * 24 * 60;
				return;
			}
			if (pattern is WeeklyRegeneratingPattern)
			{
				WeeklyRegeneratingPattern weeklyRegeneratingPattern = (WeeklyRegeneratingPattern)pattern;
				this.Type = RecurrenceTypeInBlob.Minute;
				this.Group = RecurrenceGroup.Weekly;
				this.DayMask = DaysOfWeek.Monday;
				this.Period = weeklyRegeneratingPattern.RecurrenceInterval * 7 * 24 * 60;
				return;
			}
			if (pattern is MonthlyRegeneratingPattern)
			{
				MonthlyRegeneratingPattern monthlyRegeneratingPattern = (MonthlyRegeneratingPattern)pattern;
				this.Type = RecurrenceTypeInBlob.MonthNth;
				this.Group = RecurrenceGroup.Monthly;
				this.DayMask = DaysOfWeek.Monday;
				this.NthOccurrence = (RecurrenceOrderType)0;
				this.Period = monthlyRegeneratingPattern.RecurrenceInterval;
				return;
			}
			if (pattern is YearlyRegeneratingPattern)
			{
				YearlyRegeneratingPattern yearlyRegeneratingPattern = (YearlyRegeneratingPattern)pattern;
				this.Type = RecurrenceTypeInBlob.Month;
				this.Group = RecurrenceGroup.Yearly;
				this.DayOfMonth = 1;
				this.Period = 12 * yearlyRegeneratingPattern.RecurrenceInterval;
			}
		}
Example #4
0
        protected Recurrence ICalRecurrenceFromXsoRecurrence(Recurrence xsoRecurrence)
        {
            Recurrence        recurrence = new Recurrence();
            RecurrencePattern pattern    = xsoRecurrence.Pattern;
            RecurrenceRange   range      = xsoRecurrence.Range;

            if (pattern is DailyRecurrencePattern)
            {
                recurrence.Frequency = Frequency.Daily;
            }
            else if (pattern is WeeklyRecurrencePattern)
            {
                recurrence.Frequency = Frequency.Weekly;
                WeeklyRecurrencePattern weeklyRecurrencePattern = (WeeklyRecurrencePattern)pattern;
                recurrence.ByDayList     = VItemBase.ByDayListFromDaysOfWeek(weeklyRecurrencePattern.DaysOfWeek);
                recurrence.WorkWeekStart = weeklyRecurrencePattern.FirstDayOfWeek;
            }
            else if (pattern is MonthlyRecurrencePattern)
            {
                recurrence.Frequency = Frequency.Monthly;
                MonthlyRecurrencePattern monthlyRecurrencePattern = (MonthlyRecurrencePattern)pattern;
                recurrence.ByMonthDay = new int[]
                {
                    monthlyRecurrencePattern.DayOfMonth
                };
            }
            else if (pattern is MonthlyThRecurrencePattern)
            {
                recurrence.Frequency = Frequency.Monthly;
                MonthlyThRecurrencePattern monthlyThRecurrencePattern = (MonthlyThRecurrencePattern)pattern;
                recurrence.ByDayList = VItemBase.ByDayListFromDaysOfWeek(monthlyThRecurrencePattern.DaysOfWeek);
                int order = (int)monthlyThRecurrencePattern.Order;
                if (recurrence.ByDayList.Length == 1)
                {
                    recurrence.ByDayList[0].OccurrenceNumber = order;
                }
                else
                {
                    recurrence.BySetPosition = new int[]
                    {
                        order
                    };
                }
            }
            else if (pattern is YearlyRecurrencePattern)
            {
                recurrence.Frequency = Frequency.Yearly;
                YearlyRecurrencePattern yearlyRecurrencePattern = (YearlyRecurrencePattern)pattern;
                recurrence.ByMonth = new int[]
                {
                    yearlyRecurrencePattern.Month
                };
                recurrence.ByMonthDay = new int[]
                {
                    yearlyRecurrencePattern.DayOfMonth
                };
            }
            else if (pattern is YearlyThRecurrencePattern)
            {
                recurrence.Frequency = Frequency.Yearly;
                YearlyThRecurrencePattern yearlyThRecurrencePattern = (YearlyThRecurrencePattern)pattern;
                recurrence.ByMonth = new int[]
                {
                    yearlyThRecurrencePattern.Month
                };
                recurrence.ByDayList = VItemBase.ByDayListFromDaysOfWeek(yearlyThRecurrencePattern.DaysOfWeek);
                int order2 = (int)yearlyThRecurrencePattern.Order;
                if (recurrence.ByDayList.Length == 1)
                {
                    recurrence.ByDayList[0].OccurrenceNumber = order2;
                }
                else
                {
                    recurrence.BySetPosition = new int[]
                    {
                        order2
                    };
                }
            }
            IntervalRecurrencePattern intervalRecurrencePattern = pattern as IntervalRecurrencePattern;

            if (intervalRecurrencePattern != null)
            {
                recurrence.Interval = intervalRecurrencePattern.RecurrenceInterval;
            }
            else
            {
                recurrence.Interval = 1;
            }
            if (range is EndDateRecurrenceRange)
            {
                EndDateRecurrenceRange endDateRecurrenceRange = (EndDateRecurrenceRange)range;
                recurrence.UntilDateTime = (DateTime)(endDateRecurrenceRange.EndDate + xsoRecurrence.StartOffset).ToUtc();
            }
            else if (range is NumberedRecurrenceRange)
            {
                NumberedRecurrenceRange numberedRecurrenceRange = (NumberedRecurrenceRange)range;
                recurrence.Count = numberedRecurrenceRange.NumberOfOccurrences;
            }
            return(recurrence);
        }