public FullCalendarEvent(DDay.iCal.IEvent ev, string backColour, string textColour)
 {
     id              = ev.UID;
     title           = ev.Name;
     allDay          = ev.IsAllDay;;
     start           = ev.Start.UTC;
     end             = ev.End.UTC;
     url             = ev.Url.ToString();
     backgroundColor = backColour;
     borderColor     = backColour;
     textColor       = textColour;
 }
        public void ProcessICalRequest(Uri iCalUri, DateTime start, DateTime end, HttpContext context)
        {
            string backColor = PageUtils.getFromForm("backColour", "white");
            string textColor = PageUtils.getFromForm("textColor", "black");

            int    cacheMinutes = HatCMS.Tools.cachingProxy.CacheDuration_Minutes;
            string cacheKey     = iCalUri.ToString();

            DDay.iCal.IICalendarCollection calCollection;
            if (cacheMinutes > 0 && context.Cache[cacheKey] != null)
            {
                calCollection = (DDay.iCal.IICalendarCollection)context.Cache[cacheKey];
            }
            else
            {
                calCollection = DDay.iCal.iCalendar.LoadFromUri(iCalUri);

                // -- add the data to the cache
                if (cacheMinutes > 0)
                {
                    context.Cache.Insert(cacheKey, calCollection, null,
                                         Cache.NoAbsoluteExpiration,
                                         TimeSpan.FromMinutes(cacheMinutes),
                                         CacheItemPriority.Normal, null);
                }
            }

            List <FullCalendarEvent>     eventsToOutput = new List <FullCalendarEvent>();
            IList <DDay.iCal.Occurrence> occurrences    = calCollection.GetOccurrences <DDay.iCal.IEvent>(start, end);

            foreach (DDay.iCal.Occurrence occurrence in occurrences)
            {
                if (occurrence.Source is DDay.iCal.IEvent)
                {
                    DDay.iCal.IEvent ievent = occurrence.Source as DDay.iCal.IEvent;
                    if (ievent.IsActive()) // make sure the event hasn't been cancelled.
                    {
                        FullCalendarEvent e = new FullCalendarEvent(ievent, backColor, textColor);
                        eventsToOutput.Add(e);
                    }
                }
            } // foreach

            string json = JsonWriter.Serialize(eventsToOutput.ToArray());

            context.Response.Write(json);
        }