本文整理汇总了C#中Keen.Core.KeenClient.AddEvent方法的典型用法代码示例。如果您正苦于以下问题:C# KeenClient.AddEvent方法的具体用法?C# KeenClient.AddEvent怎么用?C# KeenClient.AddEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Keen.Core.KeenClient
的用法示例。
在下文中一共展示了KeenClient.AddEvent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Setup
public override void Setup()
{
base.Setup();
// If not using mocks, set up conditions on the server
if (!UseMocks)
{
var client = new KeenClient(settingsEnv);
//client.DeleteCollection(testCol);
client.AddEvent(testCol, new { field1 = "99999999" });
}
}
示例2: Setup
public override void Setup()
{
base.Setup();
// If not using mocks, set up conditions on the server
if (!UseMocks)
{
var client = new KeenClient(SettingsEnv);
client.DeleteCollection(FunnelColA);
client.DeleteCollection(FunnelColB);
client.DeleteCollection(FunnelColC);
client.AddEvent(FunnelColA, new { id = 1, name = new { first = "sam", last = "w" } });
client.AddEvent(FunnelColA, new { id = 2, name = new { first = "dean", last = "w" } });
client.AddEvent(FunnelColA, new { id = 3, name = new { first = "crowly", last = "" } });
client.AddEvent(FunnelColB, new { id = 1, name = new { first = "sam", last = "w" } });
client.AddEvent(FunnelColB, new { id = 2, name = new { first = "dean", last = "w" } });
client.AddEvent(FunnelColC, new { id = 1, name = new { first = "sam", last = "w" } });
Thread.Sleep(8000); // Give it a moment to show up. Queries will fail if run too soon.
}
}
示例3: No_AddOn_Success
public void No_AddOn_Success()
{
var client = new KeenClient(SettingsEnv);
if (UseMocks)
client.EventCollection = new EventCollectionMock(SettingsEnv,
addEvent: (c, e, p) =>
{
if (e["keen"].ToString().Contains("keen:ip_to_geo"))
throw new Exception("Unexpected values");
});
Assert.DoesNotThrow(() => client.AddEvent("AddOnTest", new { an_ip = "70.187.8.97" }));
}
示例4: IpToGeo_Send_Success
public void IpToGeo_Send_Success()
{
var client = new KeenClient(SettingsEnv);
if (UseMocks)
client.EventCollection = new EventCollectionMock(SettingsEnv,
addEvent: (c, e, p) =>
{
if (!e["keen"].ToString().Contains("keen:ip_to_geo"))
throw new Exception("Unexpected values");
});
var a = AddOn.IpToGeo("an_ip", "geocode");
Assert.DoesNotThrow(() => client.AddEvent("AddOnTest", new {an_ip = "70.187.8.97"}, new List<AddOn> {a}));
}
示例5: UserAgentParser_Send_Success
public void UserAgentParser_Send_Success()
{
var client = new KeenClient(SettingsEnv);
if (UseMocks)
client.EventCollection = new EventCollectionMock(SettingsEnv,
addEvent: (c, e, p) =>
{
if (!e["keen"].ToString().Contains("keen:ua_parser"))
throw new Exception("Unexpected values");
});
var a = AddOn.UserAgentParser("user_agent_string", "user_agent_parsed");
Assert.DoesNotThrow(() => client.AddEvent("AddOnTest", new { user_agent_string = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36" }, new List<AddOn> { a }));
}
示例6: IpToGeo_MissingInput_Throws
public void IpToGeo_MissingInput_Throws()
{
var client = new KeenClient(SettingsEnv);
if (UseMocks)
client.EventCollection = new EventCollectionMock(SettingsEnv,
addEvent: (c, e, p) =>
{
if (!e["keen"].ToString().Contains("\"ip\": \"an_ip\""))
throw new KeenException("Unexpected values");
});
var a = AddOn.IpToGeo("wrong_field", "geocode");
Assert.Throws<KeenException>(() => client.AddEvent("AddOnTest", new { an_ip = "70.187.8.97" }, new List<AddOn> { a }));
}
示例7: Main
static void Main (string[] args)
{
// Loading Keen.IO Keys and Misc. from Config File
_keenIOProjectID = ConfigurationManager.AppSettings["keenIOProjectID"];
_keenIOMasterKey = ConfigurationManager.AppSettings["keenIOMasterKey"];
_keenIOWriteKey = ConfigurationManager.AppSettings["keenIOWriteKey"];
_keenIOReadKey = ConfigurationManager.AppSettings["keenIOReadKey"];
_bucketName = ConfigurationManager.AppSettings["keenIOBucketName"];
// Configuring MongoDB Wrapper for connection and queries
MongoDBWrapper mongoDB = new MongoDBWrapper ();
string fullServerAddress = String.Join (":", Consts.MONGO_SERVER, Consts.MONGO_PORT);
mongoDB.ConfigureDatabase (Consts.MONGO_USER, Consts.MONGO_PASS, Consts.MONGO_AUTH_DB, fullServerAddress, Consts.MONGO_TIMEOUT, Consts.MONGO_DATABASE, Consts.MONGO_COLLECTION);
// Creating Keen.IO Variables
var projectSettings = new ProjectSettingsProvider (_keenIOProjectID, _keenIOMasterKey, _keenIOWriteKey, _keenIOReadKey);
var keenClient = new KeenClient (projectSettings);
// From This point on, you can change your code to reflect your own "Reading" logic
// What I've done is simply read the records from the MongoDB database and Upload them to Keen.IO
foreach (var currentApp in mongoDB.FindMatch<AppModel> (Query.NE ("Uploaded", true)))
{
try
{
// Adding Event to Keen.IO
keenClient.AddEvent ("PlayStore2014", currentApp);
// Incrementing Counter
_appsCounter++;
// Console feedback Every 100 Processed Apps
if (_appsCounter % 100 == 0)
{
Console.WriteLine ("Uploaded : " + _appsCounter);
}
mongoDB.SetUpdated (currentApp.Url);
}
catch (Exception ex)
{
Console.WriteLine ("\n\t" + ex.Message);
}
}
}
示例8: Async_Caching_SendEvents_Success
public async Task Async_Caching_SendEvents_Success()
{
var client = new KeenClient(settingsEnv, new EventCacheMemory());
if (UseMocks)
client.Event = new EventMock(settingsEnv,
AddEvents: new Func<JObject, IProjectSettings, IEnumerable<CachedEvent>>((e, p) =>
{
Assert.AreEqual(p, settingsEnv, "Unexpected settings object");
Assert.AreEqual(e.Property("CachedEventTest").Value.AsEnumerable().Count(), 3, "Expected exactly 3 collection members");
return new List<CachedEvent>();
}));
client.AddEvent("CachedEventTest", new { AProperty = "AValue" });
client.AddEvent("CachedEventTest", new { AProperty = "AValue" });
client.AddEvent("CachedEventTest", new { AProperty = "AValue" });
await client.SendCachedEventsAsync();
Assert.Null(await client.EventCache.TryTake(), "Cache should be empty");
}
示例9: Caching_SendInvalidEvents_Throws
public void Caching_SendInvalidEvents_Throws()
{
var client = new KeenClient(settingsEnv, new EventCacheMemory());
if (UseMocks)
client.Event = new EventMock(settingsEnv,
AddEvents: new Func<JObject, IProjectSettings, IEnumerable<CachedEvent>>((e, p) =>
{
if (p == settingsEnv)
throw new KeenBulkException("Mock exception",
new List<CachedEvent>(){new CachedEvent("CachedEventTest", e, new Exception())});
else
throw new Exception("Unexpected value");
}));
var anEvent = new JObject();
anEvent.Add("AProperty", "AValue");
client.AddEvent("CachedEventTest", anEvent);
anEvent.Add("keen", JObject.FromObject(new {invalidPropName = "value"} ));
client.AddEvent("CachedEventTest", anEvent);
Assert.DoesNotThrow(() =>
{
try
{
client.SendCachedEvents();
}
catch (KeenBulkException ex)
{
if (ex.FailedEvents.Count() != 1)
throw new Exception("Expected 1 failed event.");
}
});
}
示例10: Caching_SendManyEvents_Success
public async void Caching_SendManyEvents_Success()
{
var client = new KeenClient(settingsEnv, new EventCacheMemory());
var total = 0;
if (UseMocks)
client.Event = new EventMock(settingsEnv,
AddEvents: new Func<JObject, IProjectSettings, IEnumerable<CachedEvent>>((e, p) =>
{
if ((p == settingsEnv)
&& (null != e.Property("CachedEventTest"))
&& ((e.Property("CachedEventTest").Value.Children().Count() == KeenConstants.BulkBatchSize)))
{
total += e.Property("CachedEventTest").Value.Children().Count();
return new List<CachedEvent>();
}
else
throw new Exception("Unexpected value");
}));
for (int i = 0; i < KeenConstants.BulkBatchSize; i++)
client.AddEvent("CachedEventTest", new { AProperty = "AValue" });
Assert.DoesNotThrow(() => client.SendCachedEvents());
Assert.Null(await client.EventCache.TryTake(), "Cache is empty");
Assert.True( !UseMocks || ( total == KeenConstants.BulkBatchSize));
}
示例11: Caching_SendEvents_Success
public async void Caching_SendEvents_Success()
{
var client = new KeenClient(settingsEnv, new EventCacheMemory());
if (UseMocks)
client.Event = new EventMock(settingsEnv,
AddEvents: new Func<JObject, IProjectSettings, IEnumerable<CachedEvent>>((e, p) =>
{
if ((p == settingsEnv)
&& (null!=e.Property("CachedEventTest"))
&& (e.Property("CachedEventTest").Value.Children().Count()==3))
return new List<CachedEvent>();
else
throw new Exception("Unexpected value");
}));
client.AddEvent("CachedEventTest", new { AProperty = "AValue" });
client.AddEvent("CachedEventTest", new { AProperty = "AValue" });
client.AddEvent("CachedEventTest", new { AProperty = "AValue" });
Assert.DoesNotThrow(() => client.SendCachedEvents());
Assert.Null(await client.EventCache.TryTake(), "Cache is empty");
}
示例12: Caching_AddEvents_Success
public void Caching_AddEvents_Success()
{
var client = new KeenClient(settingsEnv, new EventCacheMemory());
Assert.DoesNotThrow(() => client.AddEvent("CachedEventTest", new { AProperty = "AValue" }));
Assert.DoesNotThrow(() => client.AddEvent("CachedEventTest", new { AProperty = "AValue" }));
Assert.DoesNotThrow(() => client.AddEvent("CachedEventTest", new { AProperty = "AValue" }));
}
示例13: AddGlobalProperty_DelegateValueProviderNullReturn_Throws
public void AddGlobalProperty_DelegateValueProviderNullReturn_Throws()
{
var client = new KeenClient(settingsEnv);
if (UseMocks)
client.EventCollection = new EventCollectionMock(settingsEnv,
AddEvent: new Action<string, JObject, IProjectSettings>((c, e, p) =>
{
if ((p == settingsEnv) && (c == "AddEventTest")
&& (e["AProperty"].Value<string>() == "AValue")
&& (e["AGlobal"].Value<string>() == "value"))
return;
else
throw new Exception("Unexpected value");
}));
var i = 0;
// return valid for the first two tests, then null
client.AddGlobalProperty("AGlobal", new DynamicPropertyValue(() => i++ > 1 ? null : "value"));
// This is the second test (AddGlobalProperty runs the first)
Assert.DoesNotThrow(() => client.AddEvent("AddEventTest", new { AProperty = "AValue" }));
// Third test should fail.
Assert.Throws<KeenException>(() => { client.AddEvent("AddEventTest", new { AProperty = "AValue" }); });
}
示例14: CachingPCL_AddEvents_Success
public void CachingPCL_AddEvents_Success(IEventCache cache)
{
var client = new KeenClient(SettingsEnv, cache);
Assert.DoesNotThrow(() => client.AddEvent("CachedEventTest", new { AProperty = "AValue" }));
Assert.DoesNotThrow(() => client.AddEvent("CachedEventTest", new { AProperty = "AValue" }));
Assert.DoesNotThrow(() => client.AddEvent("CachedEventTest", new { AProperty = "AValue" }));
}
示例15: UrlParser_Send_Success
public void UrlParser_Send_Success()
{
var client = new KeenClient(SettingsEnv);
if (UseMocks)
client.EventCollection = new EventCollectionMock(SettingsEnv,
addEvent: (c, e, p) =>
{
if (!e["keen"].ToString().Contains("keen:url_parser"))
throw new Exception("Unexpected values");
});
var a = AddOn.UrlParser("url", "url_parsed");
Assert.DoesNotThrow(() => client.AddEvent("AddOnTest", new { url = "https://keen.io/docs/data-collection/data-enrichment/#anchor" }, new List<AddOn> { a }));
}