// FIXME: add similar methods for RDATE and EXDATE /// <summary> /// Adds a recurrence rule to the recurring component /// </summary> /// <param name="recur">The recurrence rule to add</param> public void AddRecurrence(Recur recur) { if (RRule != null) { Recur[] rules = new Recur[RRule.Length + 1]; RRule.CopyTo(rules, 0); rules[rules.Length - 1] = recur; RRule = rules; } else { RRule = new Recur[] { recur } }; }
// FIXME: add similar methods for RDATE and EXDATE /// <summary> /// Adds a recurrence rule to the recurring component /// </summary> /// <param name="recur">The recurrence rule to add</param> public void AddRecurrence(Recur recur) { if (string.IsNullOrEmpty(recur.Name)) { recur.Name = "RRULE"; } if (RRule != null) { Recur[] rules = new Recur[RRule.Length + 1]; RRule.CopyTo(rules, 0); rules[rules.Length - 1] = recur; RRule = rules; } else { RRule = new Recur[] { recur } }; }
/// <summary> /// Adds a recurrence rule to the recurring component /// </summary> /// <param name="recur">The recurrence rule to add</param> virtual public void AddRecurrencePattern(RecurrencePattern recur) { if (string.IsNullOrEmpty(recur.Name)) { recur.Name = "RRULE"; } recur.Parent = this; if (RRule != null) { RecurrencePattern[] rules = new RecurrencePattern[RRule.Length + 1]; RRule.CopyTo(rules, 0); rules[rules.Length - 1] = recur; RRule = rules; } else { RRule = new RecurrencePattern[] { recur } }; }
/// <summary> /// Processes Until= attribute entries /// </summary> /// <param name="entry"></param> /// <param name="rrule"></param> /// <param name="attr"></param> private void ProcessUntil(CalendarEntry entry, RRule rrule, AttributeData attr) { rrule.Until = (attr.Value.Length > 8) ? ProcessDateTime(entry, attr.Value) : ProcessDateValue(entry, attr.Value); }
/// <summary> /// Processes Interval= attribute entries /// </summary> /// <param name="entry"></param> /// <param name="rrule"></param> /// <param name="attr"></param> private void ProcessInterval(CalendarEntry entry, RRule rrule, AttributeData attr) { int n; if (int.TryParse(attr.Value, out n) == false) { n = 1; ReportError(entry, String.Format("\"{0}\" is not a valid INTERVAL value", attr.Value)); } rrule.Interval = n; }
/// <summary> /// Processes Freq= attribute entries /// </summary> /// <param name="entry"></param> /// <param name="rrule"></param> /// <param name="attr"></param> private void ProcessFreq(CalendarEntry entry, RRule rrule, AttributeData attr) { ValueToken tkn = (ValueToken)GetToken(_values, attr.Value); switch (tkn) { case ValueToken.Secondly: rrule.Freq = Frequency.Secondly; break; case ValueToken.Minutely: rrule.Freq = Frequency.Minutely; break; case ValueToken.Hourly: rrule.Freq = Frequency.Hourly; break; case ValueToken.Daily: rrule.Freq = Frequency.Daily; break; case ValueToken.Weekly: rrule.Freq = Frequency.Weekly; break; case ValueToken.Monthly: rrule.Freq = Frequency.Monthly; break; case ValueToken.Yearly: rrule.Freq = Frequency.Yearly; break; default: ReportError(entry, "Invalid FREQ value"); rrule.Freq = Frequency.Daily; break; } }
/// <summary> /// Processes ByDay= attribute entries /// </summary> /// <param name="entry"></param> /// <param name="rrule"></param> /// <param name="value"></param> private void ProcessByDay(CalendarEntry entry, RRule rrule, string value) { rrule.ByDays = eDayOfWeekRecurrence.None; Regex p = new Regex("(?<dayNum>[+-]{0,1}\\d+)*(?<weekDay>\\w+)"); MatchCollection mc = p.Matches(value); if (mc.Count > 0) { rrule.ByDay = new List<int>[7]; foreach (Match ma in mc) { int dayOfWeek; eDayOfWeekRecurrence weekDay = ProcessWeekDay(entry, ma.Groups["weekDay"].Value, out dayOfWeek); rrule.ByDays |= weekDay; string s = ma.Groups["dayNum"].Value; int n = 0; if (String.IsNullOrEmpty(s) == false) { n = int.Parse(s); if (Math.Abs(n) > 53) { ReportError(entry, String.Format("BYDAY value ({0}) is not in the range +/- 1 to 53", n)); n = 0; } } if (rrule.ByDay[dayOfWeek] == null) rrule.ByDay[dayOfWeek] = new List<int>(); rrule.ByDay[dayOfWeek].Add(n); } } }
/// <summary> /// Processes RRule entries /// </summary> /// <param name="entry"></param> /// <returns></returns> private RRule ProcessRRule(CalendarEntry entry) { RRule rrule = new RRule(); List<AttributeData> attributes = new List<AttributeData>(); string s = ";" + entry.Value; ParseAttributeData(attributes, ref s); foreach (AttributeData attr in attributes) { ValueToken tkn = (ValueToken)GetToken(_values, attr.Id); switch (tkn) { case ValueToken.ByDay: ProcessByDay(entry, rrule, attr.Value); break; case ValueToken.ByMonth: rrule.ByMonth = ProcessByIntValues(entry, attr.Value, 1, 12, tkn); break; case ValueToken.ByMonthDay: rrule.ByMonthDay = ProcessByIntValues(entry, attr.Value, 1, 31, tkn); break; case ValueToken.Count: ProcessCount(entry, rrule, attr); break; case ValueToken.Freq: ProcessFreq(entry, rrule, attr); break; case ValueToken.Interval: ProcessInterval(entry, rrule, attr); break; case ValueToken.Until: ProcessUntil(entry, rrule, attr); break; case ValueToken.BySecond: case ValueToken.ByMinute: case ValueToken.ByHour: case ValueToken.ByYearDay: case ValueToken.ByWeekNo: case ValueToken.BySetPos: case ValueToken.WkSt: break; default: ReportError(entry, "Unrecognized RRULE Value - " + attr.Id); break; } } return (rrule); }