本文整理汇总了C#中BsonJavaScript类的典型用法代码示例。如果您正苦于以下问题:C# BsonJavaScript类的具体用法?C# BsonJavaScript怎么用?C# BsonJavaScript使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BsonJavaScript类属于命名空间,在下文中一共展示了BsonJavaScript类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: cmdEval_Click
private void cmdEval_Click(object sender, EventArgs e)
{
MongoDatabase mongoDB = SystemManager.GetCurrentDataBase();
BsonJavaScript js = new BsonJavaScript(txtevalJs.Text);
List<Object> Params = new List<Object>();
if (txtParm.Text != String.Empty) {
foreach (String parm in txtParm.Text.Split(",".ToCharArray())) {
if (parm.StartsWith("'") & parm.EndsWith("'"))
{
Params.Add(parm);
}
else {
//TODO:检查数字型
try
{
Params.Add(Convert.ToInt16(parm));
}
catch (Exception ex)
{
MyMessageBox.ShowMessage("异常", "参数异常", ex.ToString(), true);
}
}
}
}
try
{
BsonValue result = mongoDB.Eval(js, Params.ToArray());
MyMessageBox.ShowMessage("结果", "执行结果", MongoDBHelper.GetBsonElementText("Result",result,0), true);
}
catch (Exception ex)
{
MyMessageBox.ShowMessage("异常","执行异常",ex.ToString(),true);
}
}
示例2: TestBsonJavaScriptEquals
public void TestBsonJavaScriptEquals() {
BsonJavaScript lhs = new BsonJavaScript("n = 1");
BsonJavaScript rhs = new BsonJavaScript("n = 1");
Assert.AreNotSame(lhs, rhs);
Assert.AreEqual(lhs, rhs);
Assert.AreEqual(lhs.GetHashCode(), rhs.GetHashCode());
}
示例3: MapReduceOperationBase
protected MapReduceOperationBase(
string collectionName,
string databaseName,
BsonJavaScript finalizeFunction,
bool? javaScriptMode,
long? limit,
BsonJavaScript mapFunction,
BsonDocument query,
BsonJavaScript reduceFunction,
BsonDocument scope,
BsonDocument sort,
bool? verbose)
{
_collectionName = collectionName;
_databaseName = databaseName;
_finalizeFunction = finalizeFunction;
_javaScriptMode = javaScriptMode;
_limit = limit;
_mapFunction = mapFunction;
_query = query;
_reduceFunction = reduceFunction;
_scope = scope;
_sort = sort;
_verbose = verbose;
}
示例4: TestAsBsonJavaScript
public void TestAsBsonJavaScript() {
BsonValue v = new BsonJavaScript("code");
BsonValue s = "";
var js = v.AsBsonJavaScript;
Assert.AreEqual("code", js.Code);
Assert.Throws<InvalidCastException>(() => { var x = s.AsBsonJavaScript; });
}
示例5: MapReduceOperationBase
// constructors
/// <summary>
/// Initializes a new instance of the <see cref="MapReduceOperationBase"/> class.
/// </summary>
/// <param name="collectionNamespace">The collection namespace.</param>
/// <param name="mapFunction">The map function.</param>
/// <param name="reduceFunction">The reduce function.</param>
/// <param name="messageEncoderSettings">The message encoder settings.</param>
protected MapReduceOperationBase(CollectionNamespace collectionNamespace, BsonJavaScript mapFunction, BsonJavaScript reduceFunction, MessageEncoderSettings messageEncoderSettings)
{
_collectionNamespace = Ensure.IsNotNull(collectionNamespace, nameof(collectionNamespace));
_mapFunction = Ensure.IsNotNull(mapFunction, nameof(mapFunction));
_reduceFunction = Ensure.IsNotNull(reduceFunction, nameof(reduceFunction));
_messageEncoderSettings = Ensure.IsNotNull(messageEncoderSettings, nameof(messageEncoderSettings));
}
示例6: MapReduceOperationBase
// constructors
protected MapReduceOperationBase(CollectionNamespace collectionNamespace, BsonJavaScript mapFunction, BsonJavaScript reduceFunction, BsonDocument query, MessageEncoderSettings messageEncoderSettings)
{
_collectionNamespace = Ensure.IsNotNull(collectionNamespace, "collectionNamespace");
_mapFunction = Ensure.IsNotNull(mapFunction, "mapFunction");
_reduceFunction = Ensure.IsNotNull(reduceFunction, "reduceFunction");
_query = query;
_messageEncoderSettings = messageEncoderSettings;
}
示例7: constructor_should_throw_when_databaseNamespace_is_null
public void constructor_should_throw_when_databaseNamespace_is_null()
{
var function = new BsonJavaScript("return 1");
Action action = () => new EvalOperation(null, function, _messageEncoderSettings);
action.ShouldThrow<ArgumentNullException>();
}
示例8: Aggregate_with_map_reduce
public void Aggregate_with_map_reduce()
{
var dataBase = new MongoClient("mongodb://localhost").GetServer().GetDatabase("MapReduce");
var sessions = dataBase.GetCollection<Session>("Sessions");
BsonJavaScript map = new BsonJavaScript(Scipts.map);
BsonJavaScript reduce = new BsonJavaScript(Scipts.reduce);
var result = sessions.MapReduce(map, reduce);
}
示例9: GetPageViewsByUserAgent
private ICollection<KeyValuePair<string, int>> GetPageViewsByUserAgent(IMongoQuery query)
{
var reduce = new BsonJavaScript("function(o, agg) { agg.count++; }");
var results = DB.PageViews.Group(query, "UserAgent", new { count = 0 }.ToBsonDocument(), reduce, null).ToList();
return results
.ToKeyValuePairs(x => x["UserAgent"].AsString, x => x["count"].ToInt32())
.OrderByDescending(kvp => kvp.Value)
.ToList();
}
示例10: Seed
public void Seed()
{
var db = CreateDatabase();
foreach (var seedDefinition in Description.Seeds)
{
var command = new BsonJavaScript(seedDefinition.Load());
db.Eval(command);
}
}
示例11: Args_should_work
public void Args_should_work()
{
var function = new BsonJavaScript("return 1");
var subject = new EvalOperation(_adminDatabaseNamespace, function, _messageEncoderSettings);
var args = new BsonValue[] { 1, 2, 3 };
subject.Args = args;
subject.Args.Should().Equal(args);
}
示例12: Eval
public static void Eval(MongoDatabase database, string fileName)
{
using (var stream = new FileStream(fileName, FileMode.Open))
{
using (var reader = new StreamReader(stream))
{
var javaScript = new BsonJavaScript(reader.ReadToEnd());
database.Eval(javaScript);
}
}
}
示例13: constructor_with_key_should_throw_when_key_is_null
public void constructor_with_key_should_throw_when_key_is_null()
{
var collectionNamespace = new CollectionNamespace("databaseName", "collectionName");
var initial = new BsonDocument("x", 1);
var reduceFunction = new BsonJavaScript("reduceFunction");
var filter = new BsonDocument("y", 1);
var messageEncoderSettings = new MessageEncoderSettings();
Action action = () => new GroupOperation<BsonDocument>(collectionNamespace, (BsonDocument)null, initial, reduceFunction, filter, messageEncoderSettings);
action.ShouldThrow<ArgumentNullException>();
}
示例14: cmdRun_Click
/// <summary>
/// 运行
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void cmdRun_Click(object sender, EventArgs e)
{
var map = new BsonJavaScript(ctlMapFunction.Context);
var reduce = new BsonJavaScript(ctlReduceFunction.Context);
//TODO:这里可能会超时,失去响应
//需要设置SocketTimeOut
MapReduceResult mMapReduceResult = SystemManager.GetCurrentCollection().MapReduce(map, reduce);
MongoDbHelper.FillDataToTreeView("MapReduce Result", trvResult, mMapReduceResult.Response);
trvResult.DatatreeView.BeginUpdate();
trvResult.DatatreeView.ExpandAll();
trvResult.DatatreeView.EndUpdate();
}
示例15: cmdRun_Click
/// <summary>
/// 运行
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void cmdRun_Click(object sender, EventArgs e)
{
BsonJavaScript map = new BsonJavaScript(txtMapJs.Text);
BsonJavaScript reduce = new BsonJavaScript(txtReduceJs.Text);
//TODO:这里可能会超时,失去响应
//需要设置SocketTimeOut
MapReduceResult mMapReduceResult = _mongocol.MapReduce(map, reduce);
MongoDBHelper.FillDataToTreeView("MapReduce Result", trvResult, mMapReduceResult.Response);
trvResult.DatatreeView.BeginUpdate();
trvResult.DatatreeView.ExpandAll();
trvResult.DatatreeView.EndUpdate();
}