private void DailyTest1Validate(string calName, DateTime dateStart, DateTime rangeEnd) { Assert.True(Model.Appointments.Count == 1); Assert.True(Model.Appointments[0].OwnerKey.Equals(calName)); AppointmentRecurrence recur = Model.Appointments[0].Recurrence; Assert.NotNull(recur); Assert.True(recur.RecurrenceType == eRecurrencePatternType.Daily); Assert.True(recur.Daily.RepeatInterval == 1); Assert.True(recur.Daily.RepeatOnDaysOfWeek == eDailyRecurrenceRepeat.All); Assert.True(recur.RangeLimitType == eRecurrenceRangeLimitType.RangeNumberOfOccurrences); Assert.True(recur.RangeNumberOfOccurrences == 9); Assert.True(recur.RecurrenceStartDate == dateStart); AppointmentSubsetCollection appc = new AppointmentSubsetCollection(Model, dateStart, dateStart.AddDays(10)); Assert.True(appc.Count == 10); DateTime date = dateStart; for (int i = 0; i < appc.Count; i++) { Assert.True(appc[i].StartTime == date); date = date.AddDays(1); } }
private void VAlarmTestValidate(string calName, DateTime dateStart, DateTime rangeEnd) { Assert.True(Model.Appointments.Count == 1); Appointment app = Model.Appointments[0]; Assert.True(app.OwnerKey.Equals(calName)); Assert.Null(app.Recurrence); AppointmentSubsetCollection appc = new AppointmentSubsetCollection(Model, dateStart, dateStart.AddYears(1)); Assert.True(appc.Count == 1); Assert.True(app.StartTime == dateStart); Assert.NotNull(app.Reminders); if (app.Reminders != null) { Assert.True(app.Reminders.Count == 2); foreach (Reminder rem in app.Reminders) { switch (rem.Description) { case DescrBefore: Assert.True(rem.ReminderTime == dateStart.AddDays(-15).AddHours(-7).AddMinutes(-12)); break; case DescrAfter: Assert.True(rem.ReminderTime == dateStart.AddMinutes(1)); break; default: Assert.Fail("Invalid Reminder."); break; } } Assert.True(app.StartTimeAction == eStartTimeAction.StartTimeReachedEvent); } }
/// <summary> /// Generates Yearly recurring appointments. If appointment is assigned to calendar method must populate the Calendar.Appointments collection as well. /// </summary> /// <param name="subsetCollection">Collection to add generated recurrences to</param> /// <param name="recurrence">Recurrence description, must be of Monthly recurrence type.</param> /// <param name="startDate">Start date for generation.</param> /// <param name="endDate">End date for generation.</param> public void GenerateYearlyRecurrence(AppointmentSubsetCollection subsetCollection, AppointmentRecurrence recurrence, DateTime startDate, DateTime endDate) { Appointment app = recurrence.Appointment; DateTime recurrenceStartDate = DateTimeHelper.MaxDate(recurrence.RecurrenceStartDate, app.EndTime.AddDays(1).Date); if (recurrenceStartDate > endDate) return; if (!(startDate.Month <= recurrence.Yearly.RepeatOnMonth && endDate.Month >= recurrence.Yearly.RepeatOnMonth) && endDate.Subtract(startDate).TotalDays < 28) return; int totalRecurrences = 0; // Check the range first if (recurrence.RangeLimitType == eRecurrenceRangeLimitType.RangeEndDate) { if (startDate > recurrence.RangeEndDate) return; } else if (recurrence.RangeLimitType == eRecurrenceRangeLimitType.RangeNumberOfOccurrences && recurrence.RangeNumberOfOccurrences > 0 && recurrenceStartDate < startDate) { int count = recurrence.RangeNumberOfOccurrences + 1; DateTime testDate = DateTimeHelper.BeginningOfDay(recurrenceStartDate.AddDays(-(recurrenceStartDate.Day - 1))).AddMonths(-1); if (testDate < app.EndTime) testDate = app.EndTime.Date.AddDays(1); DateTime startDateOnly = DateTimeHelper.BeginningOfDay(startDate); while (count > 0 && testDate < startDateOnly) { testDate = GetNextYearlyRecurrence(recurrence, testDate); if (testDate >= startDateOnly) break; count--; totalRecurrences++; } if (count == 0) return; } DateTime currentDate = DateTimeHelper.MaxDate(startDate, recurrenceStartDate).AddDays(-1); if (recurrence.Yearly.RepeatInterval > 1) currentDate = recurrenceStartDate; do { currentDate = GetNextYearlyRecurrence(recurrence, currentDate); if (recurrence.RangeLimitType == eRecurrenceRangeLimitType.RangeEndDate && currentDate > recurrence.RangeEndDate || recurrence.RangeLimitType == eRecurrenceRangeLimitType.RangeNumberOfOccurrences && totalRecurrences >= recurrence.RangeNumberOfOccurrences) break; if (currentDate >= startDate && currentDate <= endDate && !IsIgnoredRecurrence(currentDate, recurrence)) { subsetCollection.Add(CreateRecurringAppointmentInstance(currentDate, app)); totalRecurrences++; } } while (currentDate <= endDate); }
private void MonthlyTest6Validate(string calName, DateTime dateStart, DateTime rangeEnd) { Assert.True(Model.Appointments.Count == 6); for (int i = 0; i < Model.Appointments.Count; i++) { Appointment app = Model.Appointments[i]; Assert.True(app.OwnerKey.Equals(calName)); AppointmentRecurrence recur = app.Recurrence; Assert.NotNull(recur); Assert.True(recur.RecurrenceType == eRecurrencePatternType.Monthly); Assert.True(recur.Monthly.RepeatInterval == 6); Assert.True(recur.Monthly.RepeatOnRelativeDayInMonth == eRelativeDayInMonth.None); Assert.True(recur.RangeLimitType == eRecurrenceRangeLimitType.RangeNumberOfOccurrences); Assert.True(recur.RangeNumberOfOccurrences == 4); Assert.True(recur.RecurrenceStartDate == app.StartTime); } AppointmentSubsetCollection appc = new AppointmentSubsetCollection(Model, dateStart, dateStart.AddYears(20)); Assert.True(appc.Count == 30); DateTime date = dateStart; for (int i = 0; i < appc.Count / 6; i++) { Assert.True(AppcContainsDate(appc, date) == true); Assert.True(AppcContainsDate(appc, date.AddDays(1)) == true); Assert.True(AppcContainsDate(appc, date.AddDays(2)) == true); Assert.True(AppcContainsDate(appc, date.AddDays(3)) == true); Assert.True(AppcContainsDate(appc, date.AddDays(4)) == true); Assert.True(AppcContainsDate(appc, date.AddDays(5)) == true); date = date.AddMonths(6); } }
internal void GenerateSubset(AppointmentSubsetCollection subsetCollection, DateTime startDate, DateTime endDate) { IRecurrenceGenerator generator = GetRecurrenceGenerator(); if (_RecurrenceType == eRecurrencePatternType.Daily) { generator.GenerateDailyRecurrence(subsetCollection, this, startDate, endDate); } else if (_RecurrenceType == eRecurrencePatternType.Weekly) { generator.GenerateWeeklyRecurrence(subsetCollection, this, startDate, endDate); } else if (_RecurrenceType == eRecurrencePatternType.Monthly) { generator.GenerateMonthlyRecurrence(subsetCollection, this, startDate, endDate); } else if (_RecurrenceType == eRecurrencePatternType.Yearly) { generator.GenerateYearlyRecurrence(subsetCollection, this, startDate, endDate); } }
/// <summary> /// Generates Daily recurring appointments. If appointment is assigned to calendar method must populate the Calendar.Appointments collection as well. /// </summary> /// <param name="subsetCollection">Collection to add generated recurrences to</param> /// <param name="recurrence">Recurrence description, must be of Daily recurrence type.</param> /// <param name="startDate">Start date for generation.</param> /// <param name="endDate">End date for generation.</param> public void GenerateDailyRecurrence(AppointmentSubsetCollection subsetCollection, AppointmentRecurrence recurrence, DateTime startDate, DateTime endDate) { Appointment app = recurrence.Appointment; int appointmentDaysDuration = (int)Math.Max(0, Math.Ceiling(app.EndTime.Date.Subtract(app.StartTime.Date).TotalDays)); DateTime recurrenceStartDate = DateTimeHelper.MaxDate(recurrence.RecurrenceStartDate, DateTimeHelper.IsBeginningOfDay(app.EndTime) ? app.EndTime : app.EndTime.AddDays(recurrence.Daily.RepeatInterval).Date); if (recurrenceStartDate > endDate) return; int repeats = 0; // Check the range first if (recurrence.RangeLimitType == eRecurrenceRangeLimitType.RangeEndDate) { if (startDate > recurrence.RangeEndDate) return; } else if (recurrence.RangeLimitType == eRecurrenceRangeLimitType.RangeNumberOfOccurrences) { DateTime rangeStartDate = DateTimeHelper.MaxDate(recurrence.RecurrenceStartDate, DateTimeHelper.IsBeginningOfDay(app.LocalEndTime) ? app.LocalEndTime : app.LocalEndTime.AddDays(recurrence.Daily.RepeatInterval).Date); int totalDays = (int)Math.Ceiling(startDate.Subtract(rangeStartDate).TotalDays); switch (recurrence.Daily.RepeatOnDaysOfWeek) { case eDailyRecurrenceRepeat.All: repeats = Math.Max(0, totalDays / (recurrence.Daily.RepeatInterval + appointmentDaysDuration)); if (repeats >= recurrence.RangeNumberOfOccurrences) return; break; case eDailyRecurrenceRepeat.WeekDays: repeats = Math.Max(0, DateTimeHelper.TotalWeekDays(recurrenceStartDate, startDate) / (recurrence.Daily.RepeatInterval + appointmentDaysDuration)); // Assume weekdays repeat if (repeats > recurrence.RangeNumberOfOccurrences) return; break; default: repeats = Math.Max(0, DateTimeHelper.TotalWeekDays(recurrenceStartDate, startDate)); repeats = Math.Max(0, totalDays - repeats); // Assume weekend days repeat if (repeats > recurrence.RangeNumberOfOccurrences) return; break; } //repeats = 0; } DateTime currentDay = recurrenceStartDate; // DateTimeHelper.MaxDate(startDate, recurrenceStartDate); while (currentDay <= endDate) { if (currentDay >= startDate || currentDay < startDate && IsRecurringOnDay(currentDay, startDate, endDate, app)) { if (!IsRecurringOnDay(currentDay, startDate, endDate, app)) break; if (recurrence.Daily.RepeatOnDaysOfWeek == eDailyRecurrenceRepeat.All || (recurrence.Daily.RepeatOnDaysOfWeek == eDailyRecurrenceRepeat.WeekDays && !DateTimeHelper.IsWeekendDay(currentDay)) || (recurrence.Daily.RepeatOnDaysOfWeek == eDailyRecurrenceRepeat.WeekendDays && DateTimeHelper.IsWeekendDay(currentDay))) { if (!IsIgnoredRecurrence(currentDay, recurrence)) { subsetCollection.Add(CreateRecurringAppointmentInstance(currentDay, app)); repeats++; } } } switch (recurrence.Daily.RepeatOnDaysOfWeek) { case eDailyRecurrenceRepeat.All: currentDay = currentDay.AddDays(recurrence.Daily.RepeatInterval + appointmentDaysDuration); break; case eDailyRecurrenceRepeat.WeekDays: //currentDay = currentDay.AddDays(currentDay.DayOfWeek == DayOfWeek.Saturday ? 2 : Math.Max(1, recurrence.Daily.RepeatInterval + appointmentDaysDuration)); currentDay = currentDay.AddDays(Math.Max(1, recurrence.Daily.RepeatInterval + appointmentDaysDuration)); // Changed for consistency break; case eDailyRecurrenceRepeat.WeekendDays: while (true) { currentDay = currentDay.AddDays(1); if (DateTimeHelper.IsWeekendDay(currentDay) == true) break; } break; } if (recurrence.RangeLimitType == eRecurrenceRangeLimitType.RangeEndDate && currentDay > recurrence.RangeEndDate || recurrence.RangeLimitType == eRecurrenceRangeLimitType.RangeNumberOfOccurrences && repeats >= recurrence.RangeNumberOfOccurrences) break; } }
private void DailyTest3Validate(string calName, DateTime dateStart, DateTime rangeEnd) { Assert.True(Model.Appointments.Count == 1); Assert.True(Model.Appointments[0].OwnerKey.Equals(calName)); AppointmentRecurrence recur = Model.Appointments[0].Recurrence; Assert.NotNull(recur); Assert.True(recur.RecurrenceType == eRecurrencePatternType.Daily); Assert.True(recur.Daily.RepeatInterval == 1); Assert.True(recur.Daily.RepeatOnDaysOfWeek == eDailyRecurrenceRepeat.WeekendDays); Assert.True(recur.RangeLimitType == eRecurrenceRangeLimitType.RangeNumberOfOccurrences); Assert.True(recur.RangeNumberOfOccurrences == 3); Assert.True(recur.RecurrenceStartDate == dateStart); AppointmentSubsetCollection appc = new AppointmentSubsetCollection(Model, dateStart, dateStart.AddYears(1)); Assert.True(appc.Count == 4); DateTime date = dateStart; Assert.True(appc[0].StartTime == date); Assert.True(appc[1].StartTime == date.AddDays(1)); Assert.True(appc[2].StartTime == date.AddDays(7)); Assert.True(appc[3].StartTime == date.AddDays(8)); }
private void MonthlyTest2Validate(string calName, DateTime dateStart, DateTime rangeEnd) { Assert.True(Model.Appointments.Count == 1); Assert.True(Model.Appointments[0].OwnerKey.Equals(calName)); AppointmentRecurrence recur = Model.Appointments[0].Recurrence; Assert.NotNull(recur); Assert.True(recur.RecurrenceType == eRecurrencePatternType.Monthly); Assert.True(recur.Monthly.RepeatInterval == 1); Assert.True(recur.Monthly.RepeatOnRelativeDayInMonth == eRelativeDayInMonth.Third); Assert.True(recur.RangeLimitType == eRecurrenceRangeLimitType.RangeEndDate); Assert.True(recur.RangeNumberOfOccurrences == 0); Assert.True(recur.RecurrenceStartDate == dateStart); AppointmentSubsetCollection appc = new AppointmentSubsetCollection(Model, dateStart, dateStart.AddYears(1)); Assert.True(appc.Count == 3); DateTime date = dateStart; for (int i = 0; i < appc.Count; i++) { Assert.True(appc[i].StartTime == date); date = GetNextRelativeDate(date, date.DayOfWeek, 3); } }
private void YearlyTest5Validate(string calName, DateTime dateStart, DateTime rangeEnd) { Assert.True(Model.Appointments.Count == 6); Assert.True(Model.Appointments[0].OwnerKey.Equals(calName)); AppointmentRecurrence recur = Model.Appointments[0].Recurrence; Assert.NotNull(recur); Assert.True(recur.RecurrenceType == eRecurrencePatternType.Yearly); Assert.True(recur.Monthly.RepeatInterval == 1); Assert.True(recur.Monthly.RepeatOnRelativeDayInMonth == eRelativeDayInMonth.None); Assert.True(recur.RangeLimitType == eRecurrenceRangeLimitType.RangeNumberOfOccurrences); Assert.True(recur.RangeNumberOfOccurrences == 9); Assert.True(recur.RecurrenceStartDate == Model.Appointments[0].StartTime); AppointmentSubsetCollection appc = new AppointmentSubsetCollection(Model, dateStart, dateStart.AddYears(30)); Assert.True(appc.Count == 60); DateTime date = dateStart; for (int i = 0; i < appc.Count / 3; i += 3) { DateTime date1 = date; DateTime date2 = date.AddMonths(1); DateTime date5 = date.AddMonths(4); Assert.True(AppcContainsDate(appc, date1)); Assert.True(AppcContainsDate(appc, date2)); Assert.True(AppcContainsDate(appc, date5)); date1 = date1.AddDays(8); date2 = date2.AddDays(8); date5 = date5.AddDays(8); Assert.True(AppcContainsDate(appc, date1)); Assert.True(AppcContainsDate(appc, date2)); Assert.True(AppcContainsDate(appc, date5)); date = date.AddYears(1); } }
private void DurationTestValidate(string calName, DateTime dateStart, DateTime rangeEnd) { Assert.True(Model.Appointments.Count == 8); AppointmentSubsetCollection appc = new AppointmentSubsetCollection(Model, dateStart, dateStart.AddYears(1)); Assert.True(appc.Count == 8); for (int i = 0; i < appc.Count; i++) { Appointment app = appc[i]; Assert.Null(app.Recurrence); Assert.True(app.OwnerKey.Equals(calName)); int actMinutes = 0; int appMinutes = (int)(app.EndTime - app.StartTime).TotalMinutes; switch (app.StartTime.Day) { case 1: actMinutes = 60 * 48; break; case 2: actMinutes = 60 * 76; break; case 3: actMinutes = 60 * 27 + 45; break; case 4: actMinutes = 60 * 96 + 15; break; case 5: actMinutes = 60 * 4; break; case 6: actMinutes = 60 * 2 + 15; break; case 7: actMinutes = 12; break; case 8: actMinutes = 7; break; default: Assert.True(false, "Invalid duration date."); break; } Assert.True(appMinutes == actMinutes, "Incorrect duration."); } }
private void YearlyTest4Validate(string calName, DateTime dateStart, DateTime rangeEnd) { Assert.True(Model.Appointments.Count == 3); Assert.True(Model.Appointments[0].OwnerKey.Equals(calName)); AppointmentRecurrence recur = Model.Appointments[0].Recurrence; Assert.NotNull(recur); Assert.True(recur.RecurrenceType == eRecurrencePatternType.Yearly); Assert.True(recur.Monthly.RepeatInterval == 1); Assert.True(recur.Monthly.RepeatOnRelativeDayInMonth == eRelativeDayInMonth.None); Assert.True(recur.RangeLimitType == eRecurrenceRangeLimitType.NoEndDate); Assert.True(recur.RangeNumberOfOccurrences == 0); Assert.True(recur.RecurrenceStartDate == Model.Appointments[0].StartTime); AppointmentSubsetCollection appc = new AppointmentSubsetCollection(Model, dateStart, dateStart.AddYears(30)); Assert.True(appc.Count == 33); DateTime date = dateStart; for (int i = 0; i < appc.Count - 2; i++) { Assert.True(AppcContainsDate(appc, date)); date = date.AddYears(1); } date = new DateTime(2010, 9, 20, 10, 0, 0); Appointment app = AppcGetApp(appc, date); Assert.NotNull(app); if (app != null) Assert.True((app.EndTime - app.StartTime).TotalMinutes == 4 * 60); date = new DateTime(2010, 9, 22, 12, 0, 0); app = AppcGetApp(appc, date); Assert.NotNull(app); if (app != null) Assert.True((app.EndTime - app.StartTime).TotalMinutes == 3 * 60 + 45); }
private void YearlyTest1Validate(string calName, DateTime dateStart, DateTime rangeEnd) { Assert.True(Model.Appointments.Count == 1); Assert.True(Model.Appointments[0].OwnerKey.Equals(calName)); AppointmentRecurrence recur = Model.Appointments[0].Recurrence; Assert.NotNull(recur); Assert.True(recur.RecurrenceType == eRecurrencePatternType.Yearly); Assert.True(recur.Monthly.RepeatInterval == 1); Assert.True(recur.Monthly.RepeatOnRelativeDayInMonth == eRelativeDayInMonth.None); Assert.True(recur.RangeLimitType == eRecurrenceRangeLimitType.RangeNumberOfOccurrences); Assert.True(recur.RangeNumberOfOccurrences == 1); Assert.True(recur.RecurrenceStartDate == Model.Appointments[0].StartTime); DateTime dt1 = new DateTime(2009, 7, 1); AppointmentSubsetCollection appc = new AppointmentSubsetCollection(Model, dt1, dt1.AddYears(1)); Assert.True(appc.Count == 1); dt1 = dt1.AddYears(1); appc = new AppointmentSubsetCollection(Model, dt1, dt1.AddYears(1)); Assert.True(appc.Count == 1); appc = new AppointmentSubsetCollection(Model, dateStart, dateStart.AddYears(30)); Assert.True(appc.Count == 2); DateTime date = dateStart; for (int i = 0; i < appc.Count; i++) { Assert.True(AppcContainsDate(appc, date)); date = date.AddYears(1); } }
private void MonthlyTest7Validate(string calName, DateTime dateStart, DateTime rangeEnd) { Assert.True(Model.Appointments.Count == 3); for (int i = 0; i < Model.Appointments.Count; i++) { Appointment app = Model.Appointments[i]; Assert.True(app.OwnerKey.Equals(calName)); AppointmentRecurrence recur = app.Recurrence; Assert.NotNull(recur); Assert.True(recur.RecurrenceType == eRecurrencePatternType.Monthly); Assert.True(recur.Monthly.RepeatInterval == 2); Assert.True(recur.Monthly.RepeatOnRelativeDayInMonth == eRelativeDayInMonth.None); Assert.True(recur.RangeLimitType == eRecurrenceRangeLimitType.NoEndDate); Assert.True(recur.RangeNumberOfOccurrences == 0); Assert.True(recur.RecurrenceStartDate == app.StartTime); } AppointmentSubsetCollection appc = new AppointmentSubsetCollection(Model, dateStart, dateStart.AddYears(1)); Assert.True(appc.Count == 19); DateTime date = dateStart; for (int i = 0; i < appc.Count; i++) { Assert.True(AppcContainsDate(appc, date) == true); switch (date.Day) { case 1: date = date.AddDays(14); break; case 15: date = date.AddDays(5); break; default: for (int j = 0; j < 2; j++) date = date.AddMonths(1); date = date.AddDays(-date.Day + 1); break; } } }
private void WeeklyTest5Validate(string calName, DateTime dateStart, DateTime rangeEnd) { Assert.True(Model.Appointments.Count == 1); Assert.True(Model.Appointments[0].OwnerKey.Equals(calName)); AppointmentRecurrence recur = Model.Appointments[0].Recurrence; Assert.NotNull(recur); Assert.True(recur.RecurrenceType == eRecurrencePatternType.Weekly); Assert.True(recur.Weekly.RepeatInterval == 2); Assert.True(recur.Weekly.RepeatOnDaysOfWeek == (eDayOfWeekRecurrence.Monday | eDayOfWeekRecurrence.Wednesday | eDayOfWeekRecurrence.Friday)); Assert.True(recur.RangeLimitType == eRecurrenceRangeLimitType.RangeEndDate); Assert.True(recur.RangeNumberOfOccurrences == 0); Assert.True(recur.RecurrenceStartDate == dateStart); AppointmentSubsetCollection appc = new AppointmentSubsetCollection(Model, dateStart, dateStart.AddYears(1)); Assert.True(appc.Count == 12); DateTime date = dateStart; for (int i = 0; i < appc.Count; i += 3) { Assert.True(appc[i].StartTime == date); date = date.AddDays(2); Assert.True(appc[i + 1].StartTime == date); date = date.AddDays(2); Assert.True(appc[i + 2].StartTime == date); date = date.AddDays(10); } }
private void ExDateTestValidate(string calName, DateTime dateStart, DateTime rangeEnd) { Assert.True(Model.Appointments.Count == 1); Assert.True(Model.Appointments[0].OwnerKey.Equals(calName)); AppointmentRecurrence recur = Model.Appointments[0].Recurrence; Assert.NotNull(recur); Assert.True(recur.RecurrenceType == eRecurrencePatternType.Daily); Assert.True(recur.Daily.RepeatInterval == 1); Assert.True(recur.Daily.RepeatOnDaysOfWeek == eDailyRecurrenceRepeat.All); Assert.True(recur.RangeLimitType == eRecurrenceRangeLimitType.RangeNumberOfOccurrences); Assert.True(recur.RangeNumberOfOccurrences == 29); Assert.True(recur.RecurrenceStartDate == dateStart); AppointmentSubsetCollection appc = new AppointmentSubsetCollection(Model, dateStart, dateStart.AddYears(1)); Assert.True(appc.Count == 30); DateTime date = dateStart; for (int i = 0; i < appc.Count; i++) { if (date.Month == 7) { if (date.Day == 2 || date.Day == 16) { Assert.True(AppcContainsDate(appc, date) == false); i--; } } else { Assert.True(AppcContainsDate(appc, date) == true); } date = date.AddDays(1); } }
private void WeeklyTest6Validate(string calName, DateTime dateStart, DateTime rangeEnd) { Assert.True(Model.Appointments.Count == 1); Assert.True(Model.Appointments[0].OwnerKey.Equals(calName)); AppointmentRecurrence recur = Model.Appointments[0].Recurrence; Assert.NotNull(recur); Assert.True(recur.RecurrenceType == eRecurrencePatternType.Weekly); Assert.True(recur.Weekly.RepeatInterval == 1); Assert.True(recur.Weekly.RepeatOnDaysOfWeek == eDayOfWeekRecurrence.Tuesday); Assert.True(recur.RangeLimitType == eRecurrenceRangeLimitType.NoEndDate); Assert.True(recur.RangeNumberOfOccurrences == 0); Assert.True(recur.RecurrenceStartDate == dateStart); AppointmentSubsetCollection appc = new AppointmentSubsetCollection(Model, dateStart, dateStart.AddYears(1)); Assert.True(appc.Count == 53); DateTime date = dateStart; for (int i = 0; i < appc.Count; i++) { Assert.True(appc[i].StartTime == date); Assert.True(appc[i].StartTime.DayOfWeek == DayOfWeek.Tuesday); Assert.True((appc[i].EndTime - appc[i].StartTime).TotalDays == 3); date = date.AddDays(7); } }
private void XdnbTestValidate(string calName, DateTime dateStart, DateTime rangeEnd) { Assert.True(Model.Appointments.Count == 1); Assert.True(Model.Appointments[0].OwnerKey.Equals(calName)); AppointmentRecurrence recur = Model.Appointments[0].Recurrence; Assert.NotNull(recur); Assert.True(recur.RecurrenceType == eRecurrencePatternType.Daily); Assert.True(recur.Daily.RepeatInterval == 1); Assert.True(recur.Daily.RepeatOnDaysOfWeek == eDailyRecurrenceRepeat.All); Assert.True(recur.RangeLimitType == eRecurrenceRangeLimitType.RangeNumberOfOccurrences); Assert.True(recur.RangeNumberOfOccurrences == 9); Assert.True(recur.RecurrenceStartDate == dateStart); AppointmentSubsetCollection appc = new AppointmentSubsetCollection(Model, dateStart, dateStart.AddYears(1)); Assert.True(appc.Count == 10); DateTime date = dateStart; for (int i = 0; i < appc.Count; i++) { Appointment app = appc[i]; Assert.True(app.CategoryColor.Equals(Appointment.CategoryPurple), "Incorrect CategoryColor."); Assert.True(app.DisplayTemplate.Equals("<font color=\"Blue\">[StartTime] - [EndTime]</font><br />"), "Incorrect DisplayTemplate."); Assert.True(app.ImageAlign == eImageContentAlignment.MiddleRight, "Incorrect ImageAlign."); Assert.True(app.ImageKey.Equals("OpenFolder"), "Incorrect ImageKey."); Assert.True(app.Locked, "Incorrect Locked value."); Assert.True(app.TimeMarkedAs.Equals(Appointment.TimerMarkerOutOfOffice), "Incorrect TimeMarkedAs."); Assert.True(app.Tooltip.Equals("MyToolTip is, of course, the best tooltip!"), "Incorrect Tooltip."); Assert.True(AppcContainsDate(appc, date), "Invalid Date."); date = date.AddDays(1); } }
private void MonthlyTest3Validate(string calName, DateTime dateStart, DateTime rangeEnd) { Assert.True(Model.Appointments.Count == 2); for (int i = 0; i < Model.Appointments.Count; i++) { Appointment app = Model.Appointments[i]; Assert.True(app.OwnerKey.Equals(calName)); AppointmentRecurrence recur = app.Recurrence; Assert.NotNull(recur); Assert.True(recur.RecurrenceType == eRecurrencePatternType.Monthly); Assert.True(recur.Monthly.RepeatInterval == 2); Assert.True(recur.Monthly.RepeatOnRelativeDayInMonth != eRelativeDayInMonth.None); Assert.True(recur.RangeLimitType == eRecurrenceRangeLimitType.RangeNumberOfOccurrences); Assert.True(recur.RangeNumberOfOccurrences == 9); Assert.True(recur.RecurrenceStartDate == app.StartTime); } AppointmentSubsetCollection appc = new AppointmentSubsetCollection(Model, dateStart, dateStart.AddYears(2)); Assert.True(appc.Count == 20); DateTime date = GetNextLastDate(dateStart.AddMonths(-1), DayOfWeek.Saturday); for (int i = 0; i < appc.Count / 2; i++) { Assert.True(AppcContainsDate(appc, date) == true); for (int j = 0; j < 2; j++) date = GetNextLastDate(date, date.DayOfWeek); } date = dateStart; for (int i = 0; i < appc.Count / 2; i++) { Assert.True(AppcContainsDate(appc, date) == true); for (int j = 0; j < 2; j++) date = GetNextRelativeDate(date, date.DayOfWeek, 2); } }
private void RecIdTestValidate(string calName, DateTime dateStart, DateTime rangeEnd) { Assert.True(Model.Appointments.Count == 2); Assert.True(Model.Appointments[0].OwnerKey.Equals(calName)); AppointmentRecurrence recur = Model.Appointments[0].Recurrence; Assert.NotNull(recur); Assert.True(recur.RecurrenceType == eRecurrencePatternType.Monthly); Assert.True(recur.Monthly.RepeatInterval == 1); Assert.True(recur.Monthly.RepeatOnDayOfMonth == 15); Assert.True(recur.Monthly.RepeatOnRelativeDayInMonth == eRelativeDayInMonth.None); Assert.True(recur.RangeLimitType == eRecurrenceRangeLimitType.RangeNumberOfOccurrences); Assert.True(recur.RangeNumberOfOccurrences == 9); Assert.True(recur.RecurrenceStartDate == dateStart); AppointmentSubsetCollection appc = new AppointmentSubsetCollection(Model, dateStart, dateStart.AddYears(1)); Assert.True(appc.Count == 11); DateTime date = dateStart; for (int i = 0; i < appc.Count; i++) { if (date.Month == 6) { DateTime dateRecId = new DateTime(2010, 06, 15, 15, 30, 0); Appointment app = AppcGetApp(appc, dateRecId); Assert.True(app != null, "Incorrect RecurrenceId date."); if (app != null) Assert.True((app.EndTime - app.StartTime).TotalMinutes == 285, "Incorrect RecurrenceId duration."); } else { Appointment app = AppcGetApp(appc, date); Assert.True(app != null, "Invalid Date."); if (app != null) Assert.True((app.EndTime - app.StartTime).TotalMinutes == 180, "Incorrect normal duration."); } date = date.AddMonths(1); } }
/// <summary> /// Generates Weekly recurring appointments. If appointment is assigned to calendar method must populate the Calendar.Appointments collection as well. /// </summary> /// <param name="subsetCollection">Collection to add generated recurrences to</param> /// <param name="recurrence">Recurrence description, must be of Weekly recurrence type.</param> /// <param name="startDate">Start date for generation.</param> /// <param name="endDate">End date for generation.</param> public void GenerateWeeklyRecurrence(AppointmentSubsetCollection subsetCollection, AppointmentRecurrence recurrence, DateTime startDate, DateTime endDate) { Appointment app = recurrence.Appointment; DateTime baseStartDate = app.EndTime.Date; if (app.EndTime.Date > app.StartTime.Date && app.EndTime.TimeOfDay > app.StartTime.TimeOfDay && baseStartDate != DateTime.MinValue) baseStartDate = baseStartDate.AddDays(1); DateTime recurrenceStartDate = baseStartDate; int repeatInterval = recurrence.Weekly.RepeatInterval; if (RepeatsOnSingleDayOnly(recurrence.Weekly.RepeatOnDaysOfWeek) && !(app.StartTime.Date == startDate.Date && endDate.Date == startDate.Date)) recurrenceStartDate = baseStartDate.AddMilliseconds(-1).AddDays((repeatInterval) * 7 /*+ (recurrence.Weekly.RepeatInterval > 1 ? (8 - (int)baseStartDate.DayOfWeek) : 1)*/).Date; else { if (app.EndTime.Date > app.StartTime.Date && app.EndTime.TimeOfDay < app.StartTime.TimeOfDay) recurrenceStartDate = app.StartTime.Date.AddDays(1); else recurrenceStartDate = app.EndTime.Date.AddDays(1); } recurrenceStartDate = DateTimeHelper.MaxDate(recurrence.RecurrenceStartDate, recurrenceStartDate); if (recurrenceStartDate > endDate) return; int totalRecurrences = 0; // Check the range first if (recurrence.RangeLimitType == eRecurrenceRangeLimitType.RangeEndDate) { if (startDate > recurrence.RangeEndDate) return; } else if (recurrence.RangeLimitType == eRecurrenceRangeLimitType.RangeNumberOfOccurrences && repeatInterval == 1) { int totalDays = (int)Math.Ceiling(endDate.Subtract(recurrenceStartDate).TotalDays); int occurrencesPerWeek = GetNumberOfDays(recurrence.Weekly.RepeatOnDaysOfWeek); if (occurrencesPerWeek == 0) throw new ArgumentException("Weekly recurrence must have at least single day selected using RepeatOnDaysOfWeek property."); totalRecurrences = DateTimeHelper.TotalNumberOfDays(recurrenceStartDate, endDate, recurrence.Weekly.RepeatOnDaysOfWeek); if (totalRecurrences > recurrence.RangeNumberOfOccurrences) return; } bool countTotalRecurrences = false; if (repeatInterval > 1 && recurrence.RangeLimitType == eRecurrenceRangeLimitType.RangeNumberOfOccurrences) countTotalRecurrences = true; DateTime currentDay = recurrenceStartDate;// DateTimeHelper.MaxDate(recurrenceStartDate, startDate); while (currentDay <= endDate) { if (currentDay >= startDate && DateTimeHelper.HasDay(currentDay.DayOfWeek, recurrence.Weekly.RepeatOnDaysOfWeek) && !IsIgnoredRecurrence(currentDay, recurrence)) { subsetCollection.Add(CreateRecurringAppointmentInstance(currentDay, app)); totalRecurrences++; } else if (countTotalRecurrences && currentDay < startDate && DateTimeHelper.HasDay(currentDay.DayOfWeek, recurrence.Weekly.RepeatOnDaysOfWeek) && !IsIgnoredRecurrence(currentDay, recurrence)) { totalRecurrences++; if (totalRecurrences >= recurrence.RangeNumberOfOccurrences) return; } if (currentDay.DayOfWeek != DayOfWeek.Sunday) { while (currentDay.DayOfWeek != DayOfWeek.Sunday) { currentDay = currentDay.AddDays(1); if (currentDay > endDate || recurrence.RangeLimitType == eRecurrenceRangeLimitType.RangeEndDate && currentDay > recurrence.RangeEndDate) break; if (currentDay >= startDate && DateTimeHelper.HasDay(currentDay.DayOfWeek, recurrence.Weekly.RepeatOnDaysOfWeek) && !IsIgnoredRecurrence(currentDay, recurrence)) { subsetCollection.Add(CreateRecurringAppointmentInstance(currentDay, app)); } else if (countTotalRecurrences && currentDay < startDate && DateTimeHelper.HasDay(currentDay.DayOfWeek, recurrence.Weekly.RepeatOnDaysOfWeek) && !IsIgnoredRecurrence(currentDay, recurrence)) { totalRecurrences++; if (totalRecurrences >= recurrence.RangeNumberOfOccurrences) return; } } } currentDay = currentDay.AddDays(1 + (repeatInterval - 1) * 7); if (recurrence.RangeLimitType == eRecurrenceRangeLimitType.RangeEndDate && currentDay > recurrence.RangeEndDate || recurrence.RangeLimitType == eRecurrenceRangeLimitType.RangeNumberOfOccurrences && totalRecurrences > recurrence.RangeNumberOfOccurrences) break; } }
private void LongValueTestValidate(string calName, DateTime dateStart, DateTime rangeEnd) { Assert.True(Model.Appointments.Count == 1); Appointment app = Model.Appointments[0]; Assert.True(app.OwnerKey.Equals(calName)); Assert.Null(app.Recurrence); string metaDesc = AddMetaData(app.Description); Assert.True(metaDesc.Equals(_Description), "Incorrect description"); AppointmentSubsetCollection appc = new AppointmentSubsetCollection(Model, dateStart, dateStart.AddYears(1)); Assert.True(appc.Count == 1); }
/// <summary> /// Generates Monthly recurring appointments. If appointment is assigned to calendar method must populate the Calendar.Appointments collection as well. /// </summary> /// <param name="subsetCollection">Collection to add generated recurrences to</param> /// <param name="recurrence">Recurrence description, must be of Monthly recurrence type.</param> /// <param name="startDate">Start date for generation.</param> /// <param name="endDate">End date for generation.</param> public void GenerateMonthlyRecurrence(AppointmentSubsetCollection subsetCollection, AppointmentRecurrence recurrence, DateTime startDate, DateTime endDate) { Appointment app = recurrence.Appointment; DateTime recurrenceStartDate = DateTimeHelper.MaxDate(recurrence.RecurrenceStartDate, app.EndTime/*.AddDays(1).Date*/); if (recurrenceStartDate > endDate) return; int totalRecurrences = 0; // Check the range first if (recurrence.RangeLimitType == eRecurrenceRangeLimitType.RangeEndDate) { if (startDate > recurrence.RangeEndDate) return; } else if (recurrence.RangeLimitType == eRecurrenceRangeLimitType.RangeNumberOfOccurrences && recurrence.RangeNumberOfOccurrences > 0) { int count = recurrence.RangeNumberOfOccurrences + 1; DateTime testDate = DateTimeHelper.BeginningOfDay(recurrenceStartDate); DateTime startDateOnly = DateTimeHelper.BeginningOfDay(startDate); while (count > 0 && testDate < startDateOnly) { int repeatInterval = recurrence.Monthly.RepeatInterval; while (repeatInterval > 0) { testDate = GetNextMonthlyRecurrence(recurrence, testDate); repeatInterval--; } if (testDate < startDate) totalRecurrences++; count--; } if (count == 0) return; } DateTime currentDate = recurrenceStartDate;// DateTimeHelper.MaxDate(recurrenceStartDate, startDate).AddMonths(-1); do { int repeatCount = recurrence.Monthly.RepeatInterval; do { repeatCount--; currentDate = GetNextMonthlyRecurrence(recurrence, currentDate); } while (repeatCount > 0); if (recurrence.RangeLimitType == eRecurrenceRangeLimitType.RangeEndDate && currentDate > recurrence.RangeEndDate || recurrence.RangeLimitType == eRecurrenceRangeLimitType.RangeNumberOfOccurrences && totalRecurrences >= recurrence.RangeNumberOfOccurrences) break; if (currentDate >= startDate && currentDate <= endDate && !IsIgnoredRecurrence(currentDate, recurrence)) { subsetCollection.Add(CreateRecurringAppointmentInstance(currentDate, app)); totalRecurrences++; } } while (currentDate <= endDate); }
private void VTimeZoneValidate(string calName, DateTime dateStart, DateTime rangeEnd) { Assert.True(Model.Appointments.Count == 1); Appointment app = Model.Appointments[0]; Assert.True(app.OwnerKey.Equals(calName)); Assert.Null(app.Recurrence); AppointmentSubsetCollection appc = new AppointmentSubsetCollection(Model, dateStart.AddDays(-1), dateStart.AddYears(1)); Assert.True(appc.Count == 1); Assert.True(app.StartTime == dateStart.AddHours(-7)); }
/// <summary> /// Loads the TimeLine appointment data /// </summary> /// <param name="reload"></param> private bool LoadLineData(bool reload) { if (reload == true || _lineStartTime != _View.StartDate || _lineEndTime != _View.EndDate) { _lineStartTime = _View.StartDate; _lineEndTime = _View.EndDate; _lineAppts = new AppointmentSubsetCollection(_Model, _lineStartTime, _lineEndTime); _lineState = _lineState ^ 1; } if (_ViewState != _lineState) { _ViewState = _lineState; _View.ModelReloaded = true; reload = true; } return (reload); }
/// <summary> /// Loads Model/YearView connection data /// </summary> private void LoadData(bool reload) { if (reload == true || _lineStartTime != _View.StartDate || _lineEndTime != _View.EndDate) { _lineStartTime = _View.StartDate; _lineEndTime = _View.EndDate; _lineAppts = new AppointmentSubsetCollection(_Model, _View.StartDate, _View.EndDate.AddDays(1)); } if (reload == true) _lineState = _lineState ^ 1; _ViewState = _lineState; foreach (YearMonth yearMonth in _View.YearMonths) yearMonth.AppBits.SetAll(false); int rootMonth = _View.StartDate.Year * 12 + _View.StartDate.Month; for (int i = 0; i < _lineAppts.Count; i++) { Appointment app = _lineAppts[i]; if (IsAppointmentVisible(app) == true) { int month = (app.StartTime.Year * 12 + app.StartTime.Month) - rootMonth; if ((uint)month < _View.YearMonths.Length) { YearMonth ym = _View.YearMonths[month]; DateTime date = app.StartTime; int day = app.StartTime.Day - 1; while (date < app.EndTime || (date == app.EndTime && app.StartTime == app.EndTime)) { if (day >= ym.DaysInMonth) { month++; if (month >= _View.YearMonths.Length) break; ym = _View.YearMonths[month]; day = 0; } ym.AppBits.Set(day++, true); date = date.AddDays(1); } } } } foreach (YearMonth yearMonth in _View.YearMonths) UpdateCustomItems(yearMonth); }