//===================================================================== /// <summary> /// This is overridden to allow cloning of a PDI object /// </summary> /// <returns>A clone of the object</returns> public override object Clone() { VEvent o = new VEvent(); o.Clone(this); return(o); }
public void FilterAllDayEvents1() { VCalendarParser calendar = new VCalendarParser(); calendar.ParseFile("SampleCalendar.ics"); EWSoftware.PDI.Objects.VEvent ev_allday = calendar.VCalendar.Events.AddNew(); ev_allday.UniqueId.Value = Guid.NewGuid().ToString(); ev_allday.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01); ev_allday.EndDateTime.DateTimeValue = ev_allday.StartDateTime.DateTimeValue.AddDays(1); EWSoftware.PDI.Objects.VEvent ev_notallday = calendar.VCalendar.Events.AddNew(); ev_notallday.UniqueId.Value = Guid.NewGuid().ToString(); ev_notallday.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01).AddHours(2); ev_notallday.EndDateTime.DateTimeValue = ev_notallday.StartDateTime.DateTimeValue.AddDays(1).AddHours(-2); Assert.AreEqual(1, calendar.VCalendar.Events.Count(ev => Equals(ev.UniqueId, ev_allday.UniqueId))); Assert.AreEqual(1, calendar.VCalendar.Events.Count(ev => Equals(ev.UniqueId, ev_notallday.UniqueId))); // filter out all-day events EventManager em = new EventManager(calendar); em.Filter(new FilteringOptions("h=true")); IList <EWSoftware.PDI.Objects.VEvent> eventsAfterFiltering = em.GetEventList(); Assert.AreEqual(0, eventsAfterFiltering.Count(ev => Equals(ev.UniqueId, ev_allday.UniqueId))); Assert.AreEqual(1, eventsAfterFiltering.Count(ev => Equals(ev.UniqueId, ev_notallday.UniqueId))); }
public void HideShorterThan10Minutes() { VCalendarParser calendar = new VCalendarParser(); calendar.ParseFile("SampleCalendar.ics"); EWSoftware.PDI.Objects.VEvent ev_5minutes = calendar.VCalendar.Events.AddNew(); ev_5minutes.UniqueId.Value = Guid.NewGuid().ToString(); ev_5minutes.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01); ev_5minutes.EndDateTime.DateTimeValue = ev_5minutes.StartDateTime.DateTimeValue.AddMinutes(5); EWSoftware.PDI.Objects.VEvent ev_10minutes = calendar.VCalendar.Events.AddNew(); ev_10minutes.UniqueId.Value = Guid.NewGuid().ToString(); ev_10minutes.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01); ev_10minutes.EndDateTime.DateTimeValue = ev_10minutes.StartDateTime.DateTimeValue.AddMinutes(10); EWSoftware.PDI.Objects.VEvent ev_15minutes = calendar.VCalendar.Events.AddNew(); ev_15minutes.UniqueId.Value = Guid.NewGuid().ToString(); ev_15minutes.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01).AddHours(2); ev_15minutes.EndDateTime.DateTimeValue = ev_15minutes.StartDateTime.DateTimeValue.AddMinutes(15); Assert.AreEqual(1, calendar.VCalendar.Events.Count(ev => ev.UniqueId == ev_5minutes.UniqueId)); Assert.AreEqual(1, calendar.VCalendar.Events.Count(ev => ev.UniqueId == ev_10minutes.UniqueId)); Assert.AreEqual(1, calendar.VCalendar.Events.Count(ev => ev.UniqueId == ev_15minutes.UniqueId)); // filter out all-day events EventManager em = new EventManager(calendar); em.Filter(new FilteringOptions("min=10")); System.Collections.Generic.IList <EWSoftware.PDI.Objects.VEvent> eventsAfterFiltering = em.GetEventList(); Assert.AreEqual(0, eventsAfterFiltering.Count(ev => ev.UniqueId == ev_5minutes.UniqueId)); Assert.AreEqual(1, eventsAfterFiltering.Count(ev => ev.UniqueId == ev_10minutes.UniqueId)); Assert.AreEqual(1, eventsAfterFiltering.Count(ev => ev.UniqueId == ev_15minutes.UniqueId)); }
public void ShortenEvents() { VCalendarParser calendar = new VCalendarParser(); calendar.ParseFile("SampleCalendar.ics"); EWSoftware.PDI.Objects.VEvent ev_1h = calendar.VCalendar.Events.AddNew(); ev_1h.UniqueId.Value = Guid.NewGuid().ToString(); ev_1h.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01); ev_1h.EndDateTime.DateTimeValue = ev_1h.StartDateTime.DateTimeValue.AddHours(1); EWSoftware.PDI.Objects.VEvent ev_2h = calendar.VCalendar.Events.AddNew(); ev_2h.UniqueId.Value = Guid.NewGuid().ToString(); ev_2h.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01); ev_2h.EndDateTime.DateTimeValue = ev_2h.StartDateTime.DateTimeValue.AddHours(2); EWSoftware.PDI.Objects.VEvent ev_3h = calendar.VCalendar.Events.AddNew(); ev_3h.UniqueId.Value = Guid.NewGuid().ToString(); ev_3h.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01).AddHours(2); ev_3h.EndDateTime.DateTimeValue = ev_3h.StartDateTime.DateTimeValue.AddHours(3); Assert.AreEqual(1, calendar.VCalendar.Events.First(ev => ev.UniqueId == ev_1h.UniqueId).DurationBasedOnDates().TotalHours); Assert.AreEqual(2, calendar.VCalendar.Events.First(ev => ev.UniqueId == ev_2h.UniqueId).DurationBasedOnDates().TotalHours); Assert.AreEqual(3, calendar.VCalendar.Events.First(ev => ev.UniqueId == ev_3h.UniqueId).DurationBasedOnDates().TotalHours); // filter out all-day events EventManager em = new EventManager(calendar); em.Filter(new FilteringOptions("lt=60&mt=60")); IList <EWSoftware.PDI.Objects.VEvent> eventsAfterFiltering = em.GetEventList(); Assert.AreEqual(1, eventsAfterFiltering.First(ev => ev.UniqueId == ev_1h.UniqueId).DurationBasedOnDates().TotalHours); Assert.AreEqual(1, eventsAfterFiltering.First(ev => ev.UniqueId == ev_2h.UniqueId).DurationBasedOnDates().TotalHours); Assert.AreEqual(1, eventsAfterFiltering.First(ev => ev.UniqueId == ev_3h.UniqueId).DurationBasedOnDates().TotalHours); }
/// <summary> /// This is overridden to allow proper comparison of event objects /// </summary> /// <param name="obj">The object to which this instance is compared</param> /// <returns>Returns true if the object equals this instance, false if it does not</returns> public override bool Equals(object obj) { VEvent ev = obj as VEvent; if (ev == null) { return(false); } // The ToString() method returns a text representation of the event based on all of its settings so // it's a reliable way to tell if two instances are the same. return(this == ev || this.ToString() == ev.ToString()); }
public void SkipEventsFromProjectX() { VCalendarParser calendar = new VCalendarParser(); calendar.ParseFile("SampleCalendar.ics"); EWSoftware.PDI.Objects.VEvent ev_projectX = calendar.VCalendar.Events.AddNew(); ev_projectX.UniqueId.Value = Guid.NewGuid().ToString(); ev_projectX.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01); ev_projectX.EndDateTime.DateTimeValue = ev_projectX.StartDateTime.DateTimeValue.AddDays(1); ev_projectX.Description.Value = @"Proyecto: Project X\n\nCompletar este elemento: \nhttp://todoist.com/#project/999999999"; EWSoftware.PDI.Objects.VEvent ev_projectY = calendar.VCalendar.Events.AddNew(); ev_projectY.UniqueId.Value = Guid.NewGuid().ToString(); ev_projectY.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01).AddHours(2); ev_projectY.EndDateTime.DateTimeValue = ev_projectY.StartDateTime.DateTimeValue.AddDays(1).AddHours(-2); ev_projectY.Description.Value = @"Proyecto: Project Y\n\nCompletar este elemento: \nhttp://todoist.com/#project/999999999"; EWSoftware.PDI.Objects.VEvent ev_projectZ = calendar.VCalendar.Events.AddNew(); ev_projectZ.UniqueId.Value = Guid.NewGuid().ToString(); ev_projectZ.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01).AddHours(2); ev_projectZ.EndDateTime.DateTimeValue = ev_projectZ.StartDateTime.DateTimeValue.AddDays(1).AddHours(-2); ev_projectZ.Description.Value = @"Proyecto: Project\n\nCompletar este elemento: \nhttp://todoist.com/#project/999999999"; Assert.AreEqual(1, calendar.VCalendar.Events.Count(ev => ev.UniqueId == ev_projectX.UniqueId)); Assert.AreEqual(1, calendar.VCalendar.Events.Count(ev => ev.UniqueId == ev_projectY.UniqueId)); Assert.AreEqual(1, calendar.VCalendar.Events.Count(ev => ev.UniqueId == ev_projectZ.UniqueId)); // filter out all-day events EventManager em = new EventManager(calendar); em.Filter(new FilteringOptions("&pr=Project X")); System.Collections.Generic.IList <EWSoftware.PDI.Objects.VEvent> eventsAfterFiltering = em.GetEventList(); Assert.AreEqual(0, eventsAfterFiltering.Where(ev => ev.UniqueId == ev_projectX.UniqueId).Count()); Assert.AreEqual(1, eventsAfterFiltering.Where(ev => ev.UniqueId == ev_projectY.UniqueId).Count()); Assert.AreEqual(1, eventsAfterFiltering.Where(ev => ev.UniqueId == ev_projectZ.UniqueId).Count()); }
/// <summary> /// This is overridden to allow copying of the additional properties /// </summary> /// <param name="p">The PDI object from which the settings are to be copied</param> protected override void Clone(PDIObject p) { VEvent o = (VEvent)p; this.ClearProperties(); classification = (ClassificationProperty)o.Classification.Clone(); categories = (CategoriesProperty)o.Categories.Clone(); resources = (ResourcesProperty)o.Resources.Clone(); url = (UrlProperty)o.Url.Clone(); uid = (UniqueIdProperty)o.UniqueId.Clone(); geo = (GeographicPositionProperty)o.GeographicPosition.Clone(); lastMod = (LastModifiedProperty)o.LastModified.Clone(); dateCreated = (DateCreatedProperty)o.DateCreated.Clone(); startDate = (StartDateProperty)o.StartDateTime.Clone(); endDate = (EndDateProperty)o.EndDateTime.Clone(); dateStamp = (TimeStampProperty)o.TimeStamp.Clone(); summary = (SummaryProperty)o.Summary.Clone(); desc = (DescriptionProperty)o.Description.Clone(); location = (LocationProperty)o.Location.Clone(); priority = (PriorityProperty)o.Priority.Clone(); sequence = (SequenceProperty)o.Sequence.Clone(); transp = (TimeTransparencyProperty)o.Transparency.Clone(); rNum = (RecurrenceCountProperty)o.RecurrenceCount.Clone(); comment = (CommentProperty)o.Comment.Clone(); organizer = (OrganizerProperty)o.Organizer.Clone(); recurId = (RecurrenceIdProperty)o.RecurrenceId.Clone(); status = (StatusProperty)o.Status.Clone(); duration = (DurationProperty)o.Duration.Clone(); this.Contacts.CloneRange(o.Contacts); this.Attendees.CloneRange(o.Attendees); this.RelatedTo.CloneRange(o.RelatedTo); this.Attachments.CloneRange(o.Attachments); this.RequestStatuses.CloneRange(o.RequestStatuses); this.Alarms.CloneRange(o.Alarms); this.CustomProperties.CloneRange(o.CustomProperties); base.Clone(p); }
public void HideIfTitleContainsString() { VCalendarParser calendar = new VCalendarParser(); calendar.ParseFile("SampleCalendar.ics"); EWSoftware.PDI.Objects.VEvent ev_str1 = calendar.VCalendar.Events.AddNew(); ev_str1.UniqueId.Value = Guid.NewGuid().ToString(); ev_str1.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01); ev_str1.EndDateTime.DateTimeValue = ev_str1.StartDateTime.DateTimeValue.AddDays(1); ev_str1.Summary.Value = "this is a [hidden] event"; EWSoftware.PDI.Objects.VEvent ev_str2 = calendar.VCalendar.Events.AddNew(); ev_str2.UniqueId.Value = Guid.NewGuid().ToString(); ev_str2.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01); ev_str2.EndDateTime.DateTimeValue = ev_str2.StartDateTime.DateTimeValue.AddDays(1); ev_str2.Summary.Value = "[hidden] event too"; EWSoftware.PDI.Objects.VEvent ev_nostr = calendar.VCalendar.Events.AddNew(); ev_nostr.UniqueId.Value = Guid.NewGuid().ToString(); ev_nostr.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01).AddHours(2); ev_nostr.EndDateTime.DateTimeValue = ev_nostr.StartDateTime.DateTimeValue.AddDays(1).AddHours(-2); ev_nostr.Summary.Value = "this is not hidden"; Assert.AreEqual(1, calendar.VCalendar.Events.Count(ev => Equals(ev.UniqueId, ev_str1.UniqueId))); Assert.AreEqual(1, calendar.VCalendar.Events.Count(ev => Equals(ev.UniqueId, ev_str2.UniqueId))); Assert.AreEqual(1, calendar.VCalendar.Events.Count(ev => Equals(ev.UniqueId, ev_nostr.UniqueId))); // filter out all-day events EventManager em = new EventManager(calendar); em.Filter(new FilteringOptions("st=[hidden]")); System.Collections.Generic.IList <EWSoftware.PDI.Objects.VEvent> eventsAfterFiltering = em.GetEventList(); Assert.AreEqual(0, eventsAfterFiltering.Count(ev => ev.UniqueId == ev_str1.UniqueId)); Assert.AreEqual(0, eventsAfterFiltering.Count(ev => ev.UniqueId == ev_str2.UniqueId)); Assert.AreEqual(1, eventsAfterFiltering.Count(ev => ev.UniqueId == ev_nostr.UniqueId)); }
static void Main() { Recurrence r = new Recurrence(); int idx; Console.WriteLine("The first part will calculate instances using only the Recurrence class. All " + "instances are expressed in local time.\nPress ENTER to continue..."); Console.ReadLine(); // NOTE: The examples in the spec assume the US-Eastern time zone. Here, we're specifying the // date/times directly and everything is in local time. The recurrence engine always generates the // date/times in local time when used by itself. For time zone support, use the calendar objects as // demonstrated later on below. Console.WriteLine("Daily for 10 occurrences:"); r.StartDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Daily; r.MaximumOccurrences = 10; Console.WriteLine(r.ToStringWithStartDateTime()); foreach(DateTime dt in r) Console.WriteLine(dt); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Daily until December 24, 1997:"); // We'll re-use the same object. Just reset it first. r.Reset(); r.StartDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Daily; // Note that in the spec examples, it looks as if the end times are wrong. It shows the times in // Universal Time as it should be but if you convert the times from Universal Time to US-Eastern time // (-05:00), it cuts a few of the patterns off too early. I've adjusted those where needed. r.RecurUntil = new DateTime(1997, 12, 24, 0, 0, 0); Console.WriteLine(r.ToStringWithStartDateTime()); foreach(DateTime dt in r) Console.WriteLine(dt); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every other day - forever:"); r.Reset(); r.StartDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Daily; r.Interval = 2; Console.WriteLine(r.ToStringWithStartDateTime()); // We'll limit the output of the "forever" rules by using the InstancesBetween() method to limit the // output to a range of dates and enumerate the returned DateTimeCollection. foreach(DateTime dt in r.InstancesBetween(r.StartDateTime, new DateTime(1997, 12, 5))) Console.WriteLine(dt); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every 10 days, 5 occurrences:"); r.Reset(); r.StartDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Daily; r.Interval = 10; r.MaximumOccurrences = 5; Console.WriteLine(r.ToStringWithStartDateTime()); foreach(DateTime dt in r) Console.WriteLine(dt); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every day in January, for 3 years:"); r.Reset(); r.StartDateTime = new DateTime(1998, 1, 1, 9, 0, 0); r.Frequency = RecurFrequency.Yearly; r.RecurUntil = new DateTime(2000, 1, 31, 9, 0, 0); r.ByMonth.Add(1); // When adding days without an instance value, you can use the helper method on the collection that // takes an array of DayOfWeek values rather than constructing an array of DayInstance objects. r.ByDay.AddRange(new[] { DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday }); Console.WriteLine(r.ToStringWithStartDateTime()); foreach(DateTime dt in r) Console.WriteLine(dt); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- // Like the last one but using a DAILY frequency Console.WriteLine("Everyday in January, for 3 years:"); r.Reset(); r.StartDateTime = new DateTime(1998, 1, 1, 9, 0, 0); r.Frequency = RecurFrequency.Daily; r.RecurUntil = new DateTime(2000, 1, 31, 9, 0, 0); r.ByMonth.Add(1); Console.WriteLine(r.ToStringWithStartDateTime()); foreach(DateTime dt in r) Console.WriteLine(dt); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Weekly for 10 occurrences:"); r.Reset(); r.StartDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Weekly; r.MaximumOccurrences = 10; Console.WriteLine(r.ToStringWithStartDateTime()); foreach(DateTime dt in r) Console.WriteLine(dt); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Weekly until December 24, 1997:"); r.Reset(); r.StartDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Weekly; r.RecurUntil = new DateTime(1997, 12, 24, 0, 0, 0); Console.WriteLine(r.ToStringWithStartDateTime()); foreach(DateTime dt in r) Console.WriteLine(dt); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every other week - forever:"); r.Reset(); r.StartDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Weekly; r.Interval = 2; r.WeekStart = DayOfWeek.Sunday; Console.WriteLine(r.ToStringWithStartDateTime()); // Not forever for the test foreach(DateTime dt in r.InstancesBetween(r.StartDateTime, new DateTime(1999, 2, 10))) Console.WriteLine(dt); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Weekly on Tuesday and Thursday for 5 weeks:"); r.Reset(); r.StartDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Weekly; r.RecurUntil = new DateTime(1997, 10, 07, 0, 0, 0); r.WeekStart = DayOfWeek.Sunday; r.ByDay.AddRange(new[] { DayOfWeek.Tuesday, DayOfWeek.Thursday }); Console.WriteLine(r.ToStringWithStartDateTime()); foreach(DateTime dt in r) Console.WriteLine(dt); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- // Like the last one but using a count Console.WriteLine("Weekly on Tuesday and Thursday for 5 weeks:"); r.Reset(); r.StartDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Weekly; r.MaximumOccurrences = 10; r.WeekStart = DayOfWeek.Sunday; r.ByDay.AddRange(new[] { DayOfWeek.Tuesday, DayOfWeek.Thursday }); Console.WriteLine(r.ToStringWithStartDateTime()); foreach(DateTime dt in r) Console.WriteLine(dt); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- // NOTE: The inclusion of DTSTART in a recurrence set is a feature of the calendar objects, NOT the // recurrence engine. To include DTSTART, use a calendar object such as VEvent to generate the set // as demonstrated later on below. Console.WriteLine("Every other week on Monday, Wednesday and Friday until December 24, 1997, but " + "starting on Tuesday, September 2, 1997:"); r.Reset(); r.StartDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Weekly; r.Interval = 2; r.WeekStart = DayOfWeek.Sunday; r.RecurUntil = new DateTime(1997, 12, 24, 0, 0, 0); r.ByDay.AddRange(new[] { DayOfWeek.Monday, DayOfWeek.Wednesday, DayOfWeek.Friday }); Console.WriteLine(r.ToStringWithStartDateTime()); foreach(DateTime dt in r) Console.WriteLine(dt); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every other week on Tuesday and Thursday, for 8 occurrences:"); r.Reset(); r.StartDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Weekly; r.Interval = 2; r.WeekStart = DayOfWeek.Sunday; r.MaximumOccurrences = 8; r.ByDay.AddRange(new[] { DayOfWeek.Tuesday, DayOfWeek.Thursday }); Console.WriteLine(r.ToStringWithStartDateTime()); foreach(DateTime dt in r) Console.WriteLine(dt); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Monthly on the 1st Friday for ten occurrences:"); r.Reset(); r.StartDateTime = new DateTime(1997, 9, 5, 9, 0, 0); r.Frequency = RecurFrequency.Monthly; r.MaximumOccurrences = 10; // There are also helper methods to add single instances r.ByDay.Add(1, DayOfWeek.Friday); Console.WriteLine(r.ToStringWithStartDateTime()); foreach(DateTime dt in r) Console.WriteLine(dt); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Monthly on the 1st Friday until December 24, 1997:"); r.Reset(); r.StartDateTime = new DateTime(1997, 9, 5, 9, 0, 0); r.Frequency = RecurFrequency.Monthly; r.RecurUntil = new DateTime(1997, 12, 24, 0, 0, 0); r.ByDay.Add(1, DayOfWeek.Friday); Console.WriteLine(r.ToStringWithStartDateTime()); foreach(DateTime dt in r) Console.WriteLine(dt); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every other month on the 1st and last Sunday of the month for 10 occurrences:"); r.Reset(); r.StartDateTime = new DateTime(1997, 9, 7, 9, 0, 0); r.Frequency = RecurFrequency.Monthly; r.Interval = 2; r.MaximumOccurrences = 10; r.ByDay.AddRange(new[] { new DayInstance(1, DayOfWeek.Sunday), new DayInstance(-1, DayOfWeek.Sunday) }); Console.WriteLine(r.ToStringWithStartDateTime()); foreach(DateTime dt in r) Console.WriteLine(dt); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Monthly on the second to last Monday of the month for 6 months:"); r.Reset(); r.StartDateTime = new DateTime(1997, 9, 22, 9, 0, 0); r.Frequency = RecurFrequency.Monthly; r.MaximumOccurrences = 6; r.ByDay.Add(-2, DayOfWeek.Monday); Console.WriteLine(r.ToStringWithStartDateTime()); foreach(DateTime dt in r) Console.WriteLine(dt); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Monthly on the third to the last day of the month, forever:"); r.Reset(); r.StartDateTime = new DateTime(1997, 9, 28, 9, 0, 0); r.Frequency = RecurFrequency.Monthly; r.ByMonthDay.Add(-3); Console.WriteLine(r.ToStringWithStartDateTime()); // Not forever for the test foreach(DateTime dt in r.InstancesBetween(r.StartDateTime, new DateTime(1998, 2, 28))) Console.WriteLine(dt); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Monthly on the 2nd and 15th of the month for 10 occurrences:"); r.Reset(); r.StartDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Monthly; r.MaximumOccurrences = 10; r.ByMonthDay.AddRange(new[] { 2, 15 }); Console.WriteLine(r.ToStringWithStartDateTime()); foreach(DateTime dt in r) Console.WriteLine(dt); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Monthly on the first and last day of the month for 10 occurrences:"); r.Reset(); r.StartDateTime = new DateTime(1997, 9, 30, 9, 0, 0); r.Frequency = RecurFrequency.Monthly; r.MaximumOccurrences = 10; r.ByMonthDay.AddRange(new[] { 1, -1 }); Console.WriteLine(r.ToStringWithStartDateTime()); foreach(DateTime dt in r) Console.WriteLine(dt); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every 18 months on the 10th through 15th of the month for 10 occurrences:"); r.Reset(); r.StartDateTime = new DateTime(1997, 9, 10, 9, 0, 0); r.Frequency = RecurFrequency.Monthly; r.Interval = 18; r.MaximumOccurrences = 10; r.ByMonthDay.AddRange(new[] { 10, 11, 12, 13, 14, 15 }); Console.WriteLine(r.ToStringWithStartDateTime()); foreach(DateTime dt in r) Console.WriteLine(dt); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every Tuesday, every other month:"); r.Reset(); r.StartDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Monthly; r.Interval = 2; r.ByDay.Add(DayOfWeek.Tuesday); Console.WriteLine(r.ToStringWithStartDateTime()); // Not forever for the test foreach(DateTime dt in r.InstancesBetween(r.StartDateTime, new DateTime(1998, 4, 1))) Console.WriteLine(dt); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Yearly in June and July for 10 occurrences:"); r.Reset(); r.StartDateTime = new DateTime(1997, 6, 10, 9, 0, 0); r.Frequency = RecurFrequency.Yearly; r.MaximumOccurrences = 10; r.ByMonth.AddRange(new[] { 6, 7 }); Console.WriteLine(r.ToStringWithStartDateTime()); foreach(DateTime dt in r) Console.WriteLine(dt); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every other year in January, February, and March for 10 occurrences:"); r.Reset(); r.StartDateTime = new DateTime(1997, 3, 10, 9, 0, 0); r.Frequency = RecurFrequency.Yearly; r.Interval = 2; r.MaximumOccurrences = 10; r.ByMonth.AddRange(new[] { 1, 2, 3 }); Console.WriteLine(r.ToStringWithStartDateTime()); foreach(DateTime dt in r) Console.WriteLine(dt); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every 3rd year on the 1st, 100th and 200th day for 10 occurrences:"); r.Reset(); r.StartDateTime = new DateTime(1997, 1, 1, 9, 0, 0); r.Frequency = RecurFrequency.Yearly; r.Interval = 3; r.MaximumOccurrences = 10; r.ByYearDay.AddRange(new[] { 1, 100, 200 }); Console.WriteLine(r.ToStringWithStartDateTime()); foreach(DateTime dt in r) Console.WriteLine(dt); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every 20th Monday of the year, forever:"); r.Reset(); r.StartDateTime = new DateTime(1997, 5, 19, 9, 0, 0); r.Frequency = RecurFrequency.Yearly; r.ByDay.Add(20, DayOfWeek.Monday); Console.WriteLine(r.ToStringWithStartDateTime()); // Not forever for the test foreach(DateTime dt in r.InstancesBetween(r.StartDateTime, new DateTime(2004, 5, 19))) Console.WriteLine(dt); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Monday of week number 20 (where the default start of the week is Monday), forever:"); r.Reset(); r.StartDateTime = new DateTime(1997, 5, 12, 9, 0, 0); r.Frequency = RecurFrequency.Yearly; r.ByWeekNo.Add(20); r.ByDay.Add(DayOfWeek.Monday); Console.WriteLine(r.ToStringWithStartDateTime()); // Not forever for the test foreach(DateTime dt in r.InstancesBetween(r.StartDateTime, new DateTime(2004, 5, 19))) Console.WriteLine(dt); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every Thursday in March, forever:"); r.Reset(); r.StartDateTime = new DateTime(1997, 3, 13, 9, 0, 0); r.Frequency = RecurFrequency.Yearly; r.ByMonth.Add(3); r.ByDay.Add(DayOfWeek.Thursday); Console.WriteLine(r.ToStringWithStartDateTime()); // Not forever for the test foreach(DateTime dt in r.InstancesBetween(r.StartDateTime, new DateTime(1999, 4, 1))) Console.WriteLine(dt); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every Thursday, but only during June, July, and August, forever:"); r.Reset(); r.StartDateTime = new DateTime(1997, 6, 5, 9, 0, 0); r.Frequency = RecurFrequency.Yearly; r.ByMonth.AddRange(new[] { 6, 7, 8 }); r.ByDay.Add(DayOfWeek.Thursday); Console.WriteLine(r.ToStringWithStartDateTime()); // Not forever for the test foreach(DateTime dt in r.InstancesBetween(r.StartDateTime, new DateTime(1999, 9, 1))) Console.WriteLine(dt); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every Friday the 13th, forever:"); r.Reset(); r.StartDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Monthly; r.ByDay.Add(DayOfWeek.Friday); r.ByMonthDay.Add(13); Console.WriteLine(r.ToStringWithStartDateTime()); // Not forever for the test foreach(DateTime dt in r.InstancesBetween(r.StartDateTime, new DateTime(2003, 12, 31))) Console.WriteLine(dt); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("The first Saturday that follows the first Sunday of the month, forever:"); r.Reset(); r.StartDateTime = new DateTime(1997, 9, 13, 9, 0, 0); r.Frequency = RecurFrequency.Monthly; r.ByDay.Add(DayOfWeek.Saturday); r.ByMonthDay.AddRange(new[] { 7, 8, 9, 10, 11, 12, 13 }); Console.WriteLine(r.ToStringWithStartDateTime()); // Not forever for the test foreach(DateTime dt in r.InstancesBetween(r.StartDateTime, new DateTime(1998, 7, 1))) Console.WriteLine(dt); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every four years, the first Tuesday after a Monday in November, forever " + "(U.S. Presidential Election day):"); r.Reset(); r.StartDateTime = new DateTime(1996, 11, 5, 9, 0, 0); r.Frequency = RecurFrequency.Yearly; r.Interval = 4; r.ByMonth.Add(11); r.ByDay.Add(DayOfWeek.Tuesday); r.ByMonthDay.AddRange(new[] { 2, 3, 4, 5, 6, 7, 8 }); Console.WriteLine(r.ToStringWithStartDateTime()); // Not forever for the test foreach(DateTime dt in r.InstancesBetween(r.StartDateTime, new DateTime(2004, 11, 3))) Console.WriteLine(dt); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("The 3rd instance into the month of one of Tuesday, Wednesday or Thursday, for " + "the next 3 months:"); r.Reset(); r.StartDateTime = new DateTime(1997, 9, 4, 9, 0, 0); r.Frequency = RecurFrequency.Monthly; r.MaximumOccurrences = 3; r.BySetPos.Add(3); r.ByDay.AddRange(new[] { DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday }); Console.WriteLine(r.ToStringWithStartDateTime()); foreach(DateTime dt in r) Console.WriteLine(dt); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("The 2nd to last weekday of the month:"); r.Reset(); r.StartDateTime = new DateTime(1997, 9, 29, 9, 0, 0); r.Frequency = RecurFrequency.Monthly; r.BySetPos.Add(-2); r.ByDay.AddRange(new[] { DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday }); Console.WriteLine(r.ToStringWithStartDateTime()); // Not forever for the test foreach(DateTime dt in r.InstancesBetween(r.StartDateTime, new DateTime(1998, 9, 29))) Console.WriteLine(dt); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every 3 hours from 9:00 AM to 5:00 PM on a specific day:"); r.Reset(); r.StartDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Hourly; r.Interval = 3; r.RecurUntil = new DateTime(1997, 9, 2, 17, 0, 0); Console.WriteLine(r.ToStringWithStartDateTime()); foreach(DateTime dt in r) Console.WriteLine(dt); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every 15 minutes for 6 occurrences:"); r.Reset(); r.StartDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Minutely; r.Interval = 15; r.MaximumOccurrences = 6; Console.WriteLine(r.ToStringWithStartDateTime()); foreach(DateTime dt in r) Console.WriteLine(dt); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every hour and a half for 4 occurrences:"); r.Reset(); r.StartDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Minutely; r.Interval = 90; r.MaximumOccurrences = 4; Console.WriteLine(r.ToStringWithStartDateTime()); foreach(DateTime dt in r) Console.WriteLine(dt); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every 20 minutes from 9:00 AM to 4:40 PM every day:"); r.Reset(); r.StartDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Daily; r.ByHour.AddRange(new[] { 9, 10, 11, 12, 13, 14, 15, 16 }); r.ByMinute.AddRange( new[] { 0, 20, 40 }); Console.WriteLine(r.ToStringWithStartDateTime()); // Not forever for the test foreach(DateTime dt in r.InstancesBetween(r.StartDateTime, new DateTime(1997, 9, 4))) Console.WriteLine(dt); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- // Like the last one but with a MINUTELY frequency Console.WriteLine("Every 20 minutes from 9:00 AM to 4:40 PM every day:"); r.Reset(); r.StartDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Minutely; r.Interval = 20; r.ByHour.AddRange(new[] { 9, 10, 11, 12, 13, 14, 15, 16 }); Console.WriteLine(r.ToStringWithStartDateTime()); // Not forever for the test foreach(DateTime dt in r.InstancesBetween(r.StartDateTime, new DateTime(1997, 9, 4))) Console.WriteLine(dt); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("An example where the days generated makes a difference because of WKST:"); r.Reset(); r.StartDateTime = new DateTime(1997, 8, 5, 9, 0, 0); r.Frequency = RecurFrequency.Weekly; r.Interval = 2; r.MaximumOccurrences = 4; r.ByDay.AddRange(new[] { DayOfWeek.Tuesday, DayOfWeek.Sunday }); Console.WriteLine(r.ToStringWithStartDateTime()); foreach(DateTime dt in r) Console.WriteLine(dt); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Changing only WKST from the default MO to SU yields different results:"); r.Reset(); r.StartDateTime = new DateTime(1997, 8, 5, 9, 0, 0); r.Frequency = RecurFrequency.Weekly; r.Interval = 2; r.MaximumOccurrences = 4; r.WeekStart = DayOfWeek.Sunday; r.ByDay.AddRange(new[] { DayOfWeek.Tuesday, DayOfWeek.Sunday }); Console.WriteLine(r.ToStringWithStartDateTime()); foreach(DateTime dt in r) Console.WriteLine(dt); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- // Now do the same one but use the calendar classes to demonstrate the time zone abilities Console.WriteLine("\n\nThe next part will calculate instances using the calendar classes with " + "time zone support.\nPress ENTER to continue..."); Console.ReadLine(); // First, set up the time zone information. If you don't care about the time zone, you can skip this // stuff and everything will be calculated in local time. VTimeZone vtz = new VTimeZone(); vtz.TimeZoneId.Value = "US-Eastern"; // Set the standard time observance rule ObservanceRule obr = vtz.ObservanceRules.Add(ObservanceRuleType.Standard); obr.StartDateTime.DateTimeValue = new DateTime(1970, 10, 25, 2, 0, 0); obr.OffsetFrom.TimeSpanValue = TimeSpan.FromHours(-4); obr.OffsetTo.TimeSpanValue = TimeSpan.FromHours(-5); RRuleProperty rrule = new RRuleProperty(); rrule.Recurrence.RecurYearly(DayOccurrence.Last, DaysOfWeek.Sunday, 10, 1); obr.RecurrenceRules.Add(rrule); obr.TimeZoneNames.Add("Eastern Standard Time"); // Set the daylight saving time observance rule obr = vtz.ObservanceRules.Add(ObservanceRuleType.Daylight); obr.StartDateTime.DateTimeValue = new DateTime(1970, 4, 5, 2, 0, 0); obr.OffsetFrom.TimeSpanValue = TimeSpan.FromHours(-5); obr.OffsetTo.TimeSpanValue = TimeSpan.FromHours(-4); rrule = new RRuleProperty(); rrule.Recurrence.RecurYearly(DayOccurrence.First, DaysOfWeek.Sunday, 4, 1); obr.RecurrenceRules.Add(rrule); obr.TimeZoneNames.Add("Eastern Daylight Time"); VCalendar.TimeZones.Add(vtz); // Now we'll set up an event to use for the calculations. We don't need a VCalendar object as we are // just generating recurring instances. VEvent vevent = new VEvent(); // Add an RRULE property rrule = new RRuleProperty(); vevent.RecurrenceRules.Add(rrule); // Get a reference to the recurrence rule property's recurrence and the event's start date property // for convenience. r = rrule.Recurrence; StartDateProperty startDateTime = vevent.StartDateTime; // Set the time zone of the event's start date to the same ID used for the time zone component above vevent.StartDateTime.TimeZoneId = "US-Eastern"; //----------------------------------------------------------------- Console.WriteLine("Daily for 10 occurrences:"); // The start date is set on the event. We use the TimeZoneDateTime property to indicate that the // date/time is in the time zone. Using DateTimeValue instead would convert the value from local // time to the time zone. startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Daily; r.MaximumOccurrences = 10; // Get the instances expressed in the time zone's time and in local time DateTimeInstanceCollection dtiTZ = vevent.AllInstances(false); DateTimeInstanceCollection dtiLocal = vevent.AllInstances(true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); // We'll just display the start time from each instance. End time and duration info is also present // in the returned instances. for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Daily until December 24, 1997:"); // We'll re-use the same recurrence object. Just reset it first. r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Daily; // Note that the recurrence rules in an event determine the end date of the event, NOT the EndDate // (DTEND) property of the event. The end date property on the event simply determines the duration // of each instance. Another thing to remember is that RecurUntil is specified in Universal Time // which ends up in local time when recurrence instances are generated. If specify times in another // time zone, be sure to set the RecurUntil time as a time in that time zone. r.RecurUntil = new DateTime(1997, 12, 24, 5, 0, 0).ToLocalTime(); dtiTZ = vevent.AllInstances(false); dtiLocal = vevent.AllInstances(true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every other day - forever:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Daily; r.Interval = 2; // We'll limit the output of the "forever" rules by using the InstancesBetween() method to limit the // output to a range of dates and enumerate the returned DateTimeCollection. dtiTZ = vevent.InstancesBetween(startDateTime.TimeZoneDateTime, new DateTime(1997, 12, 5), false); // For local time, the start and end date must be in local time. To match the range in the prior // call, we use the DateTimeValue property of the start date property and convert a value in // Universal Time to local time. dtiLocal = vevent.InstancesBetween(startDateTime.DateTimeValue, new DateTime(1997, 12, 5, 5, 0, 0).ToLocalTime(), true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every 10 days, 5 occurrences:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Daily; r.Interval = 10; r.MaximumOccurrences = 5; dtiTZ = vevent.AllInstances(false); dtiLocal = vevent.AllInstances(true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Everyday in January, for 3 years:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1998, 1, 1, 9, 0, 0); r.Frequency = RecurFrequency.Yearly; r.RecurUntil = new DateTime(2000, 1, 31, 14, 0, 0).ToLocalTime(); r.ByMonth.Add(1); // When adding days without an instance value, you can use the helper method on the collection that // takes an array of DayOfWeek values rather than constructing an array of DayInstance objects. r.ByDay.AddRange(new[] { DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday }); dtiTZ = vevent.AllInstances(false); dtiLocal = vevent.AllInstances(true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- // Like the last one but using a DAILY frequency Console.WriteLine("Everyday in January, for 3 years:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1998, 1, 1, 9, 0, 0); r.Frequency = RecurFrequency.Daily; r.RecurUntil = new DateTime(2000, 1, 31, 14, 0, 0).ToLocalTime(); r.ByMonth.Add(1); dtiTZ = vevent.AllInstances(false); dtiLocal = vevent.AllInstances(true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Weekly for 10 occurrences:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Weekly; r.MaximumOccurrences = 10; dtiTZ = vevent.AllInstances(false); dtiLocal = vevent.AllInstances(true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Weekly until December 24, 1997:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Weekly; r.RecurUntil = new DateTime(1997, 12, 24, 5, 0, 0).ToLocalTime(); dtiTZ = vevent.AllInstances(false); dtiLocal = vevent.AllInstances(true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every other week - forever:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Weekly; r.Interval = 2; r.WeekStart = DayOfWeek.Sunday; // Not forever for the test dtiTZ = vevent.InstancesBetween(startDateTime.TimeZoneDateTime, new DateTime(1999, 2, 10), false); dtiLocal = vevent.InstancesBetween(startDateTime.DateTimeValue, new DateTime(1999, 2, 10, 5, 0, 0).ToLocalTime(), true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Weekly on Tuesday and Thursday for 5 weeks:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Weekly; r.RecurUntil = new DateTime(1997, 10, 07, 4, 0, 0).ToLocalTime(); r.WeekStart = DayOfWeek.Sunday; r.ByDay.AddRange(new [] { DayOfWeek.Tuesday, DayOfWeek.Thursday }); dtiTZ = vevent.AllInstances(false); dtiLocal = vevent.AllInstances(true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- // Like the last one but using a count Console.WriteLine("Weekly on Tuesday and Thursday for 5 weeks:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Weekly; r.MaximumOccurrences = 10; r.WeekStart = DayOfWeek.Sunday; r.ByDay.AddRange(new[] { DayOfWeek.Tuesday, DayOfWeek.Thursday }); dtiTZ = vevent.AllInstances(false); dtiLocal = vevent.AllInstances(true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- // The inclusion of DTSTART in a recurrence set is a feature of the calendar objects, NOT the // recurrence engine. So, for this example, the start date will be included. Console.WriteLine("Every other week on Monday, Wednesday and Friday until December 24, 1997, but " + "starting on Tuesday, September 2, 1997:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Weekly; r.Interval = 2; r.WeekStart = DayOfWeek.Sunday; r.RecurUntil = new DateTime(1997, 12, 24, 5, 0, 0).ToLocalTime(); r.ByDay.AddRange(new[] { DayOfWeek.Monday, DayOfWeek.Wednesday, DayOfWeek.Friday }); dtiTZ = vevent.AllInstances(false); dtiLocal = vevent.AllInstances(true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every other week on Tuesday and Thursday, for 8 occurrences:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Weekly; r.Interval = 2; r.WeekStart = DayOfWeek.Sunday; r.MaximumOccurrences = 8; r.ByDay.AddRange(new[] { DayOfWeek.Tuesday, DayOfWeek.Thursday }); dtiTZ = vevent.AllInstances(false); dtiLocal = vevent.AllInstances(true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Monthly on the 1st Friday for ten occurrences:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 5, 9, 0, 0); r.Frequency = RecurFrequency.Monthly; r.MaximumOccurrences = 10; // There are also helper methods to add single instances r.ByDay.Add(1, DayOfWeek.Friday); dtiTZ = vevent.AllInstances(false); dtiLocal = vevent.AllInstances(true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Monthly on the 1st Friday until December 24, 1997:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 5, 9, 0, 0); r.Frequency = RecurFrequency.Monthly; r.RecurUntil = new DateTime(1997, 12, 24, 5, 0, 0).ToLocalTime(); r.ByDay.Add(1, DayOfWeek.Friday); dtiTZ = vevent.AllInstances(false); dtiLocal = vevent.AllInstances(true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every other month on the 1st and last Sunday of the month for 10 occurrences:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 7, 9, 0, 0); r.Frequency = RecurFrequency.Monthly; r.Interval = 2; r.MaximumOccurrences = 10; r.ByDay.AddRange(new[] { new DayInstance(1, DayOfWeek.Sunday), new DayInstance(-1, DayOfWeek.Sunday) }); dtiTZ = vevent.AllInstances(false); dtiLocal = vevent.AllInstances(true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Monthly on the second to last Monday of the month for 6 months:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 22, 9, 0, 0); r.Frequency = RecurFrequency.Monthly; r.MaximumOccurrences = 6; r.ByDay.Add(-2, DayOfWeek.Monday); dtiTZ = vevent.AllInstances(false); dtiLocal = vevent.AllInstances(true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Monthly on the third to the last day of the month, forever:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 28, 9, 0, 0); r.Frequency = RecurFrequency.Monthly; r.ByMonthDay.Add(-3); // Not forever for the test dtiTZ = vevent.InstancesBetween(startDateTime.TimeZoneDateTime, new DateTime(1998, 2, 28), false); dtiLocal = vevent.InstancesBetween(startDateTime.DateTimeValue, new DateTime(1998, 2, 28, 5, 0, 0).ToLocalTime(), true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Monthly on the 2nd and 15th of the month for 10 occurrences:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Monthly; r.MaximumOccurrences = 10; r.ByMonthDay.AddRange(new[] { 2, 15 }); dtiTZ = vevent.AllInstances(false); dtiLocal = vevent.AllInstances(true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Monthly on the first and last day of the month for 10 occurrences:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 30, 9, 0, 0); r.Frequency = RecurFrequency.Monthly; r.MaximumOccurrences = 10; r.ByMonthDay.AddRange(new[] { 1, -1 }); dtiTZ = vevent.AllInstances(false); dtiLocal = vevent.AllInstances(true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every 18 months on the 10th through 15th of the month for 10 occurrences:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 10, 9, 0, 0); r.Frequency = RecurFrequency.Monthly; r.Interval = 18; r.MaximumOccurrences = 10; r.ByMonthDay.AddRange(new[] { 10, 11, 12, 13, 14, 15 }); dtiTZ = vevent.AllInstances(false); dtiLocal = vevent.AllInstances(true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every Tuesday, every other month:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Monthly; r.Interval = 2; r.ByDay.Add(DayOfWeek.Tuesday); // Not forever for the test dtiTZ = vevent.InstancesBetween(startDateTime.TimeZoneDateTime, new DateTime(1998, 4, 1), false); dtiLocal = vevent.InstancesBetween(startDateTime.DateTimeValue, new DateTime(1998, 4, 1, 5, 0, 0).ToLocalTime(), true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Yearly in June and July for 10 occurrences:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 6, 10, 9, 0, 0); r.Frequency = RecurFrequency.Yearly; r.MaximumOccurrences = 10; r.ByMonth.AddRange(new[] { 6, 7 }); dtiTZ = vevent.AllInstances(false); dtiLocal = vevent.AllInstances(true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every other year in January, February, and March for 10 occurrences:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 3, 10, 9, 0, 0); r.Frequency = RecurFrequency.Yearly; r.Interval = 2; r.MaximumOccurrences = 10; r.ByMonth.AddRange(new[] { 1, 2, 3 }); dtiTZ = vevent.AllInstances(false); dtiLocal = vevent.AllInstances(true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every 3rd year on the 1st, 100th and 200th day for 10 occurrences:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 1, 1, 9, 0, 0); r.Frequency = RecurFrequency.Yearly; r.Interval = 3; r.MaximumOccurrences = 10; r.ByYearDay.AddRange(new[] { 1, 100, 200 }); dtiTZ = vevent.AllInstances(false); dtiLocal = vevent.AllInstances(true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every 20th Monday of the year, forever:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 5, 19, 9, 0, 0); r.Frequency = RecurFrequency.Yearly; r.ByDay.Add(20, DayOfWeek.Monday); // Not forever for the test dtiTZ = vevent.InstancesBetween(startDateTime.TimeZoneDateTime, new DateTime(2004, 5, 19), false); dtiLocal = vevent.InstancesBetween(startDateTime.DateTimeValue, new DateTime(2004, 5, 19, 4, 0, 0).ToLocalTime(), true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Monday of week number 20 (where the default start of the week is Monday), forever:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 5, 12, 9, 0, 0); r.Frequency = RecurFrequency.Yearly; r.ByWeekNo.Add(20); r.ByDay.Add(DayOfWeek.Monday); // Not forever for the test dtiTZ = vevent.InstancesBetween(startDateTime.TimeZoneDateTime, new DateTime(2004, 5, 19), false); dtiLocal = vevent.InstancesBetween(startDateTime.DateTimeValue, new DateTime(2004, 5, 19, 4, 0, 0).ToLocalTime(), true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every Thursday in March, forever:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 3, 13, 9, 0, 0); r.Frequency = RecurFrequency.Yearly; r.ByMonth.Add(3); r.ByDay.Add(DayOfWeek.Thursday); // Not forever for the test dtiTZ = vevent.InstancesBetween(startDateTime.TimeZoneDateTime, new DateTime(1999, 4, 1), false); dtiLocal = vevent.InstancesBetween(startDateTime.DateTimeValue, new DateTime(1999, 4, 1, 5, 0, 0).ToLocalTime(), true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every Thursday, but only during June, July, and August, forever:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 6, 5, 9, 0, 0); r.Frequency = RecurFrequency.Yearly; r.ByMonth.AddRange(new[] { 6, 7, 8 }); r.ByDay.Add(DayOfWeek.Thursday); // Not forever for the test dtiTZ = vevent.InstancesBetween(startDateTime.TimeZoneDateTime, new DateTime(1999, 9, 1), false); dtiLocal = vevent.InstancesBetween(startDateTime.DateTimeValue, new DateTime(1999, 9, 1, 4, 0, 0).ToLocalTime(), true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every Friday the 13th, forever:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Monthly; r.ByDay.Add(DayOfWeek.Friday); r.ByMonthDay.Add(13); // This one uses an EXDATE property to remove the starting date ExDateProperty exdate = vevent.ExceptionDates.Add(startDateTime.TimeZoneDateTime); exdate.TimeZoneId = startDateTime.TimeZoneId; // Not forever for the test dtiTZ = vevent.InstancesBetween(startDateTime.TimeZoneDateTime, new DateTime(2003, 12, 31), false); dtiLocal = vevent.InstancesBetween(startDateTime.DateTimeValue, new DateTime(2003, 12, 31, 5, 0, 0).ToLocalTime(), true); Console.Write(startDateTime.ToString()); Console.Write(exdate.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); // Clear the exception date vevent.ExceptionDates.Clear(); //----------------------------------------------------------------- Console.WriteLine("The first Saturday that follows the first Sunday of the month, forever:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 13, 9, 0, 0); r.Frequency = RecurFrequency.Monthly; r.ByDay.Add(DayOfWeek.Saturday); r.ByMonthDay.AddRange(new[] { 7, 8, 9, 10, 11, 12, 13 }); // Not forever for the test dtiTZ = vevent.InstancesBetween(startDateTime.TimeZoneDateTime, new DateTime(1998, 7, 1), false); dtiLocal = vevent.InstancesBetween(startDateTime.DateTimeValue, new DateTime(1998, 7, 1, 4, 0, 0).ToLocalTime(), true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every four years, the first Tuesday after a Monday in November, forever (U.S. " + "Presidential Election day):"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1996, 11, 5, 9, 0, 0); r.Frequency = RecurFrequency.Yearly; r.Interval = 4; r.ByMonth.Add(11); r.ByDay.Add(DayOfWeek.Tuesday); r.ByMonthDay.AddRange(new[] { 2, 3, 4, 5, 6, 7, 8 }); // Not forever for the test dtiTZ = vevent.InstancesBetween(startDateTime.TimeZoneDateTime, new DateTime(2004, 11, 3), false); dtiLocal = vevent.InstancesBetween(startDateTime.DateTimeValue, new DateTime(2004, 11, 3, 5, 0, 0).ToLocalTime(), true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("The 3rd instance into the month of one of Tuesday, Wednesday or Thursday, for " + "the next 3 months:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 4, 9, 0, 0); r.Frequency = RecurFrequency.Monthly; r.MaximumOccurrences = 3; r.BySetPos.Add(3); r.ByDay.AddRange(new[] { DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday }); dtiTZ = vevent.AllInstances(false); dtiLocal = vevent.AllInstances(true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("The 2nd to last weekday of the month:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 29, 9, 0, 0); r.Frequency = RecurFrequency.Monthly; r.BySetPos.Add(-2); r.ByDay.AddRange(new[] { DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday }); // Not forever for the test dtiTZ = vevent.InstancesBetween(startDateTime.TimeZoneDateTime, new DateTime(1998, 9, 29), false); dtiLocal = vevent.InstancesBetween(startDateTime.DateTimeValue, new DateTime(1998, 9, 29, 4, 0, 0).ToLocalTime(), true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every 3 hours from 9:00 AM to 5:00 PM on a specific day:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Hourly; r.Interval = 3; r.RecurUntil = new DateTime(1997, 9, 2, 21, 0, 0).ToLocalTime(); dtiTZ = vevent.AllInstances(false); dtiLocal = vevent.AllInstances(true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every 15 minutes for 6 occurrences:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Minutely; r.Interval = 15; r.MaximumOccurrences = 6; dtiTZ = vevent.AllInstances(false); dtiLocal = vevent.AllInstances(true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every hour and a half for 4 occurrences:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Minutely; r.Interval = 90; r.MaximumOccurrences = 4; dtiTZ = vevent.AllInstances(false); dtiLocal = vevent.AllInstances(true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Every 20 minutes from 9:00 AM to 4:40 PM every day:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Daily; r.ByHour.AddRange(new[] { 9, 10, 11, 12, 13, 14, 15, 16 }); r.ByMinute.AddRange( new[] { 0, 20, 40 }); // Not forever for the test dtiTZ = vevent.InstancesBetween(startDateTime.TimeZoneDateTime, new DateTime(1997, 9, 4), false); dtiLocal = vevent.InstancesBetween(startDateTime.DateTimeValue, new DateTime(1997, 9, 4, 4, 0, 0).ToLocalTime(), true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- // Like the last one but with a MINUTELY frequency Console.WriteLine("Every 20 minutes from 9:00 AM to 4:40 PM every day:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 9, 2, 9, 0, 0); r.Frequency = RecurFrequency.Minutely; r.Interval = 20; r.ByHour.AddRange(new[] { 9, 10, 11, 12, 13, 14, 15, 16 }); // Not forever for the test dtiTZ = vevent.InstancesBetween(startDateTime.TimeZoneDateTime, new DateTime(1997, 9, 4), false); dtiLocal = vevent.InstancesBetween(startDateTime.DateTimeValue, new DateTime(1997, 9, 4, 4, 0, 0).ToLocalTime(), true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("... Forever ...\nPress ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("An example where the days generated makes a difference because of WKST:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 8, 5, 9, 0, 0); r.Frequency = RecurFrequency.Weekly; r.Interval = 2; r.MaximumOccurrences = 4; r.ByDay.AddRange(new[] { DayOfWeek.Tuesday, DayOfWeek.Sunday }); dtiTZ = vevent.AllInstances(false); dtiLocal = vevent.AllInstances(true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); //----------------------------------------------------------------- Console.WriteLine("Changing only WKST from the default MO to SU yields different results:"); r.Reset(); startDateTime.TimeZoneDateTime = new DateTime(1997, 8, 5, 9, 0, 0); r.Frequency = RecurFrequency.Weekly; r.Interval = 2; r.MaximumOccurrences = 4; r.WeekStart = DayOfWeek.Sunday; r.ByDay.AddRange(new[] { DayOfWeek.Tuesday, DayOfWeek.Sunday }); dtiTZ = vevent.AllInstances(false); dtiLocal = vevent.AllInstances(true); Console.Write(startDateTime.ToString()); Console.Write(rrule.ToString()); for(idx = 0; idx < dtiTZ.Count; idx++) Console.WriteLine("TZ: {0:G} {1} Local: {2:G} {3}", dtiTZ[idx].StartDateTime, dtiTZ[idx].AbbreviatedStartTimeZoneName, dtiLocal[idx].StartDateTime, dtiLocal[idx].AbbreviatedStartTimeZoneName); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); }
//===================================================================== /// <summary> /// This is overridden to allow cloning of a PDI object /// </summary> /// <returns>A clone of the object</returns> public override object Clone() { VEvent o = new VEvent(); o.Clone(this); return o; }
/// <summary> /// Add a calendar item /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void btnAdd_Click(object sender, EventArgs e) { switch(cboComponents.SelectedIndex) { case 0: using(CalendarObjectDlg dlg = new CalendarObjectDlg()) { VEvent evt = new VEvent(); evt.UniqueId.AssignNewId(true); evt.DateCreated.TimeZoneDateTime = DateTime.Now; evt.LastModified.TimeZoneDateTime = evt.DateCreated.TimeZoneDateTime; dlg.SetValues(evt); if(dlg.ShowDialog() == DialogResult.OK) { dlg.GetValues(evt); // Create a unique ID for the new item evt.UniqueId.AssignNewId(true); vCal.Events.Add(evt); } } break; case 1: using(CalendarObjectDlg dlg = new CalendarObjectDlg()) { VToDo td = new VToDo(); td.DateCreated.TimeZoneDateTime = DateTime.Now; td.LastModified.TimeZoneDateTime = td.DateCreated.TimeZoneDateTime; dlg.SetValues(td); if(dlg.ShowDialog() == DialogResult.OK) { dlg.GetValues(td); // Create a unique ID for the new item td.UniqueId.AssignNewId(true); vCal.ToDos.Add(td); } } break; case 2: using(CalendarObjectDlg dlg = new CalendarObjectDlg()) { VJournal j = new VJournal(); j.DateCreated.TimeZoneDateTime = DateTime.Now; j.LastModified.TimeZoneDateTime = j.DateCreated.TimeZoneDateTime; dlg.SetValues(j); if(dlg.ShowDialog() == DialogResult.OK) { dlg.GetValues(j); // Create a unique ID for the new item j.UniqueId.AssignNewId(true); vCal.Journals.Add(j); } } break; case 3: using(VFreeBusyDlg dlg = new VFreeBusyDlg()) { if(dlg.ShowDialog() == DialogResult.OK) { VFreeBusy fb = new VFreeBusy(); dlg.GetValues(fb); // Create a unique ID for the new item fb.UniqueId.AssignNewId(true); vCal.FreeBusys.Add(fb); } } break; } }
/// <summary> /// Store event information from the controls /// </summary> /// <param name="ev">The event to use</param> private bool StoreEventInfo(VEvent ev) { DateTime startDate = DateTime.MinValue, endDate = DateTime.MinValue; Duration dur = Duration.Zero; lblMsg.Text = null; // Perform some edits if(txtStartDate.Text.Trim().Length != 0 && !DateTime.TryParse(txtStartDate.Text, CultureInfo.CurrentCulture, DateTimeStyles.None, out startDate)) lblMsg.Text = "Invalid start date format<br>"; if(txtEndDate.Text.Trim().Length != 0 && !DateTime.TryParse(txtEndDate.Text, CultureInfo.CurrentCulture, DateTimeStyles.None, out endDate)) lblMsg.Text = "Invalid end date format<br>"; if(txtDuration.Text.Trim().Length != 0 && !Duration.TryParse(txtDuration.Text, out dur)) lblMsg.Text += "Invalid duration format<br>"; if(dur != Duration.Zero && txtEndDate.Enabled && endDate != DateTime.MinValue) lblMsg.Text += "A duration or an end date can be specified, but not both<br>"; if(txtEndDate.Enabled && startDate != DateTime.MinValue && endDate != DateTime.MinValue && startDate > endDate) lblMsg.Text += "Start date must be less than or equal to end date<br>"; if(!String.IsNullOrWhiteSpace(lblMsg.Text)) return false; // Unique ID is not changed ev.Transparency.IsTransparent = chkTransparent.Checked; ev.LastModified.TimeZoneDateTime = DateTime.Now; if(txtSequence.Text.Trim().Length == 0) ev.Sequence.SequenceNumber = 0; else ev.Sequence.SequenceNumber = Convert.ToInt32(txtSequence.Text); if(txtPriority.Text.Trim().Length == 0) ev.Priority.PriorityValue = 0; else ev.Priority.PriorityValue = Convert.ToInt32(txtPriority.Text); ev.StartDateTime.TimeZoneDateTime = startDate; ev.StartDateTime.ValueLocation = ValLocValue.DateTime; ev.EndDateTime.TimeZoneDateTime = endDate; ev.EndDateTime.ValueLocation = ValLocValue.DateTime; ev.Duration.DurationValue = dur; ev.Summary.Value = txtSummary.Text; ev.Location.Value = txtLocation.Text; ev.Description.Value = txtDescription.Text; ev.Organizer.Value = txtOrganizer.Text; ev.Url.Value = txtUrl.Text; ev.Comment.Value = txtComments.Text; // Get status value ev.Status.StatusValue = (StatusValue)Enum.Parse(typeof(StatusValue), cboStatus.Items[cboStatus.SelectedIndex].ToString(), true); return true; }
/// <summary> /// Load event information into the controls /// </summary> /// <param name="ev">The event to use</param> private void LoadEventInfo(VEvent ev) { txtCompleted.Enabled = txtPercent.Enabled = false; lblEndDate.Text = "End"; lblUniqueId.Text = ev.UniqueId.Value; lblTimeZone.Text = ev.StartDateTime.TimeZoneId; chkTransparent.Checked = ev.Transparency.IsTransparent; txtSequence.Text = ev.Sequence.SequenceNumber.ToString(); txtPriority.Text = ev.Priority.PriorityValue.ToString(); // General if(ev.StartDateTime.TimeZoneDateTime != DateTime.MinValue) txtStartDate.Text = ev.StartDateTime.TimeZoneDateTime.ToString("G"); if(ev.EndDateTime.TimeZoneDateTime != DateTime.MinValue) txtEndDate.Text = ev.EndDateTime.TimeZoneDateTime.ToString("G"); if(ev.Duration.DurationValue != Duration.Zero) txtDuration.Text = ev.Duration.DurationValue. ToString(Duration.MaxUnit.Weeks); txtSummary.Text = ev.Summary.Value; txtLocation.Text = ev.Location.Value; txtDescription.Text = ev.Description.Value; txtOrganizer.Text = ev.Organizer.Value; txtUrl.Text = ev.Url.Value; txtComments.Text = ev.Comment.Value; // Load status values and set status cboStatus.Items.Add("None"); cboStatus.Items.Add("Tentative"); cboStatus.Items.Add("Confirmed"); cboStatus.Items.Add("Cancelled"); if(cboStatus.Items.FindByValue(ev.Status.StatusValue.ToString()) == null) cboStatus.Items.Add(ev.Status.StatusValue.ToString()); cboStatus.SelectedValue = ev.Status.StatusValue.ToString(); dgAttendees.DataSource = ev.Attendees; dgRecurrences.DataSource = ev.RecurrenceRules; dgRecurDates.DataSource = ev.RecurDates; dgExceptions.DataSource = ev.ExceptionRules; dgExDates.DataSource = ev.ExceptionDates; dgReqStats.DataSource = ev.RequestStatuses; }
/// <summary> /// This is implemented to handle properties related to VEvent items /// </summary> /// <param name="propertyName">The name of the property</param> /// <param name="parameters">A string collection containing the parameters and their values. If empty, /// there are no parameters.</param> /// <param name="propertyValue">The value of the property.</param> protected virtual void VEventParser(string propertyName, StringCollection parameters, string propertyValue) { StringCollection sc; string[] parts, parms; int idx; // The last entry is always CustomProperty so scan for length minus one for(idx = 0; idx < ntvEvent.Length - 1; idx++) if(ntvEvent[idx].IsMatch(propertyName)) break; // An opening BEGIN:VEVENT property must have been seen if(vEvent == null) throw new PDIParserException(this.LineNumber, LR.GetString("ExParseNoBeginProp", "BEGIN:VEVENT", propertyName)); // Handle or create the property switch(ntvEvent[idx].EnumValue) { case PropertyType.Begin: // Handle nested objects priorState.Push(currentState); // Is it an alarm? if(String.Compare(propertyValue.Trim(), "VALARM", StringComparison.OrdinalIgnoreCase) == 0) { vAlarm = new VAlarm(); vEvent.Alarms.Add(vAlarm); currentState = VCalendarParserState.VAlarm; } else { // Unknown/custom object currentState = VCalendarParserState.Custom; CustomObjectParser(propertyName, parameters, propertyValue); } break; case PropertyType.End: // For this, the value must be VEVENT if(String.Compare(propertyValue.Trim(), "VEVENT", StringComparison.OrdinalIgnoreCase) != 0) throw new PDIParserException(this.LineNumber, LR.GetString("ExParseUnrecognizedTagValue", ntvEvent[idx].Name, propertyValue)); // The event is added to the collection when created so we don't have to rely on an END tag // to add it. vEvent = null; currentState = priorState.Pop(); break; case PropertyType.Class: vEvent.Classification.EncodedValue = propertyValue; break; case PropertyType.Categories: // If this is seen more than once, just add the new stuff to the existing property CategoriesProperty cp = new CategoriesProperty(); cp.DeserializeParameters(parameters); cp.EncodedValue = propertyValue; foreach(string s in cp.Categories) vEvent.Categories.Categories.Add(s); break; case PropertyType.Resources: // If this is seen more than once, just add the new stuff to the existing property ResourcesProperty rp = new ResourcesProperty(); rp.DeserializeParameters(parameters); rp.EncodedValue = propertyValue; foreach(string s in rp.Resources) vEvent.Resources.Resources.Add(s); break; case PropertyType.Url: vEvent.Url.DeserializeParameters(parameters); vEvent.Url.EncodedValue = propertyValue; break; case PropertyType.UniqueId: vEvent.UniqueId.EncodedValue = propertyValue; break; case PropertyType.LastModified: vEvent.LastModified.DeserializeParameters(parameters); vEvent.LastModified.EncodedValue = propertyValue; break; case PropertyType.GeographicPosition: vEvent.GeographicPosition.EncodedValue = propertyValue; break; case PropertyType.DateCreated: vEvent.DateCreated.DeserializeParameters(parameters); vEvent.DateCreated.EncodedValue = propertyValue; break; case PropertyType.StartDateTime: vEvent.StartDateTime.DeserializeParameters(parameters); vEvent.StartDateTime.EncodedValue = propertyValue; break; case PropertyType.EndDateTime: vEvent.EndDateTime.DeserializeParameters(parameters); vEvent.EndDateTime.EncodedValue = propertyValue; break; case PropertyType.TimeStamp: vEvent.TimeStamp.DeserializeParameters(parameters); vEvent.TimeStamp.EncodedValue = propertyValue; break; case PropertyType.Summary: vEvent.Summary.DeserializeParameters(parameters); vEvent.Summary.EncodedValue = propertyValue; break; case PropertyType.Description: vEvent.Description.DeserializeParameters(parameters); vEvent.Description.EncodedValue = propertyValue; break; case PropertyType.Location: vEvent.Location.DeserializeParameters(parameters); vEvent.Location.EncodedValue = propertyValue; break; case PropertyType.Priority: vEvent.Priority.DeserializeParameters(parameters); vEvent.Priority.EncodedValue = propertyValue; break; case PropertyType.Sequence: vEvent.Sequence.DeserializeParameters(parameters); vEvent.Sequence.EncodedValue = propertyValue; break; case PropertyType.Transparency: vEvent.Transparency.DeserializeParameters(parameters); vEvent.Transparency.EncodedValue = propertyValue; break; case PropertyType.RecurrenceCount: vEvent.RecurrenceCount.DeserializeParameters(parameters); vEvent.RecurrenceCount.EncodedValue = propertyValue; break; case PropertyType.Comment: // If this is seen more than once, just add the new stuff to the existing property if(vEvent.Comment.Value != null) { vEvent.Comment.EncodedValue += "\r\n"; vEvent.Comment.EncodedValue += propertyValue; } else { vEvent.Comment.DeserializeParameters(parameters); vEvent.Comment.EncodedValue = propertyValue; } break; case PropertyType.Contact: ContactProperty c = new ContactProperty(); c.DeserializeParameters(parameters); c.EncodedValue = propertyValue; vEvent.Contacts.Add(c); break; case PropertyType.Organizer: vEvent.Organizer.DeserializeParameters(parameters); vEvent.Organizer.EncodedValue = propertyValue; break; case PropertyType.Attendee: AttendeeProperty ap = new AttendeeProperty(); ap.DeserializeParameters(parameters); ap.EncodedValue = propertyValue; vEvent.Attendees.Add(ap); break; case PropertyType.RelatedTo: RelatedToProperty rt = new RelatedToProperty(); rt.DeserializeParameters(parameters); rt.EncodedValue = propertyValue; vEvent.RelatedTo.Add(rt); break; case PropertyType.Attachment: AttachProperty att = new AttachProperty(); att.DeserializeParameters(parameters); att.EncodedValue = propertyValue; vEvent.Attachments.Add(att); break; case PropertyType.RecurrenceId: vEvent.RecurrenceId.DeserializeParameters(parameters); vEvent.RecurrenceId.EncodedValue = propertyValue; break; case PropertyType.Status: vEvent.Status.DeserializeParameters(parameters); vEvent.Status.EncodedValue = propertyValue; break; case PropertyType.RequestStatus: RequestStatusProperty rs = new RequestStatusProperty(); rs.DeserializeParameters(parameters); rs.EncodedValue = propertyValue; vEvent.RequestStatuses.Add(rs); break; case PropertyType.Duration: vEvent.Duration.DeserializeParameters(parameters); vEvent.Duration.EncodedValue = propertyValue; break; case PropertyType.AudioAlarm: case PropertyType.DisplayAlarm: case PropertyType.EMailAlarm: case PropertyType.ProcedureAlarm: // These are converted to a VAlarm object vAlarm = new VAlarm(); ParseVCalendarAlarm(ntvEvent[idx].EnumValue, parameters, propertyValue); vEvent.Alarms.Add(vAlarm); vAlarm = null; break; case PropertyType.RecurrenceRule: RRuleProperty rr = new RRuleProperty(); rr.DeserializeParameters(parameters); rr.EncodedValue = propertyValue; vEvent.RecurrenceRules.Add(rr); break; case PropertyType.RecurDate: // There may be more than one date in the value. If so, split them into separate ones. This // makes it easier to manage. They'll get written back out as individual properties but // that's okay. parts = propertyValue.Split(',', ';'); // It's important that we retain the same parameters for each one parms = new string[parameters.Count]; parameters.CopyTo(parms, 0); foreach(string s in parts) { sc = new StringCollection(); sc.AddRange(parms); RDateProperty rd = new RDateProperty(); rd.DeserializeParameters(sc); rd.EncodedValue = s; vEvent.RecurDates.Add(rd); } break; case PropertyType.ExceptionRule: ExRuleProperty er = new ExRuleProperty(); er.DeserializeParameters(parameters); er.EncodedValue = propertyValue; vEvent.ExceptionRules.Add(er); break; case PropertyType.ExceptionDate: // There may be more than one date in the value. If so, split them into separate ones. This // makes it easier to manage. They'll get written back out as individual properties but // that's okay. parts = propertyValue.Split(',', ';'); // It's important that we retain the same parameters for each one parms = new string[parameters.Count]; parameters.CopyTo(parms, 0); foreach(string s in parts) { sc = new StringCollection(); sc.AddRange(parms); ExDateProperty ed = new ExDateProperty(); ed.DeserializeParameters(sc); ed.EncodedValue = s; vEvent.ExceptionDates.Add(ed); } break; case PropertyType.ExcludeStartDateTime: // This is a custom property not defined by the spec vEvent.ExcludeStartDateTime = (propertyValue[0] == '1'); break; default: // Anything else is a custom property CustomProperty cust = new CustomProperty(propertyName); cust.DeserializeParameters(parameters); cust.EncodedValue = propertyValue; vEvent.CustomProperties.Add(cust); break; } }
/// <summary> /// This is implemented to handle properties as they are parsed from the data stream /// </summary> /// <param name="propertyName">The name of the property.</param> /// <param name="parameters">A string collection containing the parameters and their values. If empty, /// there are no parameters.</param> /// <param name="propertyValue">The value of the property.</param> /// <remarks><para>There may be a mixture of name/value pairs or values alone in the parameters string /// collection. It is up to the derived class to process the parameter list based on the specification /// to which it conforms. For entries that are parameter names, the entry immediately following it in /// the collection is its associated parameter value. The property name, parameter names, and their /// values may be in upper, lower, or mixed case.</para> /// /// <para>The value may be an encoded string. The properties are responsible for any decoding that may /// need to occur (i.e. base 64 encoded image data).</para></remarks> /// <exception cref="PDIParserException">This is thrown if an error is encountered while parsing the data /// stream. Refer to the and inner exceptions for information on the cause of the problem.</exception> protected override void PropertyParser(string propertyName, StringCollection parameters, string propertyValue) { SpecificationVersions version = SpecificationVersions.None; string temp; int idx; // Is it parsing a sub-object? if(currentState != VCalendarParserState.VCalendar) { switch(currentState) { case VCalendarParserState.VEvent: VEventParser(propertyName, parameters, propertyValue); break; case VCalendarParserState.VToDo: VToDoParser(propertyName, parameters, propertyValue); break; case VCalendarParserState.VJournal: VJournalParser(propertyName, parameters, propertyValue); break; case VCalendarParserState.VAlarm: VAlarmParser(propertyName, parameters, propertyValue); break; case VCalendarParserState.VFreeBusy: VFreeBusyParser(propertyName, parameters, propertyValue); break; case VCalendarParserState.VTimeZone: VTimeZoneParser(propertyName, parameters, propertyValue); break; case VCalendarParserState.ObservanceRule: ObservanceRuleParser(propertyName, parameters, propertyValue); break; case VCalendarParserState.Custom: CustomObjectParser(propertyName, parameters, propertyValue); break; } return; } // The last entry is always CustomProperty so scan for length minus one for(idx = 0; idx < ntvCal.Length - 1; idx++) if(ntvCal[idx].IsMatch(propertyName)) break; // An opening BEGIN:VCALENDAR property must have been seen if(vCal == null && ntvCal[idx].EnumValue != PropertyType.Begin) throw new PDIParserException(this.LineNumber, LR.GetString("ExParseNoBeginProp", "BEGIN:VCALENDAR", propertyName)); // Handle or create the property switch(ntvCal[idx].EnumValue) { case PropertyType.Begin: // Start a new object temp = propertyValue.Trim(); // The last entry is always Custom so scan for length - 1 for(idx = 0; idx < ntvObjs.Length - 1; idx++) if(ntvObjs[idx].IsMatch(temp)) break; priorState.Push(currentState); currentState = ntvObjs[idx].EnumValue; switch(currentState) { case VCalendarParserState.VCalendar: // NOTE: If serializing into an existing instance, this may not be null. If so, it // is ignored. It may also exist if two calendars appear in the same file. In that // case, they will be merged into one calendar. if(vCal == null) vCal = new VCalendar(); break; case VCalendarParserState.VEvent: vEvent = new VEvent(); vCal.Events.Add(vEvent); break; case VCalendarParserState.VToDo: vToDo = new VToDo(); vCal.ToDos.Add(vToDo); break; case VCalendarParserState.VJournal: vJournal = new VJournal(); vCal.Journals.Add(vJournal); break; case VCalendarParserState.VFreeBusy: vFreeBusy = new VFreeBusy(); vCal.FreeBusys.Add(vFreeBusy); break; case VCalendarParserState.VTimeZone: // NOTE: Unlike the other objects, time zone are not added to the collection until // the END Tag is encountered as they are shared amongst all calendar instances. vTimeZone = new VTimeZone(); break; case VCalendarParserState.Custom: CustomObjectParser(propertyName, parameters, propertyValue); break; } break; case PropertyType.End: // The value must be VCALENDAR if(String.Compare(propertyValue.Trim(), "VCALENDAR", StringComparison.OrdinalIgnoreCase) != 0) throw new PDIParserException(this.LineNumber, LR.GetString("ExParseUnrecognizedTagValue", ntvCal[idx].Name, propertyValue)); // When done, we'll propagate the version number to all objects to make it consistent vCal.PropagateVersion(); break; case PropertyType.Version: // Version must be 1.0 or 2.0 temp = propertyValue.Trim(); if(temp == "1.0") version = SpecificationVersions.vCalendar10; else if(temp == "2.0") version = SpecificationVersions.iCalendar20; else throw new PDIParserException(this.LineNumber, LR.GetString("ExParseUnrecognizedVersion", "vCalendar/iCalendar", temp)); vCal.Version = version; break; case PropertyType.ProductId: vCal.ProductId.EncodedValue = propertyValue; break; case PropertyType.CalendarScale: vCal.CalendarScale.DeserializeParameters(parameters); vCal.CalendarScale.EncodedValue = propertyValue; break; case PropertyType.Method: vCal.Method.DeserializeParameters(parameters); vCal.Method.EncodedValue = propertyValue; break; case PropertyType.GeographicPosition: vCal.VCalendarGeographicPosition.EncodedValue = propertyValue; break; case PropertyType.TimeZone: vCal.VCalendarTimeZone.DeserializeParameters(parameters); vCal.VCalendarTimeZone.EncodedValue = propertyValue; break; case PropertyType.Daylight: vCal.VCalendarDaylightRule.DeserializeParameters(parameters); vCal.VCalendarDaylightRule.EncodedValue = propertyValue; break; default: // Anything else is a custom property CustomProperty c = new CustomProperty(propertyName); c.DeserializeParameters(parameters); c.EncodedValue = propertyValue; vCal.CustomProperties.Add(c); break; } }
//===================================================================== /// <summary> /// This is overridden to handle the additional state maintained by the calendar parser /// </summary> /// <param name="fullReset">If true, a full reset is done (i.e. this is the start of a brand new session. /// If false only the line state is reset (it's done parsing a property name or value).</param> protected override void ResetState(bool fullReset) { if(fullReset) { currentState = VCalendarParserState.VCalendar; vEvent = null; vToDo = null; vJournal = null; vAlarm = null; vFreeBusy = null; vTimeZone = null; obsRule = null; priorState.Clear(); beginValue.Clear(); } base.ResetState(fullReset); }