本文整理汇总了C#中BsonElement类的典型用法代码示例。如果您正苦于以下问题:C# BsonElement类的具体用法?C# BsonElement怎么用?C# BsonElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BsonElement类属于命名空间,在下文中一共展示了BsonElement类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ResultItemViewModel
public ResultItemViewModel(BsonElement element)
{
LazyLoading = true;
Element = element;
Type = element.Value.BsonType.ToString();
if (element.Value.IsBsonArray)
{
Value = _toolTip = string.Format("{0} ({1} items)", element.Value.BsonType.ToString(), element.Value.AsBsonArray.Count);
}
else if (element.Value.IsBsonDocument)
Value = _toolTip = string.Format("{0} ({1} fields)", element.Value.BsonType.ToString(), element.Value.AsBsonDocument.ElementCount);
else if (element.Value.IsValidDateTime)
{
Value = _toolTip = element.Value.ToLocalTime().ToString("yyyy-MM-ddTHH:mm:ss.FFFzzz");
}
else
{
Value = _toolTip = element.Value.ToJson(jsonWriterSettings).Replace("\n", " ").Replace("\r", " ").Replace("\\n", " ").Replace("\\r", " ").Trim(' ', '\"');
if (Value.Length > 100)
Value = Value.Substring(0, 100) + "...";
if (_toolTip.Length > 1000)
_toolTip = _toolTip.Substring(0, 1000) + "...";
}
CopyToClipboard = new RelayCommand(() =>
{
string res = "";
if (Element.Value.IsBsonDocument)
{
res = Element.Value.ToJson(jsonWriterSettings);
}
else
{
BsonDocument document = new BsonDocument();
document.Add(Element);
res = document.ToJson(jsonWriterSettings);
}
Clipboard.SetText(res);
});
CopyName = new RelayCommand(() =>
{
Clipboard.SetText(Element.Name);
});
CopyValue = new RelayCommand(() =>
{
string res = Element.Value.ToJson(jsonWriterSettings);
Clipboard.SetText(res);
});
}
开发者ID:stefanocastriotta,项目名称:MDbGui.Net,代码行数:49,代码来源:ResultItemViewModel.cs
示例2: Group
/// <summary>
/// Generates a $group pipeline command based upon the specified group-by and grouping-aggregation specifications
/// </summary>
/// <param name="GroupBy">The group-by specification for grouping distinction</param>
/// <param name="Aggregations">An enumerable of grouping-aggregation expressions</param>
public static BsonDocument Group(BsonElement GroupBy, IEnumerable<BsonElement> Aggregations) {
var value = new BsonDocument(GroupBy);
if (Aggregations != null && Aggregations.Any()) {
value.Add(Aggregations);
}
return new BsonDocument() { { "$group", value } };
}
开发者ID:jango2015,项目名称:Mongol,代码行数:12,代码来源:Aggregation.cs
示例3: TestBsonElementEquals
public void TestBsonElementEquals() {
BsonElement lhs = new BsonElement("Hello", "World");
BsonElement rhs = new BsonElement("Hello", "World");
Assert.AreNotSame(lhs, rhs);
Assert.AreEqual(lhs, rhs);
Assert.AreEqual(lhs.GetHashCode(), rhs.GetHashCode());
}
开发者ID:redforks,项目名称:mongo-csharp-driver,代码行数:7,代码来源:BsonEqualsTests.cs
示例4: TestStringElement
public void TestStringElement()
{
BsonElement element = new BsonElement("abc", "def");
string value = element.Value.AsString;
Assert.AreEqual("abc", element.Name);
Assert.AreEqual("def", value);
}
开发者ID:niemyjski,项目名称:mongo-csharp-driver,代码行数:7,代码来源:BsonElementTests.cs
示例5: _validateProperty
private void _validateProperty(Property property, BsonElement documentProperty)
{
var value = documentProperty.Value;
if (property.Options != null)
{
_assertRequired(property, value);
_assertUnique(property, value);
_assertPattern(property, value);
}
_assertType(property.Name, property.Type.Name, value.BsonType.ToString());
}
开发者ID:r0flbear,项目名称:MongoInterface,代码行数:15,代码来源:DocumentValidator.cs
示例6: ToGroupSeriesDocument
public static BsonDocument ToGroupSeriesDocument()
{
var result = new BsonDocument();
var finalElements = new List<BsonElement>();
//first slicer will always be first element in ID representing x axis
finalElements.Add(new BsonElement("_id", new BsonString("$key.s0")));
//push first
var pushElements = new List<BsonElement>();
//second slicer will always be second element in Key
pushElements.Add(new BsonElement("s1", new BsonString("$key.s1")));
//value will always be first element in value
pushElements.Add(new BsonElement("f0", new BsonString("$value.f0")));
var pushElement = new BsonElement("$push", new BsonDocument(pushElements));
var pushField = new BsonElement("f0", new BsonDocument(pushElement));
finalElements.Add(pushField);
result.Add(new BsonElement("$group", new BsonDocument(finalElements)));
return result;
}
开发者ID:cmcginn,项目名称:Akron,代码行数:18,代码来源:QueryBuilderExtensions.cs
示例7: AddElement
/// <summary>
/// Add Element
/// </summary>
/// <param name="BaseDoc"></param>
/// <param name="AddElement"></param>
public static String AddElement(String ElementPath, BsonElement AddElement)
{
BsonDocument BaseDoc = SystemManager.GetCurrentDocument();
BsonValue t = GetLastParentDocument(BaseDoc, ElementPath, true);
if (t.IsBsonDocument)
{
try
{
t.AsBsonDocument.InsertAt(t.AsBsonDocument.ElementCount, AddElement);
}
catch (InvalidOperationException ex)
{
return ex.Message;
}
}
SystemManager.GetCurrentCollection().Save(BaseDoc);
return String.Empty;
}
开发者ID:huohe2009,项目名称:MagicMongoDBTool,代码行数:23,代码来源:MongoDBHelper_Element.cs
示例8: GetBsonDoc
/// <summary>
/// 获得BsonDocument
/// </summary>
/// <returns></returns>
public BsonElement GetBsonDoc()
{
BsonDocument ResourceContent = null;
switch (Type)
{
case ResourceType.DataBase:
ResourceContent = new BsonDocument("db", DataBaseName);
ResourceContent.Add("collection", CollectionName);
break;
case ResourceType.Cluster:
ResourceContent = new BsonDocument("cluster", BsonBoolean.True);
break;
case ResourceType.Any:
ResourceContent = new BsonDocument("anyResource",BsonBoolean.True);
break;
}
BsonElement Resource = new BsonElement("resource", ResourceContent);
return Resource;
}
开发者ID:magicdict,项目名称:MongoCola,代码行数:23,代码来源:MongoResource.cs
示例9: Create
// Insert documents into Mongo
public List<BsonDocument> Create(string collectionName, List<Dictionary<string, BsonValue>> rows)
{
List<BsonDocument> documents = new List<BsonDocument>();
// call to MongoDB which create collection
var collection = database.GetCollection<BsonDocument>(collectionName);
foreach (Dictionary<string, BsonValue> row in rows) {
BsonDocument document = new BsonDocument();
// create a BSON element for each item in the document
foreach (string key in row.Keys) {
BsonElement element = new BsonElement(key, row[key]);
document.Add(element);
}
// add the document to the result list
documents.Add(document);
// insert the document into the Mongo collection
//collection.Insert(document);
}
return documents;
}
开发者ID:bobstoned,项目名称:MongoExplorer,代码行数:20,代码来源:CollectionActions.cs
示例10: cmdAddRole_Click
/// <summary>
/// 增加角色
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void cmdAddRole_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(cmbDB.Text))
{
MyMessageBox.ShowMessage("Error", "Please Select A Database");
return;
}
frmUserRole mUserRole = new frmUserRole(new BsonArray());
mUserRole.ShowDialog();
BsonElement otherRole = new BsonElement(cmbDB.Text, mUserRole.Result);
if (OtherDBRolesDict.ContainsKey(cmbDB.Text))
{
OtherDBRolesDict[cmbDB.Text] = otherRole;
}
else
{
OtherDBRolesDict.Add(cmbDB.Text, otherRole);
}
RefreshOtherDBRoles();
}
开发者ID:huchao007,项目名称:MagicMongoDBTool,代码行数:25,代码来源:frmUser.cs
示例11: AddElement
/// <summary>
/// Add Element
/// </summary>
/// <param name="elementPath"></param>
/// <param name="addElement"></param>
/// <param name="currentCollection"></param>
public static string AddElement(string elementPath, BsonElement addElement, BsonDocument currentDocument,
MongoCollection currentCollection)
{
var baseDoc = currentDocument;
var t = GetLastParentDocument(baseDoc, elementPath, true);
if (t.IsBsonDocument)
{
try
{
t.AsBsonDocument.InsertAt(t.AsBsonDocument.ElementCount, addElement);
}
catch (InvalidOperationException ex)
{
return ex.Message;
}
}
if (!currentCollection.IsCapped())
{
currentCollection.Save(baseDoc);
}
return string.Empty;
}
开发者ID:lizhi5753186,项目名称:MongoCola,代码行数:28,代码来源:ElementHelper.cs
示例12: ToProjectionDocument
public static BsonDocument ToProjectionDocument(this GroupDefinition source)
{
var keyItems = new List<BsonElement>();
var valueItems = new List<BsonElement>();
var ignoreId = new BsonElement("_id", new BsonInt32(0));
for (var i = 0; i < source.Dimensions.Count; i++)
{
var el = new BsonElement(String.Format("s{0}", i), new BsonString(String.Format("$_id.s{0}", i)));
keyItems.Add(el);
}
for (var i = 0; i < source.Measures.Count; i++)
{
var el = new BsonElement(String.Format("f{0}", i), new BsonString(String.Format("$f{0}", i)));
valueItems.Add(el);
}
var keyValuesDoc = new BsonDocument();
keyValuesDoc.AddRange(keyItems);
var keyValuesElement = new BsonElement("key", keyValuesDoc);
var valueValuesDoc = new BsonDocument();
valueValuesDoc.AddRange(valueItems);
var valueValuesElement = new BsonElement("value", valueValuesDoc);
var ignoreIdDoc = new BsonDocument();
ignoreIdDoc.Add();
var projectDoc = new BsonDocument();
projectDoc.Add(new BsonElement("_id", new BsonInt32(0)));
projectDoc.Add(keyValuesElement);
projectDoc.Add(valueValuesElement);
var projectElement = new BsonElement("$project", projectDoc);
var result = new BsonDocument {projectElement};
return result;
}
开发者ID:cmcginn,项目名称:Akron,代码行数:38,代码来源:QueryBuilderExtensions.cs
示例13: ToMatchDocument
public static BsonDocument ToMatchDocument(this MatchDefinition source)
{
var result = new BsonDocument();
var matchFilterElements = new List<BsonElement>();
source.Filters.Where(x=>x.AvailableFilterValues.Any(y=>y.Active)).ToList().ForEach(f =>
{
var colDoc = new BsonDocument();
var selectedValues = new BsonArray();
var selectedFilterValues = f.AvailableFilterValues.Where(x=>x.Active).Select(x => x.Value).Select(x => new BsonString(x)).ToList();
selectedValues.AddRange(selectedFilterValues);
//var itemE
var itemElm = new BsonElement("$in", selectedValues);
colDoc.Add(itemElm);
var colElm = new BsonElement(f.Column.ColumnName, colDoc);
matchFilterElements.Add(colElm);
});
var elementsDoc = new BsonDocument();
elementsDoc.AddRange(matchFilterElements);
var matchElement = new BsonElement("$match", elementsDoc);
result.Add(matchElement);
return result;
}
开发者ID:cmcginn,项目名称:Akron,代码行数:23,代码来源:QueryBuilderExtensions.cs
示例14: ModifyElement
/// <summary>
/// Modify Element
/// </summary>
/// <param name="ElementPath"></param>
/// <param name="NewValue"></param>
/// <param name="ValueIndex"></param>
/// <param name="El"></param>
public static void ModifyElement(String ElementPath, BsonValue NewValue, BsonElement El)
{
BsonDocument BaseDoc = SystemManager.GetCurrentDocument();
BsonValue t = GetLastParentDocument(BaseDoc, ElementPath);
if (t.IsBsonDocument)
{
t.AsBsonDocument.GetElement(El.Name).Value = NewValue;
}
SystemManager.GetCurrentCollection().Save(BaseDoc);
}
开发者ID:huohe2009,项目名称:MagicMongoDBTool,代码行数:17,代码来源:MongoDBHelper_Element.cs
示例15: DropElement
/// <summary>
/// Drop Element
/// </summary>
/// <param name="BaseDoc"></param>
/// <param name="ElementPath"></param>
public static void DropElement(String ElementPath, BsonElement El)
{
BsonDocument BaseDoc = SystemManager.GetCurrentDocument();
BsonValue t = GetLastParentDocument(BaseDoc, ElementPath);
if (t.IsBsonDocument)
{
t.AsBsonDocument.Remove(El.Name);
}
SystemManager.GetCurrentCollection().Save(BaseDoc);
}
开发者ID:huohe2009,项目名称:MagicMongoDBTool,代码行数:15,代码来源:MongoDBHelper_Element.cs
示例16: CutElement
/// <summary>
/// Cut Element
/// </summary>
/// <param name="ElementPath"></param>
public static void CutElement(String ElementPath, BsonElement El)
{
_ClipElement = El;
_IsElementClip = true;
DropElement(ElementPath, El);
}
开发者ID:huohe2009,项目名称:MagicMongoDBTool,代码行数:10,代码来源:MongoDBHelper_Element.cs
示例17: GeoHaystackSearchOptionsDocument
/// <summary>
/// Initializes a new instance of the GeoHaystackSearchOptionsDocument class and adds one element.
/// </summary>
/// <param name="element">An element to add to the document.</param>
public GeoHaystackSearchOptionsDocument(
BsonElement element
)
: base(element)
{
}
开发者ID:vshlos,项目名称:mongo-csharp-driver,代码行数:10,代码来源:GeoHaystackSearchOptionsDocument.cs
示例18: TryGetElement
/// <summary>
/// Tries to get an element of this document.
/// </summary>
/// <param name="name">The name of the element.</param>
/// <param name="element">The element.</param>
/// <returns>
/// True if an element with that name was found.
/// </returns>
public override bool TryGetElement(string name, out BsonElement element)
{
ThrowIfDisposed();
using (var stream = new ByteBufferStream(_slice, ownsBuffer: false))
using (var bsonReader = new BsonBinaryReader(stream, _readerSettings))
{
var context = BsonDeserializationContext.CreateRoot(bsonReader);
bsonReader.ReadStartDocument();
while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
{
if (bsonReader.ReadName() == name)
{
var value = DeserializeBsonValue(context);
element = new BsonElement(name, value);
return true;
}
bsonReader.SkipValue();
}
bsonReader.ReadEndDocument();
element = default(BsonElement);
return false;
}
}
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:34,代码来源:RawBsonDocument.cs
示例19: IndexOptionsDocument
/// <summary>
/// Initializes a new instance of the IndexOptionsDocument class and adds one element.
/// </summary>
/// <param name="element">An element to add to the document.</param>
public IndexOptionsDocument(
BsonElement element
)
: base(element) {
}
开发者ID:ebix,项目名称:mongo-csharp-driver,代码行数:9,代码来源:IndexOptionsDocument.cs
示例20: UpdateDocument
/// <summary>
/// Initializes a new instance of the UpdateDocument class and adds one element.
/// </summary>
/// <param name="element">An element to add to the document.</param>
public UpdateDocument(BsonElement element)
: base(element)
{
}
开发者ID:abel,项目名称:sinan,代码行数:8,代码来源:UpdateDocument.cs
注:本文中的BsonElement类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论