private String buildRrule(RecurrencePattern oPattern) { log.Fine("Building RRULE"); rrule = new Dictionary <String, String>(); #region RECURRENCE PATTERN log.Fine("Determining pattern for frequency " + oPattern.RecurrenceType.ToString() + "."); switch (oPattern.RecurrenceType) { case OlRecurrenceType.olRecursDaily: { addRule(rrule, "FREQ", "DAILY"); setInterval(oPattern.Interval); break; } case OlRecurrenceType.olRecursWeekly: { addRule(rrule, "FREQ", "WEEKLY"); setInterval(oPattern.Interval); if ((oPattern.DayOfWeekMask & (oPattern.DayOfWeekMask - 1)) != 0) //is not a power of 2 (i.e. not just a single day) // Need to work out "BY" pattern // Eg "BYDAY=MO,TU,WE,TH,FR" { addRule(rrule, "BYDAY", string.Join(",", getByDay(oPattern.DayOfWeekMask).ToArray())); } break; } case OlRecurrenceType.olRecursMonthly: { addRule(rrule, "FREQ", "MONTHLY"); setInterval(oPattern.Interval); //Outlook runs on last day of month if day doesn't exist; Google doesn't run at all - so fix if (oPattern.PatternStartDate.Day > 28) { addRule(rrule, "BYDAY", "SU,MO,TU,WE,TH,FR,SA"); addRule(rrule, "BYSETPOS", "-1"); } break; } case OlRecurrenceType.olRecursMonthNth: { addRule(rrule, "FREQ", "MONTHLY"); setInterval(oPattern.Interval); addRule(rrule, "BYDAY", string.Join(",", getByDay(oPattern.DayOfWeekMask).ToArray())); addRule(rrule, "BYSETPOS", (oPattern.Instance == 5) ? "-1" : oPattern.Instance.ToString()); break; } case OlRecurrenceType.olRecursYearly: { addRule(rrule, "FREQ", "YEARLY"); //Google interval is years, Outlook is months if (oPattern.Interval != 12) { addRule(rrule, "INTERVAL", (oPattern.Interval / 12).ToString()); } break; } case OlRecurrenceType.olRecursYearNth: { //Issue 445: Outlook incorrectly surfaces 12 monthly recurrences as olRecursYearNth, so we'll undo that. //In addition, many apps, indeed even the Google webapp, doesn't display a yearly recurrence rule properly //despite actually showing the events on the right dates. //So to make OGCS work better with apps that aren't providing full iCal functionality, we'll translate this //into a monthly recurrence instead. addRule(rrule, "FREQ", "MONTHLY"); addRule(rrule, "INTERVAL", oPattern.Interval.ToString()); /*Strictly, what we /should/ be doing is: * addRule(rrule, "FREQ", "YEARLY"); * if (oPattern.Interval != 12) * addRule(rrule, "INTERVAL", (oPattern.Interval / 12).ToString()); * addRule(rrule, "BYMONTH", oPattern.MonthOfYear.ToString()); */ if (oPattern.DayOfWeekMask != (OlDaysOfWeek)127) //If not every day of week, define which ones { addRule(rrule, "BYDAY", string.Join(",", getByDay(oPattern.DayOfWeekMask).ToArray())); } addRule(rrule, "BYSETPOS", (oPattern.Instance == 5) ? "-1" : oPattern.Instance.ToString()); break; } } #endregion #region RECURRENCE RANGE if (!oPattern.NoEndDate) { log.Fine("Checking end date."); addRule(rrule, "UNTIL", Recurrence.IANAdate(oPattern.PatternEndDate + oPattern.StartTime.TimeOfDay)); } #endregion return(string.Join(";", rrule.Select(x => x.Key + "=" + x.Value).ToArray())); }
private String buildRrule(RecurrencePattern oPattern) { log.Fine("Building RRULE"); rrule = new Dictionary <String, String>(); #region RECURRENCE PATTERN log.Fine("Determining pattern for frequency " + oPattern.RecurrenceType.ToString() + "."); switch (oPattern.RecurrenceType) { case OlRecurrenceType.olRecursDaily: { addRule(rrule, "FREQ", "DAILY"); setInterval(oPattern.Interval); break; } case OlRecurrenceType.olRecursWeekly: { addRule(rrule, "FREQ", "WEEKLY"); setInterval(oPattern.Interval); if ((oPattern.DayOfWeekMask & (oPattern.DayOfWeekMask - 1)) != 0) //is not a power of 2 (i.e. not just a single day) // Need to work out "BY" pattern // Eg "BYDAY=MO,TU,WE,TH,FR" { addRule(rrule, "BYDAY", string.Join(",", getByDay(oPattern.DayOfWeekMask).ToArray())); } break; } case OlRecurrenceType.olRecursMonthly: { addRule(rrule, "FREQ", "MONTHLY"); setInterval(oPattern.Interval); //Outlook runs on last day of month if day doesn't exist; Google doesn't run at all - so fix if (oPattern.PatternStartDate.Day > 28) { addRule(rrule, "BYDAY", "SU,MO,TU,WE,TH,FR,SA"); addRule(rrule, "BYSETPOS", "-1"); } break; } case OlRecurrenceType.olRecursMonthNth: { addRule(rrule, "FREQ", "MONTHLY"); setInterval(oPattern.Interval); addRule(rrule, "BYSETPOS", (oPattern.Instance == 5) ? "-1" : oPattern.Instance.ToString()); if (oPattern.DayOfWeekMask != (OlDaysOfWeek)127) //If not every day of week, define which ones { addRule(rrule, "BYDAY", string.Join(",", getByDay(oPattern.DayOfWeekMask).ToArray())); } break; } case OlRecurrenceType.olRecursYearly: { addRule(rrule, "FREQ", "YEARLY"); //Google interval is years, Outlook is months addRule(rrule, "INTERVAL", (oPattern.Interval / 12).ToString()); break; } case OlRecurrenceType.olRecursYearNth: { addRule(rrule, "FREQ", "YEARLY"); addRule(rrule, "BYSETPOS", (oPattern.Instance == 5) ? "-1" : oPattern.Instance.ToString()); if (oPattern.DayOfWeekMask != (OlDaysOfWeek)127) //If not every day of week, define which ones { addRule(rrule, "BYDAY", string.Join(",", getByDay(oPattern.DayOfWeekMask).ToArray())); } addRule(rrule, "BYMONTH", oPattern.MonthOfYear.ToString()); break; } } #endregion #region RECURRENCE RANGE if (!oPattern.NoEndDate) { log.Fine("Checking end date."); if (oPattern.StartTime.TimeOfDay == oPattern.StartTime.Date.TimeOfDay) //All-day { addRule(rrule, "UNTIL", Recurrence.IANAdate(oPattern.PatternEndDate.AddDays(-1))); } else { addRule(rrule, "UNTIL", Recurrence.IANAdate(oPattern.PatternEndDate)); } } #endregion return(string.Join(";", rrule.Select(x => x.Key + "=" + x.Value).ToArray())); }