Exemple #1
0
    public static void Main(string[] args)
    {
        var serializer = new XmlSerializer(typeof(Schedule));

        var      reader   = new StreamReader(args[0] + ".xml");
        Schedule schedule = (Schedule)serializer.Deserialize(reader);

        var output = new iCalendar();

        foreach (var cal in schedule.Calendars)
        {
            var id = kCalendarUriPrefix + cal.Id + kCalendarUriSuffix;
            var cc = iCalendar.LoadFromUri(new Uri(id));

            foreach (var course in cal.Courses)
            {
                InjectCustomEvents(course, output);
            }

            foreach (var c in cc)
            {
                foreach (var e in c.Events)
                {
                    if (e.Description != null)
                    {
                        // Filter on course number by default.
                        var match = Regex.Match(e.Description, @"\d\d\d\d");

                        if (!match.Success ||
                            cal.Courses.Any(x => x.Id == match.Value))
                        {
                            output.AddChild(e.Copy <Event>());
                        }
                    }
                    else
                    {
                        // Filter on course shorthand when the university f***s
                        // up.
                        if (e.Summary == null)
                        {
                            // This should not happen... ever.
                            continue;
                        }

                        e.Description = e.Summary;

                        if (cal.Courses.Any(
                                x => e.Description.Contains(x.Abbreviation)))
                        {
                            output.AddChild(e.Copy <Event>());
                        }
                    }
                }
            }
        }

        var ser = new iCalendarSerializer();

        Console.Write(ser.SerializeToString(output));
    }
Exemple #2
0
        public void SystemTimeZone1()
        {
            System.TimeZoneInfo tzi = System.TimeZoneInfo.FindSystemTimeZoneById("Mountain Standard Time");
            Assert.IsNotNull(tzi);

            iCalendar    iCal = new iCalendar();
            iCalTimeZone tz   = iCalTimeZone.FromSystemTimeZone(tzi);

            Assert.IsNotNull(tz);
            iCal.AddChild(tz);

            iCalendarSerializer serializer = new iCalendarSerializer();

            serializer.Serialize(iCal, @"Calendars\Serialization\SystemTimeZone1.ics");

            iCalDateTime dt1 = new iCalDateTime(2003, 10, 26, 0, 59, 59, tz.TZID, iCal);
            iCalDateTime dt2 = new iCalDateTime(2003, 10, 26, 1, 0, 0, tz.TZID, iCal);

            TimeSpan result = dt2 - dt1;

            Assert.AreEqual(TimeSpan.FromHours(1) + TimeSpan.FromSeconds(1), result);

            dt1    = new iCalDateTime(2004, 4, 4, 1, 59, 59, tz.TZID, iCal);
            dt2    = new iCalDateTime(2004, 4, 4, 2, 0, 0, tz.TZID, iCal);
            result = dt2 - dt1;
            Assert.AreEqual(TimeSpan.FromHours(-1) + TimeSpan.FromSeconds(1), result);
        }
Exemple #3
0
        public void SystemTimeZone1()
        {
            System.TimeZoneInfo tzi = System.TimeZoneInfo.FindSystemTimeZoneById("Mountain Standard Time");
            Assert.IsNotNull(tzi);

            iCalendar    iCal = new iCalendar();
            iCalTimeZone tz   = iCalTimeZone.FromSystemTimeZone(tzi, new DateTime(2000, 1, 1), false);

            Assert.IsNotNull(tz);
            iCal.AddChild(tz);

            iCalendarSerializer serializer = new iCalendarSerializer();

            serializer.Serialize(iCal, @"Calendars\Serialization\SystemTimeZone1.ics");

            // Ensure the time zone transition works as expected
            // (i.e. it takes 1 hour and 1 second to transition from
            // 2003-10-26 12:59:59 AM to
            // 2003-10-26 01:00:00 AM)
            iCalDateTime dt1 = new iCalDateTime(2003, 10, 26, 0, 59, 59, tz.TZID, iCal);
            iCalDateTime dt2 = new iCalDateTime(2003, 10, 26, 1, 0, 0, tz.TZID, iCal);

            TimeSpan result = dt2 - dt1;

            Assert.AreEqual(TimeSpan.FromHours(1) + TimeSpan.FromSeconds(1), result);

            // Ensure another time zone transition works as expected
            // (i.e. it takes negative 59 minutes and 59 seconds to transition from
            // 2004-04-04 01:59:59 AM to
            // 2004-04-04 02:00:00 AM)
            dt1    = new iCalDateTime(2004, 4, 4, 1, 59, 59, tz.TZID, iCal);
            dt2    = new iCalDateTime(2004, 4, 4, 2, 0, 0, tz.TZID, iCal);
            result = dt2 - dt1;
            Assert.AreEqual(TimeSpan.FromHours(-1) + TimeSpan.FromSeconds(1), result);
        }
Exemple #4
0
    public static void InjectCustomEvents(Course course, iCalendar output)
    {
        switch (course.Id)
        {
        case "0173": {// mechanica
            Event e = new Event();
            e.Description =
                "MECH; G8; (Practicum); Voor: 3de bachelor informatica";
            e.Summary  = e.Description;
            e.Location = "G8";
            e.Class    = "PUBLIC";
            e.UID      = "000000_injected";
            e.DTStart  = new iCalDateTime(2013, 11, 08, 13, 00, 00);
            e.DTEnd    = new iCalDateTime(2013, 11, 08, 17, 00, 00);

            output.AddChild(e);
            break;
        }
        }
    }
Exemple #5
0
        /// <summary>
        /// Creates a calendar with 2 events, and returns it.
        /// </summary>
        static IICalendar CreateCalendar()
        {
            // First load a file containing time zone information for North & South America
            IICalendar timeZones = iCalendar.LoadFromFile("America.ics")[0];

            // Add the time zones we are going to use to our calendar
            // If we're not sure what we'll use, we could simply copy the
            // entire time zone information instead:
            //
            // IICalendar iCal = timeZones.Copy<IICalendar>();
            //
            // This will take significantly more disk space, and can slow
            // down performance, so I recommend you determine which time
            // zones will be used and only copy the necessary zones.
            IICalendar iCal = new iCalendar();

            iCal.AddChild(timeZones.GetTimeZone("America/New_York"));
            iCal.AddChild(timeZones.GetTimeZone("America/Denver"));

            // Create an event and attach it to the iCalendar.
            Event evt = iCal.Create <Event>();

            // Set the one-line summary of the event
            evt.Summary = "The first Monday and second-to-last Monday of each month";

            // Set the longer description of the event
            evt.Description = "A more in-depth description of this event.";

            // Set the event to start at 11:00 A.M. New York time on January 2, 2007.
            evt.Start = new iCalDateTime(2007, 1, 2, 11, 0, 0, "America/New_York", iCal);

            // Set the duration of the event to 1 hour.
            // NOTE: this will automatically set the End time of the event
            evt.Duration = TimeSpan.FromHours(1);

            // The event has been confirmed
            evt.Status = EventStatus.Confirmed;

            // Set the geographic location (latitude,longitude) of the event
            evt.GeographicLocation = new GeographicLocation(114.2938, 32.982);

            evt.Location = "Home office";
            evt.Priority = 7;

            // Add an organizer to the event.
            // This is the person who created the event (or who is in charge of it)
            evt.Organizer = new Organizer("MAILTO:[email protected]");
            // Indicate that this organizer is a member of another group
            evt.Organizer.Parameters.Add("MEMBER", "MAILTO:[email protected]");

            // Add a person who will attend the event
            // FIXME: re-implement this
            //evt.Attendees.Add(new Attendee("*****@*****.**"));

            // Add categories to the event
            evt.Categories.Add("Work");
            evt.Categories.Add("Personal");

            // Add some comments to the event
            evt.Comments.Add("Comment #1");
            evt.Comments.Add("Comment #2");

            // Add resources that will be used for the event
            evt.Resources.Add("Conference Room #2");
            evt.Resources.Add("Projector #4");

            // Add contact information to this event, with an optional link to further information
            // FIXME: reimplement this:
            //evt.Contacts.Add("Doug Day (XXX) XXX-XXXX", new Uri("http://www.someuri.com/pdi/dougd.vcf"));

            // Set the identifier for the event.  NOTE: this will happen automatically
            // if you don't do it manually.  We set it manually here so we can easily
            // refer to this event later.
            evt.UID = "1234567890";

            // Now, let's add a recurrence pattern to this event.
            // It needs to happen on the first Monday and
            // second to last Monday of each month.
            RecurrencePattern rp = new RecurrencePattern();

            rp.Frequency = FrequencyType.Monthly;
            rp.ByDay.Add(new WeekDay(DayOfWeek.Monday, FrequencyOccurrence.First));
            rp.ByDay.Add(new WeekDay(DayOfWeek.Monday, FrequencyOccurrence.SecondToLast));
            evt.RecurrenceRules.Add(rp);

            // Let's also add an alarm on this event so we can be reminded of it later.
            Alarm alarm = new Alarm();

            // Display the alarm somewhere on the screen.
            alarm.Action = AlarmAction.Display;

            // This is the text that will be displayed for the alarm.
            alarm.Summary = "Alarm for the first Monday and second-to-last Monday of each month";

            // The alarm is set to occur 30 minutes before the event
            alarm.Trigger = new Trigger(TimeSpan.FromMinutes(-30));

            // Set the alarm to repeat twice (for a total of 3 alarms)
            // before the event.  Each repetition will occur 10 minutes
            // after the initial alarm.  In english - that means
            // the alarm will go off 30 minutes before the event,
            // then again 20 minutes before the event, and again
            // 10 minutes before the event.
            alarm.Repeat   = 2;
            alarm.Duration = TimeSpan.FromMinutes(10);

            // Add the alarm to the event
            evt.Alarms.Add(alarm);

            // Create another (much more simple) event
            evt             = iCal.Create <Event>();
            evt.Summary     = "Every month on the 21st";
            evt.Description = "A more in-depth description of this event.";
            evt.Start       = new iCalDateTime(2007, 1, 21, 16, 0, 0, "America/New_York", iCal);
            evt.Duration    = TimeSpan.FromHours(1.5);

            rp           = new RecurrencePattern();
            rp.Frequency = FrequencyType.Monthly;
            evt.RecurrenceRules.Add(rp);

            return(iCal);
        }
        public void FreeBusy2()
        {
            IICalendar iCal = new iCalendar();

            IEvent evt = iCal.Create<Event>();
            evt.Summary = "Test event";
            evt.Start = new iCalDateTime(2010, 10, 1, 8, 0, 0);
            evt.End = new iCalDateTime(2010, 10, 1, 9, 0, 0);

            IAttendee attendee = new Attendee("mailto:[email protected]");
            attendee.ParticipationStatus = ParticipationStatus.Tentative;
            evt.Attendees.Add(attendee);

            IICalendar freeBusyCalendar = new iCalendar();
            IFreeBusy freeBusy = iCal.GetFreeBusy(
                null, 
                new IAttendee[] { new Attendee("mailto:[email protected]") }, 
                new iCalDateTime(2010, 10, 1, 0, 0, 0), 
                new iCalDateTime(2010, 10, 7, 11, 59, 59));

            freeBusyCalendar.AddChild(freeBusy);

            iCalendarSerializer serializer = new iCalendarSerializer();
            serializer.Serialize(freeBusyCalendar, @"Calendars/Serialization/FreeBusy2.ics");

            SerializeTest("FreeBusy2.ics", typeof(iCalendarSerializer));
        }
        public void FreeBusy1()
        {
            IICalendar iCal = new iCalendar();

            IEvent evt = iCal.Create<Event>();
            evt.Summary = "Test event";
            evt.Start = new iCalDateTime(2010, 10, 1, 8, 0, 0);
            evt.End = new iCalDateTime(2010, 10, 1, 9, 0, 0);

            IICalendar freeBusyCalendar = new iCalendar();
            IFreeBusy freeBusy = iCal.GetFreeBusy(new iCalDateTime(2010, 10, 1, 0, 0, 0), new iCalDateTime(2010, 10, 7, 11, 59, 59));
            freeBusyCalendar.AddChild(freeBusy);

            iCalendarSerializer serializer = new iCalendarSerializer();
            serializer.Serialize(freeBusyCalendar, @"Calendars/Serialization/FreeBusy1.ics");

            SerializeTest("FreeBusy1.ics", typeof(iCalendarSerializer));
        }
Exemple #8
0
        public void SystemTimeZone1()
        {
            System.TimeZoneInfo tzi = System.TimeZoneInfo.FindSystemTimeZoneById("Mountain Standard Time");
            Assert.IsNotNull(tzi);

            iCalendar iCal = new iCalendar();
            iCalTimeZone tz = iCalTimeZone.FromSystemTimeZone(tzi, new DateTime(2000, 1, 1), false);
            Assert.IsNotNull(tz);
            iCal.AddChild(tz);

            iCalendarSerializer serializer = new iCalendarSerializer();
            serializer.Serialize(iCal, @"Calendars\Serialization\SystemTimeZone1.ics");

            // Ensure the time zone transition works as expected
            // (i.e. it takes 1 hour and 1 second to transition from
            // 2003-10-26 12:59:59 AM to
            // 2003-10-26 01:00:00 AM)
            iCalDateTime dt1 = new iCalDateTime(2003, 10, 26, 0, 59, 59, tz.TZID, iCal);
            iCalDateTime dt2 = new iCalDateTime(2003, 10, 26, 1, 0, 0, tz.TZID, iCal);

            TimeSpan result = dt2 - dt1;
            Assert.AreEqual(TimeSpan.FromHours(1) + TimeSpan.FromSeconds(1), result);

            // Ensure another time zone transition works as expected
            // (i.e. it takes negative 59 minutes and 59 seconds to transition from
            // 2004-04-04 01:59:59 AM to
            // 2004-04-04 02:00:00 AM)
            dt1 = new iCalDateTime(2004, 4, 4, 1, 59, 59, tz.TZID, iCal);
            dt2 = new iCalDateTime(2004, 4, 4, 2, 0, 0, tz.TZID, iCal);
            result = dt2 - dt1;
            Assert.AreEqual(TimeSpan.FromHours(-1) + TimeSpan.FromSeconds(1), result);            
        }
Exemple #9
0
        public void SystemTimeZone1()
        {
            System.TimeZoneInfo tzi = System.TimeZoneInfo.FindSystemTimeZoneById("Mountain Standard Time");
            Assert.IsNotNull(tzi);

            iCalendar iCal = new iCalendar();
            iCalTimeZone tz = iCalTimeZone.FromSystemTimeZone(tzi);
            Assert.IsNotNull(tz);

            iCal.AddChild(tz);

            iCalDateTime dt1 = new iCalDateTime(2003, 10, 26, 0, 59, 59, tz.TZID, iCal);
            iCalDateTime dt2 = new iCalDateTime(2003, 10, 26, 1, 0, 0, tz.TZID, iCal);
            TimeSpan result = dt2 - dt1;
            Assert.AreEqual(TimeSpan.FromHours(1) + TimeSpan.FromSeconds(1), result);

            dt1 = new iCalDateTime(2004, 4, 4, 1, 59, 59, tz.TZID, iCal);
            dt2 = new iCalDateTime(2004, 4, 4, 2, 0, 0, tz.TZID, iCal);
            result = dt2 - dt1;
            Assert.AreEqual(TimeSpan.FromHours(-1) + TimeSpan.FromSeconds(1), result);            
        }