2

My application needs calendar information and I would like to use a format/schema that is compatible with .ical so it can integrate with other calendar systems.

DDay iCal seems to be the only .Net library available that does this.

However I don't see any way to save the objects to a database. I'm using Nhibernate, so I'd like a natural way to do this.

Has anyone already done this? Am I missing something in the DDay iCal library? Any suggestions?

Is my only option modifying the source code?

richard
  • 12,263
  • 23
  • 95
  • 151
  • Try to serialize it, and convert it to a byte array. Then just try to persist it. – Najera Jan 03 '15 at 08:30
  • serialization is one way, or you might try writing the mappings yourself as suggested by the author of dday.ical (see http://sourceforge.net/p/dday-ical/discussion/656447/thread/dfc47faa/ ) – sotto Feb 12 '15 at 08:00

1 Answers1

1

(Don't use dday.ical; use ical.net. It contains many performance enhancements and bugfixes.)

I don't know anything about NHibernate, but icalendar is a serialization format. You can just emit ical-serialized text representing your calendar(s) and their event(s).

Here's a working example from the ical.net wiki:

var now = DateTime.Now;
var later = now.AddHours(1);

//Repeat daily for 5 days
var rrule = new RecurrencePattern(FrequencyType.Daily, 1) { Count = 5 };

var e = new Event
{
    DtStart = new CalDateTime(now),
    DtEnd = new CalDateTime(later),
    RecurrenceRules = new List<IRecurrencePattern> { rrule },
};

var calendar = new Calendar();
calendar.Events.Add(e);

var serializer = new CalendarSerializer(new SerializationContext());
var serializedCalendar = serializer.SerializeToString(calendar);

This will emit ical-serialized text that can be stored in a database using any framework you wish. The serialized text will look something like this:

BEGIN: VCALENDAR
VERSION:2.0
PRODID: -//github.com/rianjs/ical.net//NONSGML ical.net 2.1//EN
BEGIN:VEVENT
DTEND:20160704T172520
DTSTAMP:20160704T162520
DTSTART:20160704T162520
RRULE:FREQ=DAILY;COUNT=5
SEQUENCE: 0
UID: f4693a88-0a57-4761-b949-8822b8a507d2
END:VEVENT
END:VCALENDAR
rianjs
  • 7,767
  • 5
  • 24
  • 40