本文整理汇总了C#中Keen.Core.KeenClient类的典型用法代码示例。如果您正苦于以下问题:C# KeenClient类的具体用法?C# KeenClient怎么用?C# KeenClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KeenClient类属于Keen.Core命名空间,在下文中一共展示了KeenClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
示例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: 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);
}
示例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" }));
}
示例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();
}
示例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", ""));
}
}
示例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" });
}
}
示例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" }));
}
示例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 }));
}
示例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 }));
}
示例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 }));
}
示例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}));
}
示例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 ();
}
示例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" }}));
}
示例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);
}
}
}