Exemple #1
0
        public void GOOGLE1()
        {
            TZID      tzid = "Europe/Berlin";
            iCalendar iCal = iCalendar.LoadFromFile(@"Calendars/General/GoogleCalendar.ics");
            Event     evt  = iCal.Events["*****@*****.**"];

            Assert.IsNotNull(evt);

            Date_Time         dtStart     = new Date_Time(2006, 12, 18, tzid, iCal);
            Date_Time         dtEnd       = new Date_Time(2006, 12, 23, tzid, iCal);
            List <Occurrence> occurrences = iCal.GetOccurrences(dtStart, dtEnd);

            Date_Time[] DateTimes = new Date_Time[]
            {
                new Date_Time(2006, 12, 18, 7, 0, 0, tzid, iCal),
                new Date_Time(2006, 12, 19, 7, 0, 0, tzid, iCal),
                new Date_Time(2006, 12, 20, 7, 0, 0, tzid, iCal),
                new Date_Time(2006, 12, 21, 7, 0, 0, tzid, iCal),
                new Date_Time(2006, 12, 22, 7, 0, 0, tzid, iCal)
            };

            for (int i = 0; i < DateTimes.Length; i++)
            {
                Assert.AreEqual(DateTimes[i], occurrences[i].Period.StartTime, "Event should occur at " + DateTimes[i]);
            }

            Assert.IsTrue(occurrences.Count == DateTimes.Length, "There should be exactly " + DateTimes.Length + " occurrences; there were " + occurrences.Count);
        }
        /// <summary>
        /// Updates the help text.
        /// </summary>
        private void UpdateHelpText()
        {
            var fakeSchedule = new Rock.Model.Schedule();

            fakeSchedule.iCalendarContent = sbSchedule.iCalendarContent;
            sbSchedule.ToolTip            = fakeSchedule.ToFriendlyScheduleText();

            hbSchedulePreview.Text = @"<strong>iCalendar Content</strong>
<div style='white-space: pre' Font-Names='Consolas' Font-Size='9'><br />" + sbSchedule.iCalendarContent + "</div>";

            iCalendar calendar = iCalendar.LoadFromStream(new StringReader(sbSchedule.iCalendarContent)).First() as iCalendar;

            DDay.iCal.Event calendarEvent = calendar.Events[0] as Event;

            if (calendarEvent.DTStart != null)
            {
                List <Occurrence> nextOccurrences = calendar.GetOccurrences(RockDateTime.Now, RockDateTime.Now.AddYears(1)).Take(26).ToList();

                string listHtml = "<hr /><strong>Occurrences Preview</strong><ul>";
                foreach (var occurrence in nextOccurrences)
                {
                    listHtml += "<li>" + GetOccurrenceText(occurrence) + "</li>";
                }

                listHtml += string.Format("<li>{0}</li>", "...");
                listHtml += "</ul>";

                hbSchedulePreview.Text += listHtml;
            }
        }
Exemple #3
0
        /// <summary>
        /// Updates the help text.
        /// </summary>
        private void UpdateHelpText()
        {
            hbSchedulePreview.Text = "<div style='white-space: pre' Font-Names='Consolas' Font-Size='9'>" + sbSchedule.iCalendarContent + "</div>";

            iCalendar calendar = iCalendar.LoadFromStream(new StringReader(sbSchedule.iCalendarContent)).First() as iCalendar;

            DDay.iCal.Event calendarEvent = calendar.Events[0] as Event;

            if (calendarEvent.DTStart != null)
            {
                List <Occurrence> nextOccurrences = calendar.GetOccurrences(DateTime.Now.Date, DateTime.Now.Date.AddYears(1)).Take(26).ToList();

                string listHtml = "<hr /><span>Occurrences Preview</span><ul>";
                foreach (var occurrence in nextOccurrences)
                {
                    if (occurrence.Period.StartTime.Value.Date.Equals(occurrence.Period.EndTime.Value.Date))
                    {
                        listHtml += string.Format("<li>{0} - {1} to {2} ( {3} hours) </li>", occurrence.Period.StartTime.Value.Date.ToShortDateString(), occurrence.Period.StartTime.Value.TimeOfDay.ToTimeString(), occurrence.Period.EndTime.Value.TimeOfDay.ToTimeString(), occurrence.Period.Duration.TotalHours.ToString("#0.00"));
                    }
                    else
                    {
                        listHtml += string.Format("<li>{0} to {1} ( {2} hours) </li>", occurrence.Period.StartTime.Value.ToString("g"), occurrence.Period.EndTime.Value.ToString("g"), occurrence.Period.Duration.TotalHours.ToString("#0.00"));
                    }
                }

                listHtml += string.Format("<li>{0}</li>", "...");
                listHtml += "</ul>";

                hbSchedulePreview.Text += listHtml;
            }
        }
Exemple #4
0
        public void Outlook2007_With_Folded_Lines_Using_Tabs_Contains_One_Event()
        {
            iCalendar         iCal   = iCalendar.LoadFromFile(@"Calendars/General/Outlook2007LineFolds.ics");
            List <Occurrence> events = iCal.GetOccurrences(new DateTime(2009, 06, 20), new DateTime(2009, 06, 22));

            Assert.AreEqual(1, events.Count);
        }
Exemple #5
0
        /// <summary>
        /// Displays the calendar in the time zone identified by <paramref name="tzid"/>.
        /// </summary>
        static void ShowCalendar(iCalendar iCal, string tzid)
        {
            iCalDateTime start = new iCalDateTime(2007, 3, 1);
            iCalDateTime end   = new iCalDateTime(2007, 4, 1).AddSeconds(-1);

            List <Occurrence> occurrences = iCal.GetOccurrences(start, end);

            Console.WriteLine("====Events/Todos/Journal Entries in " + tzid + "====");
            foreach (Occurrence o in occurrences)
            {
                Console.WriteLine(
                    o.Period.StartTime.ToTimeZone(tzid).ToString("ddd, MMM d - h:mm") + " to " +
                    o.Period.EndTime.ToTimeZone(tzid).ToString("h:mm tt") + Environment.NewLine +
                    o.Component.Summary + Environment.NewLine);
            }

            Console.WriteLine("====Alarms in " + tzid + "====");
            foreach (RecurringComponent rc in iCal.RecurringComponents)
            {
                foreach (AlarmOccurrence ao in rc.PollAlarms(start, end))
                {
                    Console.WriteLine(
                        "Alarm: " +
                        ao.DateTime.ToTimeZone(tzid).ToString("ddd, MMM d - h:mm") + ": " +
                        ao.Alarm.Summary);
                }
            }

            Console.WriteLine();
        }
Exemple #6
0
        public void Outlook2007_With_Folded_Lines_Using_Tabs_Is_Properly_Unwrapped()
        {
            string            longName = "The Exceptionally Long Named Meeting Room Whose Name Wraps Over Several Lines When Exported From Leading Calendar and Office Software Application Microsoft Office 2007";
            iCalendar         iCal     = iCalendar.LoadFromFile(@"Calendars/General/Outlook2007LineFolds.ics");
            List <Occurrence> events   = iCal.GetOccurrences <Event>(new DateTime(2009, 06, 20), new DateTime(2009, 06, 22));

            Assert.AreEqual(longName, ((Event)events[0].Component).Location.Value);
        }
Exemple #7
0
        static void Main(string[] args)
        {
            // Create a new calendar
            IICalendar iCal = new iCalendar();

            // Add the local time zone to the calendar
            ITimeZone local = iCal.AddLocalTimeZone();

            // Build a list of additional time zones
            // from .NET Framework.
            List <ITimeZone> otherTimeZones = new List <ITimeZone>();

            foreach (TimeZoneInfo tzi in System.TimeZoneInfo.GetSystemTimeZones())
            {
                // We've already added the local time zone, so let's skip it!
                if (tzi != System.TimeZoneInfo.Local)
                {
                    // Add the time zone to our list (but don't include it directly in the calendar).
                    otherTimeZones.Add(iCalTimeZone.FromSystemTimeZone(tzi));
                }
            }

            // Create a new event in the calendar
            // that uses our local time zone
            IEvent evt = iCal.Create <Event>();

            evt.Summary  = "Test Event";
            evt.Start    = iCalDateTime.Today.AddHours(8).SetTimeZone(local);
            evt.Duration = TimeSpan.FromHours(1);

            // Get all occurrences of the event that happen today
            foreach (Occurrence occurrence in iCal.GetOccurrences <IEvent>(iCalDateTime.Today))
            {
                // Write the event with the time zone information attached
                Console.WriteLine(occurrence.Period.StartTime);

                // Note that the time printed is identical to the above, but without time zone information.
                Console.WriteLine(occurrence.Period.StartTime.Local);

                // Convert the start time to other time zones and display the relative time.
                foreach (ITimeZone otherTimeZone in otherTimeZones)
                {
                    Console.WriteLine(occurrence.Period.StartTime.ToTimeZone(otherTimeZone));
                }
            }
        }
        public void PARSE11()
        {
            iCalendar iCal = iCalendar.LoadFromUri(new Uri("http://www.google.com/calendar/ical/tvhot064q4p48frqdalgo3fb2k%40group.calendar.google.com/public/basic.ics"));

            Assert.IsNotNull(iCal);
            Assert.AreEqual(1, iCal.Events.Count);
            Assert.AreEqual(1, iCal.TimeZones.Count);

            TZID tzid = iCal.TimeZones[0].TZID;
            IList <Occurrence> occurrences = iCal.GetOccurrences(new iCalDateTime(2009, 8, 24, tzid, iCal), new iCalDateTime(2009, 9, 28, tzid, iCal));

            Assert.AreEqual(5, occurrences.Count);
            Assert.AreEqual(new iCalDateTime(2009, 8, 26, 8, 0, 0, tzid, iCal), occurrences[0].Period.StartTime);
            Assert.AreEqual(new iCalDateTime(2009, 9, 2, 8, 0, 0, tzid, iCal), occurrences[1].Period.StartTime);
            Assert.AreEqual(new iCalDateTime(2009, 9, 9, 8, 0, 0, tzid, iCal), occurrences[2].Period.StartTime);
            Assert.AreEqual(new iCalDateTime(2009, 9, 16, 8, 0, 0, tzid, iCal), occurrences[3].Period.StartTime);
            Assert.AreEqual(new iCalDateTime(2009, 9, 23, 8, 0, 0, tzid, iCal), occurrences[4].Period.StartTime);
            Assert.AreEqual(new iCalDateTime(2009, 8, 26, 10, 0, 0, tzid, iCal), occurrences[0].Period.EndTime);
        }
Exemple #9
0
        public void LoadAndDisplayCalendar()
        {
            // The following code loads and displays an iCalendar
            // with US Holidays for 2006.
            //
            iCalendar iCal = iCalendar.LoadFromFile(@"Calendars\General\USHolidays.ics");

            Assert.IsNotNull(iCal, "iCalendar did not load.  Are you connected to the internet?");

            List <Occurrence> occurrences = iCal.GetOccurrences(
                new Date_Time(2006, 1, 1, "US-Eastern", iCal),
                new Date_Time(2006, 12, 31, "US-Eastern", iCal));

            foreach (Occurrence o in occurrences)
            {
                Event evt = o.Component as Event;
                if (evt != null)
                {
                    // Display the date of the event
                    Console.Write(o.Period.StartTime.Local.Date.ToString("MM/dd/yyyy") + " -\t");

                    // Display the event summary
                    Console.Write(evt.Summary);

                    // Display the time the event happens (unless it's an all-day event)
                    if (evt.Start.HasTime)
                    {
                        Console.Write(" (" + evt.Start.Local.ToShortTimeString() + " - " + evt.End.Local.ToShortTimeString());
                        if (evt.Start.TimeZoneInfo != null)
                        {
                            Console.Write(" " + evt.Start.TimeZoneInfo.TimeZoneName);
                        }
                        Console.Write(")");
                    }

                    Console.Write(Environment.NewLine);
                }
            }
        }
        public void Bug3414862()
        {
            IICalendar iCal = new iCalendar();
            Event evt = iCal.Create<Event>();
            RecurrencePattern rPattern = new RecurrencePattern();
            rPattern.Frequency = FrequencyType.Weekly;
            FrequencyOccurrence frequencyOccurrence = FrequencyOccurrence.First;
            rPattern.ByDay.Add(new WeekDay(DayOfWeek.Wednesday, frequencyOccurrence));

            DateTime startDateTime = new DateTime(2011, 1, 5, 13, 0, 0);
            DateTime endDateTime = new DateTime(2013, 4, 3, 13, 45, 0);
            evt.Start = new iCalDateTime(startDateTime);

            evt.Duration = new TimeSpan(0, 45, 0);
            rPattern.Until = endDateTime;
            evt.RecurrenceRules.Add(rPattern);

            DateTime thruDateTime = new DateTime(2013, 3, 6);

            IList<Occurrence> occurrences = iCal.GetOccurrences(startDateTime, thruDateTime.Date.AddDays(1).AddSeconds(-1));

            // There should be exactly 114 occurrences 
            Assert.AreEqual(114, occurrences.Count);

            // The last occurrence should be on march 6th
            Assert.AreEqual(new DateTime(2013, 3, 6), occurrences.Last().Period.StartTime.Date);
        }