Пример #1
0
        public void SerializeTwoZonedEvents()
        {
            var zoned = new ZonedEventStore(calinfo, SourceType.ical);

            zoned.AddEvent(in_evt0_zoned.title, in_evt0_zoned.url, in_evt0_zoned.source, in_evt0_zoned.dtstart, in_evt0_zoned.dtend, test_lat, test_lon, in_evt0_zoned.allday, test_category, test_description, test_location);
            zoned.AddEvent(in_evt1_zoned.title, in_evt1_zoned.url, in_evt1_zoned.source, in_evt1_zoned.dtstart, in_evt1_zoned.dtend, test_lat, test_lon, in_evt1_zoned.allday, test_category, test_description, test_location);
            Assert.AreEqual(2, zoned.events.Count);
            var response = bs.SerializeObjectToAzureBlob(zoned, test_container, zoned.objfile);

            Assert.AreEqual(HttpStatusCode.Created, response.HttpResponse.status);
        }
Пример #2
0
 public void AddZonedEventIncrementsCount()
 {
     var zoned = new ZonedEventStore(calinfo, SourceType.ical);
     Assert.AreEqual(0, zoned.events.Count);
     zoned.AddEvent(in_evt0_zoned.title, in_evt0_zoned.url, in_evt0_zoned.source, in_evt0_zoned.dtstart, in_evt0_zoned.dtend, test_lat, test_lon, false, in_evt0_zoned.categories, test_description, test_location);
     Assert.AreEqual(1, zoned.events.Count);
 }
Пример #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");
        }
Пример #4
0
        public void AddZonedEventIncrementsCount()
        {
            var zoned = new ZonedEventStore(calinfo, SourceType.ical);

            Assert.AreEqual(0, zoned.events.Count);
            zoned.AddEvent(in_evt0_zoned.title, in_evt0_zoned.url, in_evt0_zoned.source, in_evt0_zoned.dtstart, in_evt0_zoned.dtend, test_lat, test_lon, false, in_evt0_zoned.categories, test_description, test_location);
            Assert.AreEqual(1, zoned.events.Count);
        }
Пример #5
0
        public void SerializeAndDeserializeZonedEventStoreYieldsExpectedEvents()
        {
            var es = new ZonedEventStore(calinfo, SourceType.ical);

            es.AddEvent(title: title1, url: "http://foo", source: source1, dtstart: dt1_with_zone, dtend: min_with_zone, allday: false, lat: test_lat, lon: test_lon, categories: test_category, description: test_description, location: test_location);
            es.AddEvent(title: title2, url: "http://bar", source: source2, dtstart: dt2_with_zone, dtend: min_with_zone, lat: test_lat, lon: test_lon, allday: false, categories: test_category, description: test_description, location: test_location);

            var response = bs.SerializeObjectToAzureBlob(es, test_container, es.objfile);

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

            var uri = BlobStorage.MakeAzureBlobUri(test_container, es.objfile, false);
            var es2 = (ZonedEventStore)BlobStorage.DeserializeObjectFromUri(uri);

            var evt1 = es2.events.First();
            var evt2 = es2.events.Last();

            Assert.AreEqual(evt1.dtstart.UniversalTime.Ticks, dt1_with_zone.UniversalTime.Ticks);
            Assert.AreEqual(evt2.dtstart.UniversalTime.Ticks, dt2_with_zone.UniversalTime.Ticks);
            Assert.AreEqual(evt1.title, title1);
            Assert.AreEqual(evt2.title, title2);
        }
Пример #6
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);
        }
Пример #7
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");
        }
Пример #8
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);
        }
Пример #9
0
        public void AddUpcomingEvent(ZonedEventStore es, string venue_name, XElement evt)
        {
            var title = evt.Attribute("name").Value;
            var event_url = "http://upcoming.yahoo.com/event/" + evt.Attribute("id").Value;
            var source = venue_name;
            var venue_id = evt.Attribute("venue_id").Value;
            var venue_url = "http://upcoming.yahoo.com/venue/" + venue_id;

            string lat = this.calinfo.lat;  // default to hub's lat/lon
            string lon = this.calinfo.lon;

            try
            {
                lat = evt.Attribute("latitude").Value;
                lon = evt.Attribute("longitude").Value;
            }
            catch
            {
                GenUtils.LogMsg("warning", "AddUpcomingEvent", "cannot parse lat/lon");
            }

            string categories = "upcoming";

            if (evt.Attribute("tags") != null)
            {
                var evt_tags = evt.Attribute("tags").Value.Split(',');
                if (evt_tags.Length > 0)
                {
                    var intersection = this.tags.Intersect(evt_tags);
                    categories += "," + String.Join(",", intersection.ToArray());
                }
            }

            ustats.eventcount++;

            bool all_day = false;
            var dtstart = DateTimeWithZoneFromUpcomingXEvent(evt, ref all_day);

            string location = venue_name;
            string venue_address = evt.Attribute("venue_address").Value;
            if (!String.IsNullOrEmpty(venue_address))
                location += ", " + venue_address;

            var evt_tmp = MakeTmpEvt(this.calinfo, dtstart, DateTimeWithZone.MinValue(this.calinfo.tzinfo), title, url: event_url, location: location, description: source, lat: lat, lon: lon, allday: all_day);
            AddEventToDDayIcal(upcoming_ical, evt_tmp);

            var min = DateTimeWithZone.MinValue(this.calinfo.tzinfo);

            es.AddEvent(title: title, url: event_url, source: source, dtstart: dtstart, dtend: min, lat: lat, lon: lon, allday: all_day, categories: categories, description: null, location: location);
        }
Пример #10
0
        // put the event into a) the eventstore, and b) the per-type intermediate icalendar object
        public void AddIcalEvent(DDay.iCal.Event evt, FeedRegistry fr, ZonedEventStore es, string feedurl, string source)
        {
            try
            {
                evt = NormalizeIcalEvt(evt, feedurl, source);

                DateTimeWithZone dtstart;
                DateTimeWithZone dtend;
                var tzinfo = this.calinfo.tzinfo;

                //dtstart = Utils.DtWithZoneFromICalDateTime(evt.Start.Value, tzinfo);
                //dtend = (evt.DTEnd == null) ? new Utils.DateTimeWithZone(DateTime.MinValue, tzinfo) : Utils.DtWithZoneFromICalDateTime(evt.End.Value, tzinfo);

                //dtstart = new Utils.DateTimeWithZone(evt.Start.Value,tzinfo);
                //dtend = new Utils.DateTimeWithZone(evt.End.Value,tzinfo);

                var localstart = evt.DTStart.IsUniversalTime ? TimeZoneInfo.ConvertTimeFromUtc(evt.Start.UTC, tzinfo) : evt.Start.Local;
                dtstart = new DateTimeWithZone(localstart, tzinfo);

                var localend = evt.DTEnd.IsUniversalTime ? TimeZoneInfo.ConvertTimeFromUtc(evt.End.UTC, tzinfo) : evt.End.Local;
                dtend = new DateTimeWithZone(localend, tzinfo);

                MakeGeo(this.calinfo, evt, this.calinfo.lat, this.calinfo.lon);

                string categories = null;
                if (evt.Categories != null && evt.Categories.Count() > 0)
                    categories = string.Join(",", evt.Categories.ToList().Select(cat => cat.ToString().ToLower()));

                string description = this.calinfo.has_descriptions ? evt.Description : null;

                string location = this.calinfo.has_locations ? evt.Location : null;

                es.AddEvent(title: evt.Summary, url: evt.Url.ToString(), source: source, dtstart: dtstart, dtend: dtend, lat: this.calinfo.lat, lon: this.calinfo.lon, allday: evt.IsAllDay, categories: categories, description: description, location: location);

                var evt_tmp = MakeTmpEvt(this.calinfo, dtstart: dtstart, dtend: dtend, title: evt.Summary, url: evt.Url.ToString(), location: evt.Location, description: source, lat: this.calinfo.lat, lon: this.calinfo.lon, allday: evt.IsAllDay);
                AddEventToDDayIcal(ical_ical, evt_tmp);

                if ( fr.stats.ContainsKey(feedurl) )   // won't be true when adding to the per-feed obj cache
                    fr.stats[feedurl].loaded++;        // and this will have already been counted by the all-feeds AddIcalEvent

            }
            catch (Exception e)
            {
                GenUtils.PriorityLogMsg("exception", "AddIcalEvent", source + ": " + e.Message + ": " + evt.Summary);
            }
        }
Пример #11
0
        public void AddFacebookEvent(ZonedEventStore es, FacebookEvent fb_event, DateTimeWithZone dtstart)
        {
            var title = fb_event.name;
            var event_url = "http://www.facebook.com/event.php?eid=" + fb_event.id;
            var source = "facebook";
            var location = fb_event.location;

            var all_day = false;

            fbstats.eventcount++;

            var evt_tmp = MakeTmpEvt(this.calinfo, dtstart, DateTimeWithZone.MinValue(this.calinfo.tzinfo), title, url: event_url, location: location, description: source, lat: this.calinfo.lat, lon: this.calinfo.lon, allday: all_day);
            AddEventToDDayIcal(facebook_ical, evt_tmp);

            var min = DateTimeWithZone.MinValue(this.calinfo.tzinfo);

            es.AddEvent(title: title, url: event_url, source: source, dtstart: dtstart, dtend: min, lat: null, lon: null, allday: all_day, categories: "facebook", description: null, location: location);
        }
Пример #12
0
        public void AddEventfulEvent(ZonedEventStore es, string venue_name, XElement evt)
        {
            var str_dtstart = XmlUtils.GetXeltValue(evt, ElmcityUtils.Configurator.no_ns, "start_time");
            DateTime dtstart = Utils.LocalDateTimeFromLocalDateStr(str_dtstart);
            var dtstart_with_tz = new DateTimeWithZone(dtstart, this.calinfo.tzinfo);

            if (dtstart_with_tz.UniversalTime < Utils.MidnightInTz(this.calinfo.tzinfo).UniversalTime)
                return;

            var no_ns = ElmcityUtils.Configurator.no_ns;

            var event_id = evt.Attribute("id").Value;
            var event_owner = XmlUtils.GetXeltValue(evt, no_ns, "owner");
            var title = XmlUtils.GetXeltValue(evt, no_ns, "title");
            var venue_url = XmlUtils.GetXeltValue(evt, no_ns, "venue_url");
            var all_day = XmlUtils.GetXeltValue(evt, no_ns, "all_day") == "1";
            var venue_address = XmlUtils.GetXeltValue(evt, no_ns, "venue_address");

            string lat = this.calinfo.lat;   // default to hub lat/lon
            string lon = this.calinfo.lon;

            lat = XmlUtils.GetXeltValue(evt, no_ns, "latitude");
            lon = XmlUtils.GetXeltValue(evt, no_ns, "longitude");

            if (lat == null || lon == null)
            {
                GenUtils.LogMsg("warning", "AddEventfulEvent", "no lat/lon");
            }

            var category = XmlUtils.GetXeltValue(evt, ElmcityUtils.Configurator.no_ns, "category");
            if (String.IsNullOrWhiteSpace(category))
                category = SourceType.eventful.ToString();
            else
                category = SourceType.eventful.ToString() + "," + category;

            string event_url = "http://eventful.com/events/" + event_id;

            string source = venue_name;

            if (String.IsNullOrEmpty(source))
                source = "Unnamed Eventful Venue";
            string location;
            if (!String.IsNullOrEmpty(source))
            {
                location = venue_name;
                if (!String.IsNullOrEmpty(venue_address))
                    location += ", " + venue_address;
            }
            else
            {
                location = event_url;
            }

            estats.eventcount++;

            var evt_tmp = MakeTmpEvt(this.calinfo, dtstart_with_tz, DateTimeWithZone.MinValue(this.calinfo.tzinfo), title, url: event_url, location: location, description: source, lat: lat, lon: lon, allday: all_day);
            AddEventToDDayIcal(eventful_ical, evt_tmp);

            var min = DateTimeWithZone.MinValue(this.calinfo.tzinfo);

            // suppress description to minimize amount of eventful info carried in the event packet
            // allow location but it is subject to the per-hub locations setting (calinfo.has_locations)
            es.AddEvent(title: title, url: event_url, source: source, dtstart: dtstart_with_tz, dtend: min, lat: lat, lon: lon, allday: all_day, categories: category, description: null, location: location);
        }
Пример #13
0
        public void AddEventBriteEvent(ZonedEventStore es, XElement evt, DateTimeWithZone dtstart, DateTimeWithZone dtend)
        {
            string title;
            string event_url;
            string source;
            bool all_day;
            string categories;
            var evt_tmp = MakeDDayEventFromEventBriteEvent(evt, out title, out event_url, out source, out all_day, out categories);

            AddEventToDDayIcal(eventbrite_ical, evt_tmp);

            var min = DateTimeWithZone.MinValue(this.calinfo.tzinfo);

            // todo: dig out location from http://developer.eventbrite.com/doc/events/event_search/

            es.AddEvent(title: title, url: event_url, source: source, dtstart: dtstart, dtend: dtend, lat: null, lon: null, allday: all_day, categories: categories, description: null, location: null);
        }
Пример #14
0
 public void SerializeTwoZonedEvents()
 {
     var zoned = new ZonedEventStore(calinfo, SourceType.ical);
     zoned.AddEvent(in_evt0_zoned.title, in_evt0_zoned.url, in_evt0_zoned.source, in_evt0_zoned.dtstart, in_evt0_zoned.dtend, test_lat, test_lon, in_evt0_zoned.allday, test_category, test_description, test_location);
     zoned.AddEvent(in_evt1_zoned.title, in_evt1_zoned.url, in_evt1_zoned.source, in_evt1_zoned.dtstart, in_evt1_zoned.dtend, test_lat, test_lon, in_evt1_zoned.allday, test_category, test_description, test_location);
     Assert.AreEqual(2, zoned.events.Count);
     var response = bs.SerializeObjectToAzureBlob(zoned, test_container, zoned.objfile);
     Assert.AreEqual(HttpStatusCode.Created, response.HttpResponse.status);
 }
Пример #15
0
        public void SerializeAndDeserializeZonedEventStoreYieldsExpectedEvents()
        {
            var es = new ZonedEventStore(calinfo, SourceType.ical);
            es.AddEvent(title:title1, url:"http://foo", source:source1, dtstart:dt1_with_zone, dtend:min_with_zone, allday:false, lat:test_lat, lon:test_lon, categories:test_category, description:test_description, location: test_location);
            es.AddEvent(title:title2, url:"http://bar", source:source2, dtstart:dt2_with_zone, dtend:min_with_zone, lat:test_lat, lon:test_lon, allday:false, categories:test_category, description:test_description, location: test_location);

            var response = bs.SerializeObjectToAzureBlob(es, test_container, es.objfile);
            Assert.AreEqual(HttpStatusCode.Created, response.HttpResponse.status);

            var uri = BlobStorage.MakeAzureBlobUri(test_container, es.objfile,false);
            var es2 = (ZonedEventStore)BlobStorage.DeserializeObjectFromUri(uri);

            var evt1 = es2.events.First();
            var evt2 = es2.events.Last();

            Assert.AreEqual(evt1.dtstart.UniversalTime.Ticks, dt1_with_zone.UniversalTime.Ticks);
            Assert.AreEqual(evt2.dtstart.UniversalTime.Ticks, dt2_with_zone.UniversalTime.Ticks);
            Assert.AreEqual(evt1.title, title1);
            Assert.AreEqual(evt2.title, title2);
        }