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