本文整理汇总了C#中Keen.Core.KeenClient类的典型用法代码示例。如果您正苦于以下问题:C# KeenClient类的具体用法?C# KeenClient怎么用?C# KeenClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KeenClient类属于Keen.Core命名空间,在下文中一共展示了KeenClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: AvailableQueries_Success
public async void AvailableQueries_Success()
{
var client = new KeenClient(settingsEnv);
Mock<IQueries> queryMock = null;
if (UseMocks)
{
// A few values that should be present and are unlikely to change
IEnumerable<KeyValuePair<string,string>> testResult = new List<KeyValuePair<string, string>>()
{
new KeyValuePair<string, string>("minimum", "url" ),
new KeyValuePair<string, string>("average", "url" ),
new KeyValuePair<string, string>("maximum", "url" ),
new KeyValuePair<string, string>("count_url", "url" ),
};
queryMock = new Mock<IQueries>();
queryMock.Setup(m=>m.AvailableQueries())
.Returns(Task.FromResult(testResult));
client.Queries = queryMock.Object;
}
var response = await client.GetQueries();
Assert.True(response.Any(p => p.Key == "minimum"));
Assert.True(response.Any(p => p.Key == "average"));
Assert.True(response.Any(p => p.Key == "maximum"));
Assert.True(response.Any(p => p.Key == "count_url"));
if (null != queryMock)
queryMock.Verify(m => m.AvailableQueries());
}
开发者ID:kidchenko,项目名称:keen-sdk-net,代码行数:31,代码来源:QueryTest.cs
示例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.
}
}
开发者ID:keenlabs,项目名称:keen-sdk-net,代码行数:25,代码来源:FunnelTest.cs
示例3: Query_InvalidCollection_Throws
public async void Query_InvalidCollection_Throws()
{
var client = new KeenClient(settingsEnv);
var timeframe = QueryRelativeTimeframe.PreviousHour();
Mock<IQueries> queryMock = null;
if (UseMocks)
{
queryMock = new Mock<IQueries>();
queryMock.Setup(m => m.Metric(
It.Is<QueryType>(q => q == QueryType.Count()),
It.Is<string>(c => c == null),
It.Is<string>(p => p == ""),
It.Is<QueryRelativeTimeframe>(t => t == timeframe),
It.Is<IEnumerable<QueryFilter>>(f => f == null),
It.Is<string>(z => z == "")
))
.Throws(new ArgumentNullException());
client.Queries = queryMock.Object;
}
var count = await client.QueryAsync(QueryType.Count(), null, "", timeframe, null);
Assert.IsNotNull(count);
}
开发者ID:kidchenko,项目名称:keen-sdk-net,代码行数:25,代码来源:QueryTest.cs
示例4: 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" }));
}
开发者ID:keenlabs,项目名称:keen-sdk-net,代码行数:8,代码来源:EventCacheTest.cs
示例5: Funnel_Simple_Success
public async Task Funnel_Simple_Success()
{
var client = new KeenClient(SettingsEnv);
IEnumerable<FunnelStep> funnelsteps = new List<FunnelStep>
{
new FunnelStep
{
EventCollection = FunnelColA,
ActorProperty = "id",
},
new FunnelStep
{
EventCollection = FunnelColB,
ActorProperty = "id"
},
};
var expected = new FunnelResult
{
Steps = new []
{
new FunnelResultStep
{
EventCollection = FunnelColA,
},
new FunnelResultStep
{
EventCollection = FunnelColB,
},
},
Result = new[] { 3, 2 }
};
Mock<IQueries> queryMock = null;
if (UseMocks)
{
queryMock = new Mock<IQueries>();
queryMock.Setup(m => m.Funnel(
It.Is<IEnumerable<FunnelStep>>(f => f.Equals(funnelsteps)),
It.Is<QueryTimeframe>(t => t == null),
It.Is<string>(t => t == "")
))
.Returns(Task.FromResult(expected));
client.Queries = queryMock.Object;
}
var reply = (await client.QueryFunnelAsync(funnelsteps));
Assert.NotNull(reply);
Assert.NotNull(reply.Result);
Assert.NotNull(reply.Steps);
Assert.AreEqual(reply.Steps.Count(), 2);
if (null != queryMock)
queryMock.VerifyAll();
}
开发者ID:keenlabs,项目名称:keen-sdk-net,代码行数:58,代码来源:FunnelTest.cs
示例6: ReadKeyOnly_Success
public void ReadKeyOnly_Success()
{
var settings = new ProjectSettingsProvider(SettingsEnv.ProjectId, readKey: SettingsEnv.ReadKey);
var client = new KeenClient(settings);
if (!UseMocks)
{
// Server is required for this test
// Also, test depends on existance of collection "AddEventTest"
Assert.DoesNotThrow(() => client.Query(QueryType.Count(), "AddEventTest", ""));
}
}
开发者ID:iturpablo,项目名称:keen-sdk-net,代码行数:12,代码来源:QueryTest.cs
示例7: 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" });
}
}
开发者ID:kidchenko,项目名称:keen-sdk-net,代码行数:12,代码来源:QueryTest.cs
示例8: 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" }));
}
开发者ID:iturpablo,项目名称:keen-sdk-net,代码行数:13,代码来源:AddOnsTest.cs
示例9: 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 }));
}
开发者ID:iturpablo,项目名称:keen-sdk-net,代码行数:15,代码来源:AddOnsTest.cs
示例10: 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 }));
}
开发者ID:iturpablo,项目名称:keen-sdk-net,代码行数:15,代码来源:AddOnsTest.cs
示例11: 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 }));
}
开发者ID:iturpablo,项目名称:keen-sdk-net,代码行数:15,代码来源:AddOnsTest.cs
示例12: 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}));
}
开发者ID:iturpablo,项目名称:keen-sdk-net,代码行数:15,代码来源:AddOnsTest.cs
示例13: 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"];
// Creating Keen.IO Variables - Yes, i am setting my read key as the master key, so that you can read the bucket I have created with data
var projectSettings = new ProjectSettingsProvider (_keenIOProjectID,masterKey:_keenIOReadKey);
var keenClient = new KeenClient (projectSettings);
/*********************************************************************
* EXECUTING SIMPLE ANALYTICS QUERIES ON KEEN.IO
**********************************************************************/
// Query 1 - Average App Price grouped by Category
Dictionary<String,String> parameters = new Dictionary<String,String>();
parameters.Add ("event_collection", "PlayStore2014");
parameters.Add ("target_property", "Price");
parameters.Add ("group_by", "Category");
JObject keenResponse = keenClient.Query (KeenConstants.QueryAverage, parameters);
PrintQueryTitle ("Query 1 - Average App Price grouped by Category");
Console.WriteLine (keenResponse.ToSafeString ());
PrintSeparator ();
// Query 2 - Most Expensive app for sale of each category
keenResponse = keenClient.Query (KeenConstants.QueryMaximum, parameters);
PrintQueryTitle ("Query 2 - Most Expensive app for sale of each category");
Console.WriteLine (keenResponse.ToSafeString ());
PrintSeparator ();
// Query 3 - Most Expensive App for sale of all (without group by)
parameters.Remove ("group_by");
keenResponse = keenClient.Query (KeenConstants.QueryMaximum, parameters);
PrintQueryTitle ("Query 3 - Most Expensive App for sale of all (without group by)");
Console.WriteLine (keenResponse.ToSafeString ());
PrintSeparator ();
Console.ReadKey ();
}
开发者ID:hardikamal,项目名称:GooglePlayAppsCrawler,代码行数:48,代码来源:Analytics.cs
示例14: AddEvents_InvalidProject_Throws
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" }}));
}
开发者ID:kidchenko,项目名称:keen-sdk-net,代码行数:16,代码来源:KeenClientTest.cs
示例15: 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);
}
}
}
开发者ID:hardikamal,项目名称:GooglePlayAppsCrawler,代码行数:44,代码来源:Uploader.cs
示例16: AddEvents_PartialFailure_Throws
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));
}
开发者ID:kidchenko,项目名称:keen-sdk-net,代码行数:23,代码来源:KeenClientTest.cs
示例17: MultiAnalysis_ValidRelativeTimeFrame_Success
public async void MultiAnalysis_ValidRelativeTimeFrame_Success()
{
var client = new KeenClient(settingsEnv);
var timeframe = QueryRelativeTimeframe.PreviousNDays(2);
IEnumerable<MultiAnalysisParam> param = new List<MultiAnalysisParam>()
{
new MultiAnalysisParam("first", MultiAnalysisParam.Metric.Count()),
new MultiAnalysisParam("second", MultiAnalysisParam.Metric.Maximum("field1")),
new MultiAnalysisParam("third", MultiAnalysisParam.Metric.Minimum("field1")),
};
IDictionary<string, string> result = new Dictionary<string, string>();
result.Add("second", "fff");
result.Add("third", "aaa");
result.Add("first", "123");
Mock<IQueries> queryMock = null;
if (UseMocks)
{
queryMock = new Mock<IQueries>();
queryMock.Setup(m => m.MultiAnalysis(
It.Is<string>(c => c == testCol),
It.Is<IEnumerable<MultiAnalysisParam>>(p => p == param),
It.Is<QueryTimeframe>(t => t == timeframe),
It.Is<IEnumerable<QueryFilter>>(f => f == null),
It.Is<string>(tz => tz == "")
))
.Returns(Task.FromResult(result));
client.Queries = queryMock.Object;
}
var reply = await client.QueryMultiAnalysisAsync(testCol, param, timeframe, null, "");
if (null != queryMock)
{
Assert.AreEqual(reply.Count(), result.Count());
queryMock.VerifyAll();
}
}
开发者ID:kidchenko,项目名称:keen-sdk-net,代码行数:39,代码来源:QueryTest.cs
示例18: Funnel_ValidTimeframe_Success
public async void Funnel_ValidTimeframe_Success()
{
var client = new KeenClient(settingsEnv);
var filters = new List<QueryFilter>() { new QueryFilter("field1", QueryFilter.FilterOperator.GreaterThan(), "1") };
var funnelColA = "FunnelTestA";
var funnelColB = "FunnelTestB";
var funnelColC = "FunnelTestC";
try
{
if (!UseMocks)
{
client.DeleteCollection(funnelColA);
client.DeleteCollection(funnelColB);
client.DeleteCollection(funnelColC);
}
}
catch (Exception)
{
}
var timeframe = new QueryAbsoluteTimeframe(DateTime.Now, DateTime.Now.AddSeconds(2));
if (!UseMocks)
{
client.AddEvent(funnelColA, new { id = "1" });
client.AddEvent(funnelColA, new { id = "2" });
client.AddEvent(funnelColA, new { id = "3" });
client.AddEvent(funnelColB, new { id = "1" });
client.AddEvent(funnelColB, new { id = "2" });
client.AddEvent(funnelColC, new { id = "1" });
}
IEnumerable<FunnelStep> funnelsteps = new List<FunnelStep>()
{
new FunnelStep(){ EventCollection = funnelColA, ActorProperty = "id" },
new FunnelStep(){ EventCollection = funnelColB, ActorProperty = "id" },
new FunnelStep(){ EventCollection = funnelColC, ActorProperty = "id" },
};
IEnumerable<int> result = new List<int>() { 3, 2, 1 };
Mock<IQueries> queryMock = null;
if (UseMocks)
{
queryMock = new Mock<IQueries>();
queryMock.Setup(m => m.Funnel(
It.IsAny<string>(),
It.Is<IEnumerable<FunnelStep>>(f => f == funnelsteps),
It.Is<QueryTimeframe>(t => t == null),
It.Is<string>(t => t == "")
))
.Returns(Task.FromResult(result));
client.Queries = queryMock.Object;
}
var reply = (await client.QueryFunnelAsync(testCol, funnelsteps, null)).ToList();
if (null != queryMock)
queryMock.VerifyAll();
}
开发者ID:kidchenko,项目名称:keen-sdk-net,代码行数:64,代码来源:QueryTest.cs
示例19: ExtractResource_ValidFilter_Success
public async void ExtractResource_ValidFilter_Success()
{
var client = new KeenClient(settingsEnv);
var filters = new List<QueryFilter>() { new QueryFilter("field1", QueryFilter.FilterOperator.GreaterThan(), "1") };
dynamic eo = new ExpandoObject();
eo.field1 = "8888";
IEnumerable<dynamic> result = new List<dynamic>() { eo, eo };
Mock<IQueries> queryMock = null;
if (UseMocks)
{
queryMock = new Mock<IQueries>();
queryMock.Setup(m => m.Extract(
It.Is<string>(c => c == testCol),
It.Is<QueryAbsoluteTimeframe>(t => t == null),
It.Is<IEnumerable<QueryFilter>>(f => f == filters),
It.Is<int>(l => l == 0),
It.Is<string>(t => t == "")
))
.Returns(Task.FromResult(result));
client.Queries = queryMock.Object;
}
var reply = (await client.QueryExtractResourceAsync(testCol, null, filters)).ToList();
if (null != queryMock)
queryMock.VerifyAll();
}
开发者ID:kidchenko,项目名称:keen-sdk-net,代码行数:29,代码来源:QueryTest.cs
示例20: ExtractResource_ValidRelative_Success
public async void ExtractResource_ValidRelative_Success()
{
var client = new KeenClient(settingsEnv);
var timeframe = QueryRelativeTimeframe.ThisMinute();
dynamic eo = new ExpandoObject();
eo.field1 = "8888";
IEnumerable<dynamic> result = new List<dynamic>() { eo, eo };
Mock<IQueries> queryMock = null;
if (UseMocks)
{
queryMock = new Mock<IQueries>();
queryMock.Setup(m => m.Extract(
It.Is<string>(c => c == testCol),
It.Is<QueryRelativeTimeframe>(t => t == timeframe),
It.Is<IEnumerable<QueryFilter>>(f => f == null),
It.Is<int>(l => l == 0),
It.Is<string>(t => t == "")
))
.Returns(Task.FromResult(result));
client.Queries = queryMock.Object;
}
var reply = (await client.QueryExtractResourceAsync(testCol, timeframe)).ToList();
if (null != queryMock)
queryMock.VerifyAll();
}
开发者ID:kidchenko,项目名称:keen-sdk-net,代码行数:29,代码来源:QueryTest.cs
注:本文中的Keen.Core.KeenClient类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论