本文整理汇总了C#中BsonJavaScript类的典型用法代码示例。如果您正苦于以下问题:C# BsonJavaScript类的具体用法?C# BsonJavaScript怎么用?C# BsonJavaScript使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BsonJavaScript类属于命名空间,在下文中一共展示了BsonJavaScript类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
开发者ID:kklik,项目名称:MagicMongoDBTool,代码行数:34,代码来源:frmevalJS.cs
示例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());
}
开发者ID:redforks,项目名称:mongo-csharp-driver,代码行数:7,代码来源:BsonEqualsTests.cs
示例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;
}
开发者ID:Nakro,项目名称:mongo-csharp-driver,代码行数:25,代码来源:MapReduceOperationBase.cs
示例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; });
}
开发者ID:oskysal,项目名称:mongo-csharp-driver,代码行数:7,代码来源:BsonValueTests.cs
示例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));
}
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:15,代码来源:MapReduceOperationBase.cs
示例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;
}
开发者ID:bollinim,项目名称:mongo-csharp-driver,代码行数:9,代码来源:MapReduceOperationBase.cs
示例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>();
}
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:8,代码来源:EvalOperationTests.cs
示例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);
}
开发者ID:namesecured,项目名称:MapReduce,代码行数:9,代码来源:AggregationTests.cs
示例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();
}
开发者ID:lgadi,项目名称:ZeeBi,代码行数:10,代码来源:StatsController.cs
示例10: Seed
public void Seed()
{
var db = CreateDatabase();
foreach (var seedDefinition in Description.Seeds)
{
var command = new BsonJavaScript(seedDefinition.Load());
db.Eval(command);
}
}
开发者ID:ChrisMH,项目名称:Buddy.Database,代码行数:10,代码来源:MongoDbManager.cs
示例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);
}
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:10,代码来源:EvalOperationTests.cs
示例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);
}
}
}
开发者ID:namesecured,项目名称:MSBuildMongo,代码行数:11,代码来源:RunJavascript.cs
示例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>();
}
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:12,代码来源:GroupOperationTests.cs
示例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();
}
开发者ID:EricBlack,项目名称:MagicMongoDBTool,代码行数:17,代码来源:frmMapReduce.cs
示例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();
}
开发者ID:Eddie0330,项目名称:MagicMongoDBTool,代码行数:17,代码来源:frmMapReduce.cs
示例16: Create
public void Create()
{
Destroy();
var db = CreateDatabase();
db.GetCollectionNames(); // Creation doesn't happen until a command is run against the database
foreach (var schemaDefinition in Description.Schemas)
{
var command = new BsonJavaScript(schemaDefinition.Load());
db.Eval(command);
}
}
开发者ID:ChrisMH,项目名称:Buddy.Database,代码行数:13,代码来源:MongoDbManager.cs
示例17: 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 rtn = _mongocol.MapReduce(map, reduce);
List<BsonDocument> result = new List<BsonDocument>();
result.Add(rtn.Response);
MongoDBHelper.FillDataToTreeView("MapReduce Result", trvResult, result,0);
trvResult.DatatreeView.ExpandAll();
}
开发者ID:zwq194,项目名称:MagicMongoDBTool,代码行数:18,代码来源:frmMapReduce.cs
示例18: constructor_should_initialize_subject
public void constructor_should_initialize_subject()
{
var function = new BsonJavaScript("return 1");
var subject = new EvalOperation(_adminDatabaseNamespace, function, _messageEncoderSettings);
subject.Args.Should().BeNull();
subject.DatabaseNamespace.Should().Be(_adminDatabaseNamespace);
subject.Function.Should().Be(function);
subject.MaxTime.Should().NotHaveValue();
// subject.MessageEncoderSettings.Should().Be(_messageEncoderSettings);
Assert.Equal(_messageEncoderSettings, subject.MessageEncoderSettings);
subject.NoLock.Should().NotHaveValue();
}
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:14,代码来源:EvalOperationTests.cs
示例19: cmdEval_Click
/// <summary>
/// eval Javascript
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void cmdEval_Click(object sender, EventArgs e)
{
var mongoDb = RuntimeMongoDbContext.GetCurrentDataBase();
var js = new BsonJavaScript(ctlEval.Context);
var Params = new List<BsonValue>();
if (txtParm.Text != string.Empty)
{
foreach (var parm in txtParm.Text.Split(",".ToCharArray()))
{
if (parm.StartsWith("'") & parm.EndsWith("'"))
{
Params.Add(parm.Trim("'".ToCharArray()));
}
else
{
try
{
var isNuberic = true;
for (var i = 0; i < parm.Length; i++)
{
if (!char.IsNumber(parm, i))
{
isNuberic = false;
}
}
if (isNuberic)
{
Params.Add(Convert.ToInt16(parm));
}
}
catch (Exception ex)
{
Utility.ExceptionDeal(ex, "Exception", "Parameter Exception");
}
}
}
}
try
{
var args = new EvalArgs {Args = Params.ToArray(), Code = js};
var result = mongoDb.Eval(args);
MyMessageBox.ShowMessage("Result", "Result",
result.ToJson(MongoHelper.JsonWriterSettings), true);
}
catch (Exception ex)
{
Utility.ExceptionDeal(ex, "Exception", "Result");
}
}
开发者ID:jango2015,项目名称:MongoCola,代码行数:54,代码来源:frmEvalJS.cs
示例20: cmdEval_Click
/// <summary>
/// eval Javascript
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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.Trim("'".ToCharArray()));
}
else
{
try
{
Boolean isNuberic = true;
for (int i = 0; i < parm.Length; i++)
{
if (!char.IsNumber(parm, i))
{
isNuberic = false;
}
}
if (isNuberic)
{
Params.Add(Convert.ToInt16(parm));
}
}
catch (Exception ex)
{
MyMessageBox.ShowMessage("Exception", "Parameter Exception", ex.ToString(), true);
}
}
}
}
try
{
BsonValue result = mongoDB.Eval(js, Params.ToArray());
MyMessageBox.ShowMessage("Result", "Result", result.ToJson(SystemManager.JsonWriterSettings), true);
}
catch (Exception ex)
{
MyMessageBox.ShowMessage("Exception", "Result", ex.ToString(), true);
}
}
开发者ID:kevan,项目名称:MagicMongoDBTool,代码行数:52,代码来源:frmevalJS.cs
注:本文中的BsonJavaScript类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论