public AddEvents ( string collection, IEnumerable | ||
collection | string | Collection name |
eventsInfo | IEnumerable | Collection of events to add |
addOns | IEnumerable |
Optional collection of Data Enhancement Add-ons |
리턴 | void |
private static int SendEventsToKeep(Keen.Core.KeenClient keenClient, List <AppModel> eventsToSend, MongoDBWrapper mongoDB) { try { // Adding Event to Keen.IO keenClient.AddEvents("PlayStore2014", eventsToSend); // Incrementing Counter _appsCounter += eventsToSend.Count; // Console feedback Every 100 Processed Apps if (_appsCounter % 100 == 0) { Console.WriteLine("Uploaded : " + _appsCounter); } foreach (var e in eventsToSend) { mongoDB.SetUpdated(e.Url); } return(eventsToSend.Count); } catch (Exception ex) { Console.WriteLine("\n\t" + ex.Message); } return(0); }
public void AddEvents_InvalidProject_Throws() { var settings = new ProjectSettingsProvider(projectId: "X", writeKey: settingsEnv.WriteKey); var client = new KeenClient(settings); if (UseMocks) client.Event = new EventMock(settings, AddEvents: new Func<JObject, IProjectSettings, IEnumerable<CachedEvent>>((e, p) => { if ((p == settings) &&(p.ProjectId=="X")) throw new KeenException(); else throw new Exception("Unexpected value"); })); Assert.Throws<KeenException>(() => client.AddEvents("AddEventTest", new []{ new {AProperty = "AValue" }})); }
public void AddEvents_PartialFailure_Throws() { var client = new KeenClient(settingsEnv); if (UseMocks) client.Event = new EventMock(settingsEnv, AddEvents: new Func<JObject, IProjectSettings, IEnumerable<CachedEvent>>((e, p) => { var err = e.SelectToken("$.AddEventTest[2]") as JObject; if (null == err) throw new Exception("Unexpected error, test data not found"); return new List<CachedEvent>(){new CachedEvent("AddEventTest", e)}; })); object invalidEvent = new ExpandoObject(); ((IDictionary<string, object>)invalidEvent).Add("$" + new string('.', 260), "AValue"); var events = (from i in Enumerable.Range(1, 2) select new { AProperty = "AValue" + i }).ToList<object>(); events.Add(invalidEvent); Assert.Throws<KeenBulkException>(() => client.AddEvents("AddEventTest", events)); }
public void AddEvents_Cache_Success() { var client = new KeenClient(settingsEnv, new EventCacheMemory()); if (UseMocks) client.Event = new EventMock(settingsEnv, AddEvents: new Func<JObject, IProjectSettings, IEnumerable<CachedEvent>>((e, p) => { // Should not be called with caching enabled Assert.Fail(); return new List<CachedEvent>(); })); var events = from i in Enumerable.Range(1, 3) select new { AProperty = "AValue" + i }; Assert.DoesNotThrow(() => client.AddEvents("AddEventTest", events)); // reset the AddEvents mock if (UseMocks) client.Event = new EventMock(settingsEnv, AddEvents: new Func<JObject, IProjectSettings, IEnumerable<CachedEvent>>((e, p) => { Assert.True(p == settingsEnv, "Incorrect settings"); Assert.NotNull(e.Property("AddEventTest"), "Expected collection not found"); Assert.AreEqual(e.Property("AddEventTest").Value.AsEnumerable().Count(), 3, "Expected exactly 3 collection members"); foreach (dynamic q in ((dynamic)e).AddEventTest) Assert.NotNull(q.keen.timestamp, "keen.timestamp properties should exist"); return new List<CachedEvent>(); })); Assert.DoesNotThrow(() => client.SendCachedEvents()); }
public void AddEvents_NoCache_Success() { var client = new KeenClient(settingsEnv); var done = false; if (UseMocks) client.Event = new EventMock(settingsEnv, AddEvents: new Func<JObject, IProjectSettings, IEnumerable<CachedEvent>>((e, p) => { done = true; Assert.True(p == settingsEnv, "Incorrect settings"); Assert.NotNull(e.Property("AddEventTest"), "Expected collection not found"); Assert.AreEqual(e.Property("AddEventTest").Value.AsEnumerable().Count(), 3, "Expected exactly 3 collection members"); foreach (dynamic q in ((dynamic)e).AddEventTest) Assert.NotNull(q.keen.timestamp, "keen.timestamp properties should exist"); return new List<CachedEvent>(); })); var events = from i in Enumerable.Range(1,3) select new { AProperty = "AValue" + i}; Assert.DoesNotThrow(() => client.AddEvents("AddEventTest", events)); Assert.True((UseMocks && done) || !UseMocks, "AddEvent mock was not called"); }