public void RenderEventsAsHtml(ZonelessEventStore es, StringBuilder builder, Dictionary<string,object> args)
        {
            if (args == null)
                args = new Dictionary<string, object>();
            if ( args.ContainsKey("mobile") == false )
                args["mobile"] = false;
            //OrganizeByDate(es);
            var event_renderer = new EventRenderer(RenderEvtAsHtml);
            var year_month_anchors = new List<string>(); // e.g. ym201201
            var day_anchors = new List<string>(); // e.g. d20120119
            var current_time_of_day = TimeOfDay.Initialized;
            var sources_dict = new Dictionary<string, int>();
            int sequence_position = 0;
            bool sequence_at_zero = true;
            string last_source_key = null;
            string current_date_key = null;

            var announce_time_of_day = get_announce_time_of_day(args);
            BuildSourcesDict(es, announce_time_of_day, sources_dict);

            foreach (ZonelessEvent evt in es.events)
            {
                string datekey = Utils.DateKeyFromDateTime(evt.dtstart);
                var event_builder = new StringBuilder();
                var year_month_anchor = datekey.Substring(1, 6);

                if  ((bool)args["mobile"] == false)  // skip day anchors and headers in mobile view
                {
                    if (!year_month_anchors.Exists(ym => ym == year_month_anchor))
                    {
                        builder.Append(string.Format("\n<a name=\"ym{0}\"></a>\n", year_month_anchor));
                        year_month_anchors.Add(year_month_anchor);
                    }
                    if (!day_anchors.Exists(d => d == datekey))
                    {
                        event_builder.Append(string.Format("\n<a name=\"{0}\"></a>\n", datekey));
                        var date = Utils.DateFromDateKey(datekey);
                        event_builder.Append(string.Format("<h1 id=\"{0}\" class=\"ed\"><b>{1}</b></h1>\n", datekey, date));
                        day_anchors.Add(datekey);
                        sequence_at_zero = true;
                    }
                }

                if (announce_time_of_day && (bool) args["mobile"] == false) // skip time-of-day markers in mobile view
                {
                    var time_of_day = Utils.ClassifyTime(evt.dtstart);

                    if (time_of_day != current_time_of_day || datekey != current_date_key) // see http://blog.jonudell.net/2009/06/18/its-the-headings-stupid/
                    {
                        current_date_key = datekey;
                        current_time_of_day = time_of_day;
                        event_builder.Append(string.Format("<h2 id=\"t{0}\" class=\"timeofday\">{1}</h2>", this.time_of_day_counter, time_of_day.ToString()));
                        this.time_of_day_counter += 1;
                        sequence_at_zero = true;
                    }
                }

                var source_key = MakeSourceKey(current_time_of_day, datekey, evt);
                if (source_key != last_source_key)
                {
                    sequence_at_zero = true;
                    last_source_key = source_key;
                }

                if (sequence_at_zero)
                {
                    sequence_position = 1;
                    sequence_at_zero = false;
                }
                else
                    sequence_position++;

                if (evt.urls_and_sources.Count == 1)       // else multiple coalesced sources, nothing to hide
                {
                    args["source_key"] = source_key;
                    args["sequence_count"] = sources_dict[source_key];
                    args["sequence_position"] = sequence_position;
                }

                AppendEvent(event_builder, event_renderer, evt, args );
                builder.Append(event_builder);
            }
        }
        // render an eventstore as xml, optionally limited by view and/or count
        public string RenderXml(ZonelessEventStore eventstore, string view, int count, DateTime from, DateTime to, Dictionary<string,object> args)
        {
            eventstore = GetEventStore(eventstore, view, count, from, to);

            var xml = new StringBuilder();
            xml.Append("<events>\n");

            var event_renderer = new EventRenderer(RenderEvtAsXml);

            var eventstring = new StringBuilder();

            foreach (var evt in eventstore.events)
                AppendEvent(eventstring, event_renderer, evt, new Dictionary<string,object>() );

            xml.Append(eventstring.ToString());

            xml.Append("</events>\n");

            return xml.ToString();
        }
 // take a string representation of a set of events, in some format
 // take a per-event renderer for that format
 // take an event object
 // call the renderer to add the event object to the string representation
 // currently uses: RenderEvtAsHtml, RenderEvtAsXml
 private void AppendEvent(StringBuilder eventstring, EventRenderer event_renderer, ZonelessEvent evt, Dictionary<string,object> args)
 {
     eventstring.Append(event_renderer(evt, this.calinfo, args ) );
 }
Beispiel #4
0
        // render an eventstore as text, optionally limited by view and/or count
        public string RenderText(ZonelessEventStore eventstore, EventRenderer event_renderer, string view, int count, DateTime from, DateTime to, string source, Dictionary<string, object> args)
        {
            if (args == null)
                args = new Dictionary<string, object>();

            eventstore = GetEventStore(eventstore, view, count, from, to, source, args);

            var text = new StringBuilder();

            var eventstring = new StringBuilder();

            foreach (var evt in eventstore.events)
                AppendEvent(eventstring, event_renderer, evt, args);

            text.Append(eventstring.ToString());

            return text.ToString();
        }