Exemplo n.º 1
0
        public static void Finalize(Calinfo calinfo, ZonelessEventStore es_zoneless)
        {
            es_zoneless.events = EventStore.UniqueByTitleAndStart(calinfo.id, es_zoneless.events, save_tag_sources: true); // deduplicate

            es_zoneless.ExcludePastEvents();                                                                               // the EventCollector should already have done this, but in case not...

            es_zoneless.SortEventList();                                                                                   // order by dtstart

            Utils.BuildTagStructures(es_zoneless, calinfo);                                                                // build structures used to generate tag picklists

            var i = 0;

            foreach (var evt in es_zoneless.events)
            {
                var str  = evt.dtstart.ToString() + evt.title.ToString() + evt.source.ToString() + evt.url;
                var hash = HttpUtils.GetMd5Hash(Encoding.UTF8.GetBytes(str));
                evt.uid = i;
                i++;
                evt.hash = hash;
            }

            es_zoneless.PopulateDaysAndCounts();                // do this here for a) renderer efficiency, b) renderer simplification
            // (it only updates these structures for category views)

            es_zoneless.when_finalized = DateTime.UtcNow;

            es_zoneless.Serialize();
        }
Exemplo n.º 2
0
 public void AddZonelessEventIncrementsCount()
 {
     var zoneless = new ZonelessEventStore(calinfo);
     Assert.AreEqual(0, zoneless.events.Count);
     zoneless.AddEvent(in_evt0_zoneless.title, in_evt0_zoneless.url, in_evt0_zoneless.source, test_lat, test_lon, in_evt0_zoneless.dtstart, in_evt0_zoneless.dtend, allday: false, categories: test_category, description: test_description, location: test_location);
     Assert.AreEqual(1, zoneless.events.Count);
 }
Exemplo n.º 3
0
        public void TagsAndUrlsAreCoalesced()            // 3 events with same title + start should coalesce tags and urls
        {
            DeleteZonedObjects(keene_test_hub);

            var dtstart = new DateTimeWithZone(DateTime.Now, calinfo_keene.tzinfo);
            var dtend   = new DateTimeWithZone(dtstart.LocalTime + TimeSpan.FromHours(1), calinfo_keene.tzinfo);


            var es1 = new ZonedEventStore(calinfo_keene, SourceType.ical);

            es1.AddEvent(
                "event",
                "http://1",
                "source1",
                dtstart,
                dtend,
                "1",
                "1",
                false,
                "cat1",
                "first event",
                "first location"
                );

            es1.Serialize();

            Assert.IsTrue(calinfo_keene.eventful);

            var es2 = new ZonedEventStore(calinfo_keene, SourceType.eventful);

            es2.AddEvent(
                "event",
                "http://2",
                "source2",
                dtstart,
                dtend,
                "2",
                "2",
                false,
                "cat2,cat2a",
                "second event",
                "second location"
                );

            es2.Serialize();

            EventStore.CombineZonedEventStoresToZonelessEventStore(keene_test_hub, settings);
            var es = new ZonelessEventStore(calinfo_keene).Deserialize();

            Assert.That(es.events.Count == 1);

            var evt = es.events.Find(e => e.title == "event");

            Assert.That(evt.categories == "cat1,cat2,cat2a");

            Assert.That(evt.urls_and_sources.Keys.Count == 2);
            Assert.That(evt.urls_and_sources["http://1"] == "source1");
            Assert.That(evt.urls_and_sources["http://2"] == "source2");
        }
Exemplo n.º 4
0
        public void AddZonelessEventIncrementsCount()
        {
            var zoneless = new ZonelessEventStore(calinfo);

            Assert.AreEqual(0, zoneless.events.Count);
            zoneless.AddEvent(in_evt0_zoneless.title, in_evt0_zoneless.url, in_evt0_zoneless.source, test_lat, test_lon, in_evt0_zoneless.dtstart, in_evt0_zoneless.dtend, allday: false, categories: test_category, description: test_description, location: test_location);
            Assert.AreEqual(1, zoneless.events.Count);
        }
Exemplo n.º 5
0
 public CalendarRendererTest()
 {
     this.cr = new CalendarRenderer(Configurator.testid);
     this.cr.cache = new MockCache();
     var est = new EventStoreTest();
     est.SerializeAndDeserializeZonelessEventStoreYieldsExpectedEvents();
     this.es = new ZonelessEventStore(calinfo);
     var uri = BlobStorage.MakeAzureBlobUri(EventStoreTest.test_container, this.es.objfile,false);
     this.es = (ZonelessEventStore)BlobStorage.DeserializeObjectFromUri(uri);
 }
Exemplo n.º 6
0
        public static ZonelessEventStore ZonedToZoneless(string id, Calinfo calinfo, ZonedEventStore es_zoned)
        {
            var es_zoneless = new ZonelessEventStore(calinfo);

            foreach (var evt in es_zoned.events)
            {
                es_zoneless.AddEvent(evt.title, evt.url, evt.source, evt.lat, evt.lon, evt.dtstart.LocalTime, evt.dtend.LocalTime, evt.allday, evt.categories, evt.description, evt.location);
            }
            ZonelessEventStore.Finalize(calinfo, es_zoneless);
            return(es_zoneless);
        }
Exemplo n.º 7
0
        private static ZonelessEventStore ProcessEventBriteExample(string example, string source, Calinfo calinfo, Collector collector)
        {
            DeleteZonedObjects(calinfo.id);
            var es = new ZonedEventStore(calinfo, SourceType.eventbrite);

            collector.CollectEventBrite(es);
            EventStore.CombineZonedEventStoresToZonelessEventStore(calinfo.id, settings);
            var zes = new ZonelessEventStore(calinfo).Deserialize();

            return(zes);
        }
Exemplo n.º 8
0
        private ZonelessEventStore CreateFilterable(Calinfo calinfo)
        {
            var filterable = new ZonelessEventStore(calinfo);

            filterable.AddEvent("e1", "", "s1", null, null, DateTime.Parse("2013/11/01 8 AM"), DateTime.MinValue, false, null, null, null);
            filterable.AddEvent("e2", "", "s1", null, null, DateTime.Parse("2013/11/02 8 AM"), DateTime.MinValue, false, null, null, null);
            filterable.AddEvent("e3", "", "s2", null, null, DateTime.Parse("2013/11/03 8 AM"), DateTime.MinValue, false, null, null, null);
            filterable.AddEvent("e4", "", "s2", null, null, DateTime.Parse("2013/11/04 8 AM"), DateTime.MinValue, false, null, null, null);
            filterable.AddEvent("e5", "", "s2", null, null, DateTime.Parse("2013/11/05 8 AM"), DateTime.MinValue, false, "music", null, null);
            Assert.That(filterable.events.Count == 5);
            return(filterable);
        }
Exemplo n.º 9
0
        private static void HillsideExampleIsCorrectObj(ZonelessEventStore zes, string search, string replace)
        {
            var title_substr = "Afternoon Tea 3";

            if (search != null && replace != null)
            {
                title_substr = title_substr.Replace(search, replace);
            }
            Assert.That(zes.events.Count > 0);              // it's a recurring event, don't need/want to test for exact count
            var evt = zes.events[0];

            Assert.That(evt.title.StartsWith(title_substr));
            Assert.That(evt.dtstart.Hour == 15);
            Assert.That(evt.dtstart.Minute == 0);
            Assert.That(evt.dtstart.Second == 0);
        }
Exemplo n.º 10
0
        private static ZonelessEventStore ProcessIcalExample(string example, string source, Calinfo calinfo, FeedRegistry fr, Collector collector, bool purge)
        {
            DeleteZonedObjects(calinfo.id);
            if (purge)
            {
                Utils.PurgeFeedCacheForHub(calinfo.id);
            }
            var feedurl = BlobStorage.MakeAzureBlobUri("admin", example + ".ics", false).ToString();

            fr.AddFeed(feedurl, source);
            var es = new ZonedEventStore(calinfo, SourceType.ical);

            collector.CollectIcal(fr, es, false);
            EventStore.CombineZonedEventStoresToZonelessEventStore(calinfo.id, settings);
            var zes = new ZonelessEventStore(calinfo).Deserialize();

            return(zes);
        }
Exemplo n.º 11
0
        public static void CombineZonedEventStoresToZonelessEventStore(string id, Dictionary <string, string> settings)
        {
            var bs      = BlobStorage.MakeDefaultBlobStorage();
            var calinfo = new Calinfo(id);

            var lists_of_zoned_events = new List <List <ZonedEvent> >();

            var ical_uri = BlobStorage.MakeAzureBlobUri(container: id, name: id + "." + SourceType.ical + ".zoned.obj", use_cdn: false);

            DeserializeZoned(ical_uri, lists_of_zoned_events);

            //if (calinfo.hub_type == HubType.where.ToString())
            if (calinfo.hub_enum == HubType.where)
            {
                Uri non_ical_uri;
                //foreach (var type in non_ical_types)
                foreach (NonIcalType type in Enum.GetValues(typeof(CalendarAggregator.NonIcalType)))
                {
                    if (Utils.UseNonIcalService(type, settings, calinfo) == false)
                    {
                        continue;
                    }
                    non_ical_uri = BlobStorage.MakeAzureBlobUri(container: id, name: id + "." + type + ".zoned.obj", use_cdn: false);
                    if (BlobStorage.ExistsBlob(non_ical_uri))                     // // might not exist, e.g. if facebook=no in hub metadata
                    {
                        DeserializeZoned(non_ical_uri, lists_of_zoned_events);
                    }
                }
            }

            var es_zoneless = new ZonelessEventStore(calinfo);

            // combine the various List<ZonedEvent> objects into our new ZonelessEventStore
            // always add the local time
            foreach (var list in lists_of_zoned_events)
            {
                foreach (var evt in list)
                {
                    es_zoneless.AddEvent(evt.title, evt.url, evt.source, evt.lat, evt.lon, evt.dtstart.LocalTime, evt.dtend.LocalTime, evt.allday, evt.categories, evt.description, evt.location);
                }
            }

            ZonelessEventStore.Finalize(calinfo, es_zoneless);
        }
Exemplo n.º 12
0
        public void SerializeAndDeserializeZonelessEventStoreYieldsExpectedEvents()
        {
            var es = new ZonelessEventStore(calinfo);

            es.AddEvent(title: title1, url: "http://foo", source: source1, lat: null, lon: null, dtstart: dt1, dtend: min, allday: false, categories: test_category, description: test_description, location: test_location);

            var evt1 = es.events.Find(e => e.title == title1);

            evt1.urls_and_sources = new Dictionary <string, string>()
            {
                { "http://foo", source1 }
            };

            es.AddEvent(title: title2, url: "http://bar", source: source2, lat: null, lon: null, dtstart: dt2, dtend: min, allday: false, categories: null, description: test_description, location: test_location);

            var evt2 = es.events.Find(e => e.title == title2);

            evt2.urls_and_sources = new Dictionary <string, string>()
            {
                { "http://bar", source2 }
            };

            var response = es.Serialize();

            Assert.AreEqual(HttpStatusCode.Created, response.HttpResponse.status);

            var es2 = new ZonelessEventStore(calinfo).Deserialize();

            es2.SortEventList();

            Assert.That(es2.events.Count == 2);
            evt1 = es2.events[0];
            evt2 = es2.events[1];

            Assert.AreEqual(evt1.dtstart, dt1);
            Assert.AreEqual(evt2.dtstart, dt2);
            Assert.AreEqual(evt1.title, title1);
            Assert.AreEqual(evt2.title, title2);
        }
Exemplo n.º 13
0
        private ZonelessEventStore MakeNewEventStore()
        {
            var title1 = "e1";
            var title2 = "e2";

            var source1 = "s1";
            var source2 = "s2";

            var expected_year = 2020;
            var expected_hour = 1;

            var dt1 = new DateTime(expected_year, 1, 1, expected_hour, 1, 1);
            var dt2 = new DateTime(expected_year, 2, 2, expected_hour, 2, 2);

            var min = DateTime.MinValue;

            var test_category    = "test_category";
            var test_description = "test_description";
            var test_location    = "test_location";
            var es = new ZonelessEventStore(calinfo);

            es.AddEvent(title: title1, url: "http://foo", source: source1, lat: null, lon: null, dtstart: dt1, dtend: min, allday: false, categories: test_category, description: test_description, location: test_location);
            var evt1 = es.events.Find(e => e.title == title1);

            evt1.urls_and_sources = new Dictionary <string, string>()
            {
                { "http://foo", source1 }
            };

            es.AddEvent(title: title2, url: "http://bar", source: source2, lat: null, lon: null, dtstart: dt2, dtend: min, allday: false, categories: null, description: test_description, location: test_location);
            var evt2 = es.events.Find(e => e.title == title2);

            evt2.urls_and_sources = new Dictionary <string, string>()
            {
                { "http://foo", source1 }
            };
            return(es);
        }
Exemplo n.º 14
0
 private ZonelessEventStore GetEventStoreWithoutCaching(ICache cache)
 {
     var es = new ZonelessEventStore(this.calinfo);
     var obj_bytes = HttpUtils.FetchUrl(es.uri).bytes;
     return (ZonelessEventStore)BlobStorage.DeserializeObjectFromBytes(obj_bytes);
 }
Exemplo n.º 15
0
        // possibly filter an event list by view or count
        public List<ZonelessEvent> Filter(string view, int count, DateTime from, DateTime to, ZonelessEventStore es)
        {
            var events = es.events;

            FilterMode mode;

            if ( from != DateTime.MinValue && to != DateTime.MinValue )
                events = events.FindAll(evt => evt.dtstart >= from && evt.dtstart <= to);  // reduce to time window

            if (view != null) // reduce to matching categories
            {
                if (view.Contains('|'))
                    mode = FilterMode.or_list;
                else if (view.Contains(','))
                    mode = FilterMode.and_list;
                else
                    mode = FilterMode.single;

                var view_list = new List<string>();

                switch (mode)
                {
                    case FilterMode.and_list:
                        view_list = view.Split(',').ToList();
                        foreach (var view_item in view_list)
                        {
                            var and_item = view_item.Trim();
                            events = events.FindAll(evt => evt.categories != null && evt.categories.Split(',').ToList().Contains(and_item));
                        }
                        break;
                    case FilterMode.or_list:
                        view_list = view.Split('|').ToList();
                        events = events.FindAll(evt => evt.categories != null && evt.categories.Split(',').ToList().Any(x => view_list.Contains(x.Trim())));
                        break;
                    case FilterMode.single:
                        events = events.FindAll(evt => evt.categories != null && evt.categories.Split(',').ToList().Contains(view));
                        break;
                    default:
                        break;
                }

            }
            if (count != 0)   // reduce to first count events
                events = events.Take(count).ToList();
            return events;
        }
Exemplo n.º 16
0
 private static ZonelessEventStore ProcessUpcomingExample(string example, string source, Calinfo calinfo, Collector collector)
 {
     DeleteZonedObjects(calinfo.id);
     var es = new ZonedEventStore(calinfo, SourceType.upcoming);
     collector.CollectUpcoming(es, test: true);
     EventStore.CombineZonedEventStoresToZonelessEventStore(calinfo.id, settings);
     var zes = new ZonelessEventStore(calinfo).Deserialize();
     return zes;
 }
Exemplo n.º 17
0
 private static ContentResult view_calendar_helper(string id, ContentResult r, ZonedEventStore es_zoned, ZonelessEventStore es_zoneless)
 {
     foreach (var evt in es_zoned.events)
         es_zoneless.AddEvent(evt.title, evt.url.ToString(), evt.source, "", "", evt.dtstart.LocalTime, evt.dtend.LocalTime, evt.allday, evt.categories, evt.description, evt.location);
     es_zoneless.events = EventStore.UniqueByTitleAndStart(id, es_zoneless.events, save_tag_sources: false);
     es_zoneless.ExcludePastEvents();
     es_zoneless.SortEventList();
     var cr = new CalendarRenderer(id);
     r.Content = cr.RenderHtmlEventsOnly(es_zoneless, null, 0, DateTime.MinValue, DateTime.MinValue, new Dictionary<string, object>() { { "announce_time_of_day", false }, { "add_to_cal", false }, { "inline_descriptions", true }, {"taglist",false } } );
     return r;
 }
Exemplo n.º 18
0
 public List<string> GetTags(ZonelessEventStore es)
 {
     var dicts = MakeTagCloud(es);
     var tags = dicts.Select(x => x.Keys.First());
     return tags.ToList();
 }
Exemplo n.º 19
0
        public string RenderHtmlEventsOnly(ZonelessEventStore eventstore, string view, int count, DateTime from, DateTime to, Dictionary<string,object> args)
        {
            MaybeUseTestTemplate(args);

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

            //AdvanceToAnHourAgo(eventstore);

            var builder = new StringBuilder();

            RenderEventsAsHtml(eventstore, builder, args);

            var html = this.template_html.Replace("__EVENTS__", builder.ToString());

            if (args.ContainsKey("taglist") && (bool) args["taglist"] == true )
                html = this.InsertTagSelector(html, view, eventsonly: true);

            html = html.Replace("__APPDOMAIN__", ElmcityUtils.Configurator.appdomain);

            html = html.Replace("__ID__", this.id);
            html = html.Replace("__TITLE__", MakeTitle(view));
            html = html.Replace("__META__", MakeTitle(view) + " calendars happenings schedules");
            html = html.Replace("__CSSURL__", this.calinfo.css);
            html = MaybeOverrideTheme(args, html);
            html = html.Replace("__GENERATED__", System.DateTime.UtcNow.ToString());

            html = Utils.RemoveCommentSection(html, "SIDEBAR");
            html = Utils.RemoveCommentSection(html, "JQUERY_UI_CSS");
            html = Utils.RemoveCommentSection(html, "JQUERY_UI");
            html = Utils.RemoveCommentSection(html, "DATEPICKER");
            html = Utils.RemoveCommentSection(html, "HUBTITLE");
            html = Utils.RemoveCommentSection(html, "TAGS");

            return html;
        }
Exemplo n.º 20
0
        public string RenderHtmlEventsOnlyRaw(ZonelessEventStore eventstore, string view, int count, DateTime from, DateTime to, Dictionary<string, object> args)
        {
            this.ResetCounters();

            MaybeUseTestTemplate(args);

            eventstore = GetEventStore(eventstore, view, count, from, to);
            string title = null;
            DateTime dtstart = DateTime.MinValue;
            try
            {
                var sentinel = (string)args["raw_sentinel"];
                string[] separators = new string[] { "__|__" };
                var l = sentinel.Split(separators, StringSplitOptions.None);
                title = l[0];
                dtstart = DateTime.Parse(l[1]);
            }
            catch (Exception e)
            {
                GenUtils.PriorityLogMsg("exception", "RenderHtmlEventsOnlyRaw", e.Message + e.StackTrace);
            }

            var events = new List<ZonelessEvent>();

            if ((String.IsNullOrEmpty(title) == false) && (dtstart != DateTime.MinValue))
            {
                var found = false;
                foreach (var evt in eventstore.events)
                {
                    if (found)      // add everything after the sentinel
                    {
                        events.Add(evt);
                    }
                    if (evt.title == title && evt.dtstart == dtstart)
                    {
                        found = true;
                        continue;     // skip the sentinel
                    }

                }
            }
            eventstore.events = events;
            var builder = new StringBuilder();
            RenderEventsAsHtml(eventstore, builder, args);
            var html = builder.ToString();
            return html;
        }
Exemplo n.º 21
0
 public string RenderHtml(ZonelessEventStore es)
 {
     return RenderHtml(eventstore: es, view: null, count: 0, from: DateTime.MinValue, to: DateTime.MinValue, args:null);
 }
Exemplo n.º 22
0
        public string RenderHtml(ZonelessEventStore eventstore, string view, int count, DateTime from, DateTime to, Dictionary<string,object> args)
        {
            this.ResetCounters();

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

            AdvanceToAnHourAgo(eventstore);

            MaybeUseTestTemplate(args);

            var builder = new StringBuilder();
            RenderEventsAsHtml(eventstore, builder, args);

            var html = this.template_html.Replace("__EVENTS__", builder.ToString());

            if (args.ContainsKey("taglist") && (bool)args["taglist"] == true)
                html = this.InsertTagSelector(html, view, eventsonly: false);

            html = html.Replace("__APPDOMAIN__", ElmcityUtils.Configurator.appdomain);

            html = html.Replace("__ID__", this.id);
            html = html.Replace("__CSSURL__", this.calinfo.css);
            html = MaybeOverrideTheme(args, html);

            //html = html.Replace("__TITLE__", this.calinfo.title);
            html = html.Replace("__TITLE__", MakeTitle(view));
            html = html.Replace("__META__", MakeTitle(view) + " calendars happenings schedules");
            html = html.Replace("__WIDTH__", this.calinfo.display_width);
            html = html.Replace("__CONTACT__", this.calinfo.contact);
            html = html.Replace("__FEEDCOUNT__", this.calinfo.feed_count);

            /*
            string generated = String.Format("{0}\n{1}\n{2}\n{3}",
                    System.DateTime.UtcNow.ToString(),
                    System.Net.Dns.GetHostName(),
                    JsonConvert.SerializeObject(GenUtils.GetSettingsFromAzureTable("usersettings")),
                    JsonConvert.SerializeObject(this.calinfo) );
             */

            html = html.Replace("__GENERATED__", System.DateTime.UtcNow.ToString() + " : " + this.calinfo.version_description);

            return html;
        }
Exemplo n.º 23
0
 public string RenderEventsAsHtmlList(ZonelessEventStore es)
 {
     var sb = new StringBuilder();
     sb.Append(@"<ul style=""list-style-type:none"">");
     foreach (var evt in es.events)
         sb.Append(RenderEvtAsListItem(evt));
     sb.Append("</ul>");
     return sb.ToString();
 }
Exemplo n.º 24
0
        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);
            }
        }
Exemplo n.º 25
0
 // see http://blog.jonudell.net/2009/09/16/familiar-idioms/
 public List<Dictionary<string, int>> MakeTagCloud(ZonelessEventStore es)
 {
     if ( es == null )
         es = this.es_getter(this.cache);
     var tagquery =
         from evt in es.events
         where evt.categories != null
         from tag in evt.categories.Split(',')
         where tag != ""
         group tag by tag into occurrences
         orderby occurrences.Count() descending
         select new Dictionary<string, int>() { { occurrences.Key, occurrences.Count() } };
     return tagquery.ToList();
 }
Exemplo n.º 26
0
        public ActionResult view_cached_calendar(string feedurl, string id)
        {
            var r = new ContentResult();
            r.ContentType = "text/html";

            try
            {
                var calinfo = Utils.AcquireCalinfo(id);
                var es_zoneless = new ZonelessEventStore(calinfo);
                var es_zoned = Utils.GetFeedObjFromCache(calinfo, feedurl);
                r = view_calendar_helper(id, r, es_zoned, es_zoneless);
            }

            catch (Exception e)
            {
                r.Content = "Unable to view calendar. " + e.Message + e.StackTrace;
                return r;
            }
            return r;
        }
Exemplo n.º 27
0
        public void TagsAndUrlsAreCoalesced()
        {
            DeleteZonedObjects(keene_test_hub);

            var dtstart = new DateTimeWithZone(DateTime.Now, calinfo_keene.tzinfo);
            var dtend = new DateTimeWithZone(dtstart.LocalTime + TimeSpan.FromHours(1), calinfo_keene.tzinfo);

            var es1 = new ZonedEventStore(calinfo_keene, SourceType.ical);
            es1.AddEvent(
                "event",
                "http://1",
                "source1",
                dtstart,
                dtend,
                "1",
                "1",
                false,
                "cat1",
                "first event",
                "first location"
                );

            es1.Serialize();

            Assert.IsTrue(calinfo_keene.eventful);

            var es2 = new ZonedEventStore(calinfo_keene, SourceType.eventful);
            es2.AddEvent(
                "event",
                "http://2",
                "source2",
                dtstart,
                dtend,
                "2",
                "2",
                false,
                "cat2,cat2a",
                "second event",
                "second location"
                );

            es2.Serialize();

            Assert.IsTrue(calinfo_keene.upcoming);

            var es3 = new ZonedEventStore(calinfo_keene, SourceType.upcoming);
            es3.AddEvent(
                "event",
                "http://3",
                "source3",
                dtstart,
                dtend,
                "3",
                "3",
                false,
                "cat3,cat3a",
                "third event",
                "third location"
                );

            es3.AddEvent(
                "another event",
                "http://4",
                "source4",
                dtstart,
                dtend,
                "4",
                "4",
                false,
                "cat4,cat4a",
                "fourth event",
                "fourth location"
                );

            es3.Serialize();

            EventStore.CombineZonedEventStoresToZonelessEventStore(keene_test_hub, settings);
            var es = new ZonelessEventStore(calinfo_keene).Deserialize();

            Assert.That(es.events.Count == 2);

            var evt = es.events.Find(e => e.title == "event");

            Assert.That(evt.categories == "cat1,cat2,cat2a,cat3,cat3a");

            Assert.That(evt.urls_and_sources.Keys.Count == 3);
            Assert.That(evt.urls_and_sources["http://1"] == "source1");
            Assert.That(evt.urls_and_sources["http://2"] == "source2");
            Assert.That(evt.urls_and_sources["http://3"] == "source3");

            //Assert.That(evt.list_of_urls_and_sources[0][0] == "http://1" && evt.list_of_urls_and_sources[0][1] == "source1");
            //Assert.That(evt.list_of_urls_and_sources[1][0] == "http://2" && evt.list_of_urls_and_sources[1][1] == "source2");
            //Assert.That(evt.list_of_urls_and_sources[2][0] == "http://3" && evt.list_of_urls_and_sources[2][1] == "source3");
        }
Exemplo n.º 28
0
        public ActionResult view_calendar(string feedurl, string id)
        {
            var r = new ContentResult();
            r.ContentType = "text/html";

            if (id != String.Empty && Utils.CachedFeedObjExists(id, feedurl))
                return view_cached_calendar(feedurl, id);

            DDay.iCal.iCalendar ical;
            var source = ""; // unneeded for this single-cal purpose
            try
            {
                ical = Utils.iCalFromFeedUrl(feedurl, settings);
            }
            catch (Exception e)
            {
                r.Content = string.Format(@"Sorry, unable to parse {0} as an iCalendar feed. The error was: {1}", feedurl, e.Message + e.StackTrace);
                return r;
            }

            var events_to_include = new List<DDay.iCal.Event>();
            var event_recurrence_types = new Dictionary<DDay.iCal.Event, Collector.RecurrenceType>();
            var calinfo = new Calinfo(id);
            var collector = new Collector(calinfo, settings);
            try
            {
                DateTime utc_midnight_in_tz = Utils.MidnightInTz(calinfo.tzinfo).UniversalTime;
                DateTime then = utc_midnight_in_tz.AddDays(calinfo.icalendar_horizon_days);
                collector.FeedGather(utc_midnight_in_tz, then, 0, ical, source, events_to_include, event_recurrence_types, false);
                var es_zoned = new ZonedEventStore(calinfo, SourceType.ical);
                var fr = new FeedRegistry(id);
                foreach (var evt in events_to_include)
                    collector.AddIcalEvent(evt, fr, es_zoned, feedurl, source);
                var es_zoneless = new ZonelessEventStore(calinfo);
                r = view_calendar_helper(id, r, es_zoned, es_zoneless);
            }
            catch (Exception e)
            {
                r.Content = "Unable to view calendar. " + e.Message + e.StackTrace;
                return r;
            }
            return r;
        }
Exemplo n.º 29
0
 private static void HillsideExampleIsCorrectObj(ZonelessEventStore zes, string search, string replace)
 {
     var title_substr = "Afternoon Tea 3";
     if (search != null && replace != null)
         title_substr = title_substr.Replace(search, replace);
     Assert.That(zes.events.Count > 0);  // it's a recurring event, don't need/want to test for exact count
     var evt = zes.events[0];
     Assert.That(evt.title.StartsWith(title_substr));
     Assert.That(evt.dtstart.Hour == 15);
     Assert.That(evt.dtstart.Minute == 0);
     Assert.That(evt.dtstart.Second == 0);
 }
Exemplo n.º 30
0
        public void EventfulUrlsAreNormalized()
        {
            DeleteZonedObjects(keene_test_hub);

            var dtstart = new DateTimeWithZone(DateTime.Now, calinfo_keene.tzinfo);
            var dtend = new DateTimeWithZone(dtstart.LocalTime + TimeSpan.FromHours(1), calinfo_keene.tzinfo);

            var es1 = new ZonedEventStore(calinfo_keene, SourceType.ical);
            es1.AddEvent(
                "event",
                "http://eventful.com/E0-001-039987477-3",
                "The Blind Pig",
                dtstart,
                dtend,
                "1",
                "1",
                false,
                "music",
                "first event",
                "first location"
                );

            es1.Serialize();

            var es2 = new ZonedEventStore(calinfo_keene, SourceType.eventful);
            es2.AddEvent(
                "event",
                "http://eventful.com/events/E0-001-039987477-3",
                "Blind Pig",
                dtstart,
                dtend,
                "1",
                "1",
                false,
                "eventful",
                "first event",
                "first location"
                );

            es2.Serialize();

            EventStore.CombineZonedEventStoresToZonelessEventStore(keene_test_hub, settings);

            var es = new ZonelessEventStore(calinfo_keene).Deserialize();

            Assert.That(es.events.Count == 1);

            var evt = es.events.Find(e => e.title == "event");

            var categories = evt.categories.Split(',').ToList();
            categories.Sort();
            Assert.That(categories.SequenceEqual(new List<string>() { "eventful", "music" }));
            Assert.That(evt.urls_and_sources.Keys.Count == 1);
        }
Exemplo n.º 31
0
 // return an eventstore with just today's events for this hub
 public ZonelessEventStore FindTodayEvents()
 {
     ZonelessEventStore es;
     try
     {
         es = this.es_getter(this.cache);
         es.events = es.events.FindAll(e => Utils.DtIsTodayInTz(e.dtstart, this.calinfo.tzinfo));
         var events_having_dt = es.events.FindAll(evt => ZonelessEventStore.IsZeroHourMinSec(evt) == false);
         var events_not_having_dt = es.events.FindAll(evt => ZonelessEventStore.IsZeroHourMinSec(evt) == true);
         es.events = new List<ZonelessEvent>();
         foreach (var evt in events_having_dt)
             es.events.Add(evt);
         foreach (var evt in events_not_having_dt)
             es.events.Add(evt);
     }
     catch (Exception e)
     {
         es = new ZonelessEventStore(this.calinfo);
         GenUtils.PriorityLogMsg("exception", "CalendarRenderer.FindTodayEvents", e.Message + e.StackTrace);
     }
     return es;
 }
Exemplo n.º 32
0
        public void UpcomingUrlsAreNormalized()
        {
            DeleteZonedObjects(keene_test_hub);

            var dtstart = new DateTimeWithZone(DateTime.Now, calinfo_keene.tzinfo);
            var dtend = new DateTimeWithZone(dtstart.LocalTime + TimeSpan.FromHours(1), calinfo_keene.tzinfo);

            var es1 = new ZonedEventStore(calinfo_keene, SourceType.ical);
            es1.AddEvent(
                "event",
                "http://upcoming.yahoo.com/event/8504144/",
                "Comedy Showcase",
                dtstart,
                dtend,
                "1",
                "1",
                false,
                "comedy",
                "first event",
                "first location"
                );

            es1.Serialize();

            var es2 = new ZonedEventStore(calinfo_keene, SourceType.upcoming);
            es2.AddEvent(
                "event",
                "http://upcoming.yahoo.com/event/8504144",
                "Ann Arbor Comedy Showcase",
                dtstart,
                dtend,
                "1",
                "1",
                false,
                "upcoming",
                "first event",
                "first location"
                );

            es2.Serialize();

            EventStore.CombineZonedEventStoresToZonelessEventStore(keene_test_hub, settings);

            var es = new ZonelessEventStore(calinfo_keene).Deserialize();
            Assert.That(es.events.Count == 1);

            var evt = es.events.Find(e => e.title == "event");

            var categories = evt.categories.Split(',').ToList();
            categories.Sort();
            Assert.That(categories.SequenceEqual(new List<string>() { "comedy", "upcoming" }));
            Assert.That(evt.urls_and_sources.Keys.Count == 1);
        }
Exemplo n.º 33
0
        public string RenderIcs(ZonelessEventStore eventstore, string view, int count, DateTime from, DateTime to, Dictionary<string,object> args)
        {
            eventstore = GetEventStore(eventstore, view, count, from, to);
            var ical = new DDay.iCal.iCalendar();
            Collector.AddTimezoneToDDayICal(ical, this.calinfo.tzinfo);
            var tzid = this.calinfo.tzinfo.Id;

            foreach (var evt in eventstore.events)
            {
                var ical_evt = new DDay.iCal.Event();
                ical_evt.Start = new DDay.iCal.iCalDateTime(evt.dtstart);
                ical_evt.Start.TZID = tzid;
                ical_evt.End = new DDay.iCal.iCalDateTime(evt.dtend);
                ical_evt.End.TZID = tzid;
                ical_evt.Summary = evt.title;
                ical_evt.Url = new Uri(evt.url);

                if (evt.description != null)
                    ical_evt.Description = evt.description + " " + evt.url;
                else
                    ical_evt.Description = evt.url;

                ical_evt.Description = evt.description;
                ical_evt.Location = evt.location;
                Collector.AddCategoriesFromCatString(ical_evt, evt.categories);
                ical.Children.Add(ical_evt);
            }

            var ics_text = Utils.SerializeIcalToIcs(ical);

            return ics_text;
        }
Exemplo n.º 34
0
 private static ZonelessEventStore ProcessIcalExample(string example, string source, Calinfo calinfo, FeedRegistry fr, Collector collector)
 {
     DeleteZonedObjects(calinfo.id);
     var feedurl = BlobStorage.MakeAzureBlobUri("admin", example + ".ics", false).ToString();
     fr.AddFeed(feedurl, source);
     var es = new ZonedEventStore(calinfo, SourceType.ical);
     collector.CollectIcal(fr, es, false);
     EventStore.CombineZonedEventStoresToZonelessEventStore(calinfo.id, settings);
     var zes = new ZonelessEventStore(calinfo).Deserialize();
     return zes;
 }
Exemplo n.º 35
0
 public string RenderJson(ZonelessEventStore eventstore, string view, int count, DateTime from, DateTime to, Dictionary<string, object> args)
 {
     eventstore = GetEventStore(eventstore, view, count, from, to);
     for (var i = 0; i < eventstore.events.Count; i++)
     {
         var evt = eventstore.events[i];
         if ( this.calinfo.hub_enum == HubType.where )
         {
             evt.lat = evt.lat != null ? evt.lat : this.calinfo.lat;
             evt.lon = evt.lon != null ? evt.lon : this.calinfo.lon;
         }
         // provide utc so browsers receiving the json don't apply their own timezones
         evt = ZonelessEventStore.UniversalFromLocalAndTzinfo(evt, this.calinfo.tzinfo);
         eventstore.events[i] = evt;
     }
     return JsonConvert.SerializeObject(eventstore.events);
 }
Exemplo n.º 36
0
 // the CalendarRenderer object uses this to get the pickled object that contains an eventstore,
 // from the CalendarRender's cache if available, else fetching bytes
 private ZonelessEventStore GetEventStoreWithCaching(ICache cache)
 {
     var es = new ZonelessEventStore(this.calinfo);
     var obj_bytes = (byte[])CacheUtils.RetrieveBlobAndEtagFromServerCacheOrUri(cache, es.uri)["response_body"];
     return (ZonelessEventStore)BlobStorage.DeserializeObjectFromBytes(obj_bytes);
 }
Exemplo n.º 37
0
 public string RenderRss(ZonelessEventStore eventstore, string view, int count, DateTime from, DateTime to, Dictionary<string,object> args)
 {
     try
     {
         eventstore = GetEventStore(eventstore, view, count, from, to);
         var query = string.Format("view={0}&count={1}", view, count);
         return Utils.RssFeedFromEventStore(this.id, query, eventstore);
     }
     catch (Exception e)
     {
         GenUtils.PriorityLogMsg("exception", String.Format("RenderRss: view {0}, count {1}", view, count), e.Message);
         return String.Empty;
     }
 }
Exemplo n.º 38
0
 private ZonelessEventStore CreateFilterable(Calinfo calinfo)
 {
     var filterable = new ZonelessEventStore(calinfo);
     filterable.AddEvent("e1", "", "s1", null, null, DateTime.Parse("2013/11/01 8 AM"), DateTime.MinValue, false, null, null, null);
     filterable.AddEvent("e2", "", "s1", null, null, DateTime.Parse("2013/11/02 8 AM"), DateTime.MinValue, false, null, null, null);
     filterable.AddEvent("e3", "", "s2", null, null, DateTime.Parse("2013/11/03 8 AM"), DateTime.MinValue, false, null, null, null);
     filterable.AddEvent("e4", "", "s2", null, null, DateTime.Parse("2013/11/04 8 AM"), DateTime.MinValue, false, null, null, null);
     filterable.AddEvent("e5", "", "s2", null, null, DateTime.Parse("2013/11/05 8 AM"), DateTime.MinValue, false, "music", null, null);
     Assert.That(filterable.events.Count == 5);
     return filterable;
 }
Exemplo n.º 39
0
        private ZonelessEventStore MakeNewEventStore()
        {
            var title1 = "e1";
            var title2 = "e2";

            var source1 = "s1";
            var source2 = "s2";

            var expected_year = 2020;
            var expected_hour = 1;

            var dt1 = new DateTime(expected_year, 1, 1, expected_hour, 1, 1);
            var dt2 = new DateTime(expected_year, 2, 2, expected_hour, 2, 2);

            var min = DateTime.MinValue;

            var test_category = "test_category";
            var test_description = "test_description";
            var test_location = "test_location";
            var es = new ZonelessEventStore(calinfo);

            es.AddEvent(title: title1, url: "http://foo", source: source1, lat: null, lon: null, dtstart: dt1, dtend: min, allday: false, categories: test_category, description: test_description, location: test_location);
            var evt1 = es.events.Find(e => e.title == title1);
            evt1.urls_and_sources = new Dictionary<string, string>() { { "http://foo", source1 } };

            es.AddEvent(title: title2, url: "http://bar", source: source2, lat: null, lon: null, dtstart: dt2, dtend: min, allday: false, categories: null, description: test_description, location: test_location);
            var evt2 = es.events.Find(e => e.title == title2);
            evt2.urls_and_sources = new Dictionary<string, string>() { { "http://foo", source1 } };
            return es;
        }
Exemplo n.º 40
0
        public string RenderHtmlForMobile(ZonelessEventStore eventstore, string view, int count, DateTime from, DateTime to, Dictionary<string,object> args)
        {
            //GenUtils.LogMsg("info", "RenderForMobile", JsonConvert.SerializeObject(args));
            this.ResetCounters();

            MaybeUseTestTemplate(args);

            eventstore = GetEventStore(eventstore, view, count, from, to);
            if (from == DateTime.MinValue && to == DateTime.MinValue)
                AdvanceToAnHourAgo(eventstore);

            count = (int) args["mobile_event_count"];                        // wait until now to apply the reduction
            eventstore.events = eventstore.events.Take(count).ToList();

            // assume a css link like this:
            // <link type="text/css" rel="stylesheet" href="http://elmcity.cloudapp.net/get_css_theme?theme_name=a2chron"/>

            var css = (string) args["css"];
            var theme = css.Replace("http://elmcity.cloudapp.net/get_css_theme?theme_name=", "");
            args["theme"] = theme;

            var html = RenderHtmlEventsOnly(eventstore, view, count, from, to, args);

            string mobile_long = "";
            string ua = "";
            if (args.ContainsKey("mobile_long") && args.ContainsKey("ua"))
            {
                mobile_long = (string)args["mobile_long"];   // the longest dimension of detected mobile device
                ua = (string)args["ua"];                     // user agent
            }

            html = html.Replace("get_css_theme?", string.Format("get_css_theme?mobile=yes&mobile_long={0}&ua={1}&", mobile_long, ua));

            //html = this.InsertTagSelector(html, (string) args["view"]);

            /*
            html = html.Replace("__MOBILE__", "yes");                          // todo: remove this when conversion to server-side method is complete
            if (args.ContainsKey("mobile_long") && args.ContainsKey("mobile_short"))
            {
                html = html.Replace("__MOBILE_LONG__", args["mobile_long"].ToString());
                html = html.Replace("__MOBILE_SHORT__", args["mobile_short"].ToString());
            }
             */
            return html;
        }
Exemplo n.º 41
0
 // the default html rendering chunks by day, this method processes the raw list of events into
 // the ZonelessEventStore's event_dict like so:
 // key: d20100710
 // value: [ <ZonelessEvent>, <ZonelessEvent> ... ]
 public static void OrganizeByDate(ZonelessEventStore es)
 {
     es.GroupEventsByDatekey();
     es.SortEventSublists();
     es.SortDatekeys();
 }