/// <summary> /// Initializes a new instance of the <see cref="RecurrencePattern"/> class. /// </summary> public RecurrencePattern( TimeSpan startTime, TimeSpan stopTime, List <TimeSpan> times, RecurrenceFrequency dailyFrequency, int dailyInterval, int?dayOfMonth, RecurrenceDays daysOfWeekMask, RecurrenceFrequency frequency, int interval, int?monthOfYear, int?dayOrdinal) : this() { this._StartTime = startTime; this._StopTime = stopTime; this._Times = times; this.dailyFrequency = dailyFrequency; this.dailyInterval = dailyInterval; this.dayOfMonth = dayOfMonth; this.daysOfWeekMask = daysOfWeekMask; this.frequency = frequency; this.interval = interval; this.monthOfYear = monthOfYear; this.dayOrdinal = dayOrdinal; }
public static EventRecurrence CreateWeeklyRecurrence(int interval, RecurrenceDays dayOfWeekMask, string startDatePattern) { ValidateInterval(interval); ValidateDate(startDatePattern); return(new EventRecurrence(RecurrenceType.Weekly, interval, 0, 0, dayOfWeekMask, 0, startDatePattern, null, false)); }
/// <summary> /// Matches the day of week mask. /// </summary> /// <param name="start">The start.</param> /// <param name="daysOfWeekMask">The days of week mask.</param> /// <returns></returns> protected static bool MatchDayOfWeekMask(DateTime start, RecurrenceDays daysOfWeekMask) { if (daysOfWeekMask == RecurrenceDays.None) { return(true); } return(daysOfWeekMask.HasDay(start.DayOfWeek.GetRecurrenceDay())); }
/// <summary> /// Determines whether the specified recurrence days has day. /// </summary> /// <param name="recurrenceDays">The recurrence days.</param> /// <param name="dayToCompare">The day to compare.</param> /// <returns> /// <c>true</c> if the specified recurrence days has day; otherwise, <c>false</c>. /// </returns> public static bool HasDay(this RecurrenceDays recurrenceDays, RecurrenceDays dayToCompare) { if ((recurrenceDays & dayToCompare) == dayToCompare) { return(true); } return(false); }
public static EventRecurrence CreateMonthNthRecurrence(int interval, RecurrenceDays dayOfWeekMask, short instance, string startDatePattern) { ValidateInterval(interval); ValidateInstance(instance); ValidateDate(startDatePattern); return(new EventRecurrence(RecurrenceType.MonthNth, interval, 0, 0, dayOfWeekMask, instance, startDatePattern, null, false)); }
public static EventRecurrence CreateYearNthRecurrence(RecurrenceDays dayOfWeekMask, short month, short instance, string startDatePattern, bool noEndDate) { ValidateMonth(month); ValidateInstance(instance); ValidateDate(startDatePattern); return(new EventRecurrence(RecurrenceType.YearNth, 0, month, 0, dayOfWeekMask, instance, startDatePattern, null, noEndDate)); }
/// <summary> /// Gets the day of week. /// </summary> /// <param name="recurrenceDays">The recurrence days.</param> /// <returns></returns> /// <exception cref="ArgumentException"><paramref name="recurrenceDays"/></exception> public static DayOfWeek GetDayOfWeek(this RecurrenceDays recurrenceDays) { List <DayOfWeek> daysOfWeek = GetDaysOfWeek(recurrenceDays).ToList(); if (daysOfWeek.Count != 1) { throw new ArgumentException(ExceptionsStrings.ContainsOnlyOneFlagValue, "recurrenceDays"); } return(daysOfWeek[0]); }
/// <summary> /// Gets the day of week. /// </summary> /// <param name="recurrenceDays">The recurrence days.</param> /// <returns></returns> /// <exception cref="ArgumentException"><paramref name="recurrenceDays"/></exception> public static DayOfWeek GetDayOfWeek(this RecurrenceDays recurrenceDays) { List <DayOfWeek> daysOfWeek = GetDaysOfWeek(recurrenceDays).ToList(); if (daysOfWeek.Count != 1) { throw new ArgumentException("Invalid Recurrence Days parameter - days of week count <> 1", "recurrenceDays"); } return(daysOfWeek[0]); }
/// <summary> /// Matches the day ordinal. /// </summary> /// <param name="date">The date.</param> /// <param name="dayOrdinal">The day ordinal.</param> /// <param name="daysOfWeekMask">The days of week mask.</param> /// <returns></returns> protected static bool MatchDayOrdinal(DateTime date, int?dayOrdinal, RecurrenceDays daysOfWeekMask) { if (!dayOrdinal.HasValue) { return(true); } return((0 < dayOrdinal) ? MatchDayOrdinalPositive(date, dayOrdinal.Value, daysOfWeekMask) : MatchDayOrdinalNegative(date, dayOrdinal.Value, daysOfWeekMask)); }
private EventRecurrence(RecurrenceType type, int interval, short month, short dayOfMonth, RecurrenceDays dayOfWeekMask, short instance, string startDatePattern, string endDatePattern, bool noEndDate) { this.type = type; this.interval = interval; this.month = month; this.dayOfMonth = dayOfMonth; this.dayOfWeekMask = dayOfWeekMask; this.instance = instance; this.startDatePattern = startDatePattern; this.endDatePattern = endDatePattern; this.noEndDate = noEndDate; }
/// <summary> /// Initializes a new instance of the <see cref="RecurrencePattern"/> class. /// </summary> public RecurrencePattern() { this.dayOfMonth = null; this.daysOfWeekMask = RecurrenceDays.None; this.frequency = RecurrenceFrequency.None; this.interval = 1; this.monthOfYear = null; this.dayOrdinal = null; this.recursUntil = null; this.maxOccurrences = null; this.firstDayOfWeek = DayOfWeek.Monday; }
private RecurrenceDays GetRecurrenceDays() { RecurrenceDays days = RecurrenceDays.None; foreach (var item in this.WeekDays) { if (item.IsSelected) { days = days.AddDay(item.Value); } } return(days); }
private EventRecurrence(RecurrenceType type, int interval, short month, short dayOfMonth, RecurrenceDays dayOfWeekMask, short instance, string startDatePattern, string endDatePattern, bool noEndDate) { this.type = type; this.interval = interval; this.month = month; this.dayOfMonth = dayOfMonth; this.dayOfWeekMask = dayOfWeekMask; this.instance = instance; this.startDatePattern = startDatePattern; this.endDatePattern = endDatePattern; this.noEndDate = noEndDate; }
/// <summary> /// Gets the days of week. /// </summary> /// <param name="recurrenceDays">The recurrence days.</param> /// <returns></returns> public static IEnumerable <DayOfWeek> GetDaysOfWeek(this RecurrenceDays recurrenceDays) { var dayOfWeeks = new List <DayOfWeek>(); foreach (DayOfWeek dayOfWeek in Enum.GetValues(typeof(DayOfWeek))) { if (recurrenceDays.HasDay(dayOfWeek)) { dayOfWeeks.Add(dayOfWeek); } } dayOfWeeks.Sort(); return(dayOfWeeks); }
/// <summary> /// Initializes a new instance of the <see cref="RecurrencePattern"/> class. /// </summary> public RecurrencePattern() { this.dayOfMonth = null; this.daysOfWeekMask = RecurrenceDays.None; this.frequency = RecurrenceFrequency.Daily; this.interval = 1; this.monthOfYear = null; this.dayOrdinal = null; this._StartTime = new TimeSpan(0, 0, 0); this._StopTime = new TimeSpan(23, 59, 59); this._Times = new List <TimeSpan>(); this.dailyFrequency = RecurrenceFrequency.Minutely; this.dailyInterval = 1; this.firstDayOfWeek = DayOfWeek.Monday; }
/// <summary> /// Initializes a new instance of the <see cref="RecurrencePattern"/> class. /// </summary> /// <param name="dayOfMonth">The day of month.</param> /// <param name="daysOfWeekMask">The days of week mask.</param> /// <param name="frequency">The frequency.</param> /// <param name="interval">The interval.</param> /// <param name="monthOfYear">The month of year.</param> /// <param name="dayOrdinal">The week of month.</param> public RecurrencePattern( int?dayOfMonth, RecurrenceDays daysOfWeekMask, RecurrenceFrequency frequency, int interval, int?monthOfYear, int?dayOrdinal) : this() { this.dayOfMonth = dayOfMonth; this.daysOfWeekMask = daysOfWeekMask; this.frequency = frequency; this.interval = interval; this.monthOfYear = monthOfYear; this.dayOrdinal = dayOrdinal; }
private static bool MatchDayOrdinalNegative(DateTime date, int dayOrdinal, RecurrenceDays dayOfWeekMask) { DateTime currentDate = CalendarHelper.GetEndOfMonth(date.Year, date.Month); int current = 0; while (date < currentDate) { if (MatchDayOfWeekMask(currentDate, dayOfWeekMask)) { current--; } currentDate = currentDate.AddDays(-1); } return(current == dayOrdinal); }
private static List <NameValueItem <RecurrenceDays> > CreateWeekDays( IScheduler scheduler, RecurrenceDays dayOfWeekMask) { var days = new List <NameValueItem <RecurrenceDays> >(); IDictionary <DayOfWeek, string> namesOfDays = CalendarHelper.GetNamesOfDays(scheduler.GetCultureInUse()); foreach ( DayOfWeek dayOfWeek in CalendarHelper.GetDaysOfWeekStartWithFirstDayOfWeek(scheduler.GetFirstDayOfWeekInUse())) { RecurrenceDays recurrenceDay = dayOfWeek.GetRecurrenceDay(); var day = new NameValueItem <RecurrenceDays>( recurrenceDay, namesOfDays[dayOfWeek], dayOfWeekMask.HasDay(recurrenceDay)); days.Add(day); } return(days); }
/// <summary> /// Determines whether the specified recurrence days has day. /// </summary> /// <param name="recurrenceDays">The recurrence days.</param> /// <param name="dayToCompare">The day to compare.</param> /// <returns> /// <c>true</c> if the specified recurrence days has day; otherwise, <c>false</c>. /// </returns> public static bool HasDay(this RecurrenceDays recurrenceDays, RecurrenceDays dayToCompare) { if ((recurrenceDays & dayToCompare) == dayToCompare) { return true; } return false; }
/// <summary> /// Adds the day. /// </summary> /// <param name="recurrenceDays">The recurrence days.</param> /// <param name="dayToAdd">The day to add.</param> public static RecurrenceDays AddDay(this RecurrenceDays recurrenceDays, RecurrenceDays dayToAdd) { return(recurrenceDays | dayToAdd); }
/// <summary> /// Adds the day. /// </summary> /// <param name="recurrenceDays">The recurrence days.</param> /// <param name="dayToAdd">The day to add.</param> public static RecurrenceDays AddDay(this RecurrenceDays recurrenceDays, RecurrenceDays dayToAdd) { return recurrenceDays | dayToAdd; }
private static bool MatchDayOrdinalPositive( DateTime date, int dayOrdinal, RecurrenceDays dayOfWeekMask) { DateTime currentDate = CalendarHelper.GetStartOfMonth(date.Year, date.Month); int current = 0; while (currentDate <= date) { if (MatchDayOfWeekMask(currentDate, dayOfWeekMask)) { current++; } currentDate = currentDate.AddDays(1); } return current == dayOrdinal; }
/// <summary> /// Initializes a new instance of the <see cref="RecurrencePattern"/> class. /// </summary> public RecurrencePattern() { this.dayOfMonth = null; this.daysOfWeekMask = RecurrenceDays.None; this.frequency = RecurrenceFrequency.Daily; this.interval = 1; this.monthOfYear = null; this.dayOrdinal = null; this._StartTime = new TimeSpan(0, 0, 0); this._StopTime = new TimeSpan(23, 59, 59); this._Times = new List<TimeSpan>(); this.dailyFrequency = RecurrenceFrequency.Minutely; this.dailyInterval = 1; this.firstDayOfWeek = DayOfWeek.Monday; }
/// <summary> /// Matches the day ordinal. /// </summary> /// <param name="date">The date.</param> /// <param name="dayOrdinal">The day ordinal.</param> /// <param name="daysOfWeekMask">The days of week mask.</param> /// <returns></returns> protected static bool MatchDayOrdinal(DateTime date, int? dayOrdinal, RecurrenceDays daysOfWeekMask) { if (!dayOrdinal.HasValue) { return true; } return (0 < dayOrdinal) ? MatchDayOrdinalPositive(date, dayOrdinal.Value, daysOfWeekMask) : MatchDayOrdinalNegative(date, dayOrdinal.Value, daysOfWeekMask); }
private Slot CreateNonWorkingSlot(ObservableCollection<Resource> resources, DateTime start, DateTime end, RecurrenceDays days) { Slot slot = new NonWorkingSlot(start, end); slot.RecurrencePattern = new RecurrencePattern(null, days, RecurrenceFrequency.Weekly, 1, null, null); slot.Resources.AddRange(resources); return slot; }
/// <summary> /// Determines whether the specified recurrence days has day. /// </summary> /// <param name="recurrenceDays">The recurrence days.</param> /// <param name="dayToCompare">The day to compare.</param> /// <returns> /// <c>true</c> if the specified recurrence days has day; otherwise, <c>false</c>. /// </returns> public static bool HasDay(this RecurrenceDays recurrenceDays, DayOfWeek dayToCompare) { RecurrenceDays recurrenceDayToCompare = dayToCompare.GetRecurrenceDay(); return(recurrenceDays.HasDay(recurrenceDayToCompare)); }
private Slot CreateNonWorkingSlot(ObservableCollection <Resource> resources, DateTime start, DateTime end, RecurrenceDays days) { Slot slot = new NonWorkingSlot(start, end); slot.RecurrencePattern = new RecurrencePattern(null, days, RecurrenceFrequency.Weekly, 1, null, null); slot.Resources.AddRange(resources); return(slot); }
public static EventRecurrence CreateWeeklyRecurrence(int interval, RecurrenceDays dayOfWeekMask, string startDatePattern, bool noEndDate) { ValidateInterval(interval); ValidateDate(startDatePattern); return new EventRecurrence(RecurrenceType.Weekly, interval, 0, 0, dayOfWeekMask, 0, startDatePattern, null, noEndDate); }
public static EventRecurrence CreateMonthNthRecurrence(int interval, RecurrenceDays dayOfWeekMask, short instance, string startDatePattern, bool noEndDate) { ValidateInterval(interval); ValidateInstance(instance); ValidateDate(startDatePattern); return new EventRecurrence(RecurrenceType.MonthNth, interval, 0, 0, dayOfWeekMask, instance, startDatePattern, null, noEndDate); }
/// <summary> /// Initializes a new instance of the <see cref="RecurrencePattern"/> class. /// </summary> public RecurrencePattern( TimeSpan startTime, TimeSpan stopTime, List<TimeSpan> times, RecurrenceFrequency dailyFrequency, int dailyInterval, int? dayOfMonth, RecurrenceDays daysOfWeekMask, RecurrenceFrequency frequency, int interval, int? monthOfYear, int? dayOrdinal) : this() { this._StartTime = startTime; this._StopTime = stopTime; this._Times = times; this.dailyFrequency = dailyFrequency; this.dailyInterval = dailyInterval; this.dayOfMonth = dayOfMonth; this.daysOfWeekMask = daysOfWeekMask; this.frequency = frequency; this.interval = interval; this.monthOfYear = monthOfYear; this.dayOrdinal = dayOrdinal; }
/// <summary> /// Matches the day of week mask. /// </summary> /// <param name="start">The start.</param> /// <param name="daysOfWeekMask">The days of week mask.</param> /// <returns></returns> protected static bool MatchDayOfWeekMask(DateTime start, RecurrenceDays daysOfWeekMask) { if (daysOfWeekMask == RecurrenceDays.None) { return true; } return daysOfWeekMask.HasDay(start.DayOfWeek.GetRecurrenceDay()); }
private void GetValues() { _Pattern = new RecurrencePattern(); CultureInfo ci = new CultureInfo("en-US"); // time values if (this.dailyPeriodically.IsChecked == true) { TimeSpan tStart = new TimeSpan(); if (TimeSpan.TryParseExact(this.periodicallyStart.Text, "%h\\:mm", ci, out tStart) == true) { _Pattern.StartTime = tStart; } TimeSpan tStop = new TimeSpan(); if (TimeSpan.TryParseExact(this.periodicallyStop.Text, "%h\\:mm", ci, out tStop) == true) { _Pattern.StopTime = tStop; } int di = 1; int.TryParse(this.periodicallyMinutes.Text, out di); // shoul be checked convertion result for validate the form _Pattern.DailyInterval = di; } else { _Pattern.Times.AddRange((List <TimeSpan>)timesForSchedule.ItemsSource); } // day/week/month values // daily if (this.dailyPattern.IsChecked == true) { if (this.everyWeekDay.IsChecked == true) { _Pattern.Frequency = RecurrenceFrequency.Weekly; _Pattern.DaysOfWeekMask = RecurrenceDays.WeekDays; _Pattern.Interval = 1; } else { int interval = 1; int.TryParse(this.daysNumber.Text, out interval); _Pattern.Interval = interval; _Pattern.DaysOfWeekMask = RecurrenceDays.EveryDay; _Pattern.Frequency = RecurrenceFrequency.Daily; } } // weekly else if (this.weeklyPattern.IsChecked == true) { _Pattern.Frequency = RecurrenceFrequency.Weekly; int interval = 1; int.TryParse(this.recurrEveryWeeks.Text, out interval); _Pattern.Interval = interval; RecurrenceDays dayMask = RecurrenceDays.None; if (this.sunday.IsChecked == true) { dayMask = dayMask | RecurrenceDays.Sunday; } if (this.monday.IsChecked == true) { dayMask = dayMask | RecurrenceDays.Monday; } if (this.tuesday.IsChecked == true) { dayMask = dayMask | RecurrenceDays.Tuesday; } if (this.wednesday.IsChecked == true) { dayMask = dayMask | RecurrenceDays.Wednesday; } if (this.thursday.IsChecked == true) { dayMask = dayMask | RecurrenceDays.Thursday; } if (this.friday.IsChecked == true) { dayMask = dayMask | RecurrenceDays.Friday; } if (this.saturday.IsChecked == true) { dayMask = dayMask | RecurrenceDays.Saturday; } _Pattern.DaysOfWeekMask = dayMask; _Pattern.FirstDayOfWeek = CultureInfo.CurrentUICulture.DateTimeFormat.FirstDayOfWeek; } else if (this.monthlyPattern.IsChecked == true) { _Pattern.Frequency = RecurrenceFrequency.Monthly; if (this.monthlyDays.IsChecked == true) { int interval = 1; int.TryParse(this.monthlyDaysNum.Text, out interval); _Pattern.Interval = interval; int dayOfMonth = 1; int.TryParse(this.monthlyDaysMonths.Text, out dayOfMonth); _Pattern.DayOfMonth = dayOfMonth; } else if (this.monthlyNums.IsChecked == true) { switch (this.monthlyNum.Text) { case "first": _Pattern.DayOrdinal = 1; break; case "second": _Pattern.DayOrdinal = 2; break; case "third": _Pattern.DayOrdinal = 3; break; case "fourth": _Pattern.DayOrdinal = 4; break; case "last": _Pattern.DayOrdinal = 5; break; } if (this.monthlyNumType.Text == "Monday") { _Pattern.DaysOfWeekMask = RecurrenceDays.Monday; } else if (this.monthlyNumType.Text == "Tuesday") { _Pattern.DaysOfWeekMask = RecurrenceDays.Tuesday; } else if (this.monthlyNumType.Text == "Wednesday") { _Pattern.DaysOfWeekMask = RecurrenceDays.Wednesday; } else if (this.monthlyNumType.Text == "Thursday") { _Pattern.DaysOfWeekMask = RecurrenceDays.Thursday; } else if (this.monthlyNumType.Text == "Friday") { _Pattern.DaysOfWeekMask = RecurrenceDays.Friday; } else if (this.monthlyNumType.Text == "Saturday") { _Pattern.DaysOfWeekMask = RecurrenceDays.Saturday; } else if (this.monthlyNumType.Text == "Sunday") { _Pattern.DaysOfWeekMask = RecurrenceDays.Sunday; } int interval = 1; int.TryParse(this.monthlyValue.Text, out interval); _Pattern.Interval = interval; } } }
public static EventRecurrence CreateYearNthRecurrence(RecurrenceDays dayOfWeekMask, short month, short instance, string startDatePattern, bool noEndDate) { ValidateMonth(month); ValidateInstance(instance); ValidateDate(startDatePattern); return new EventRecurrence(RecurrenceType.YearNth, 0, month, 0, dayOfWeekMask, instance, startDatePattern, null, noEndDate); }