本文整理汇总了C#中BsonDocument.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# BsonDocument.Contains方法的具体用法?C# BsonDocument.Contains怎么用?C# BsonDocument.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BsonDocument
的用法示例。
在下文中一共展示了BsonDocument.Contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GeneralTrigger
public GeneralTrigger(BsonDocument doc, TriggerType triggerType) {
TriggerOn = new List<string>();
And = new List<string>();
NotOn = new List<string>();
MessageOverrideAsString = new List<string>();
if (doc != null && doc.ElementCount > 0 && doc.Contains("TriggerOn")) {
foreach (var on in doc["TriggerOn"].AsBsonArray) {
TriggerOn.Add(on.AsString);
}
foreach (var and in doc["And"].AsBsonArray) {
And.Add(and.AsString);
}
foreach (var not in doc["NoTriggerOn"].AsBsonArray) {
NotOn.Add(not.AsString);
}
AutoProcess = doc.Contains("AutoProcess") ? doc["AutoProcess"].AsBoolean : false;
ChanceToTrigger = doc["ChanceToTrigger"].AsInt32;
script = ScriptFactory.GetScript(doc["ScriptID"].AsString, triggerType.ToString());
foreach (var overrides in doc["Overrides"].AsBsonArray) {
MessageOverrideAsString.Add(overrides.AsString);
}
Type = doc["Type"].AsString;
TriggerId = doc["Id"].AsString;
}
}
示例2: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
decimal price = 0m;
if (!document.Contains(OrganizationRepository.FieldNames.PlanId))
return;
switch (document.GetValue(OrganizationRepository.FieldNames.PlanId).AsString) {
case "EX_SMALL":
price = BillingManager.SmallPlan.Price;
break;
case "EX_MEDIUM":
price = BillingManager.MediumPlan.Price;
break;
case "EX_LARGE":
price = BillingManager.LargePlan.Price;
break;
}
if (price == 0m)
return;
if (!document.Contains(OrganizationRepository.FieldNames.BillingPrice))
document.Add(OrganizationRepository.FieldNames.BillingPrice, new BsonString(price.ToString()));
else
document.Set(OrganizationRepository.FieldNames.BillingPrice, new BsonString(price.ToString()));
collection.Save(document);
}
示例3: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document)
{
if (document.Contains("ErrorCount"))
document.ChangeName("ErrorCount", "EventCount");
if (document.Contains("TotalErrorCount"))
document.ChangeName("TotalErrorCount", "TotalEventCount");
if (document.Contains("LastErrorDate"))
document.ChangeName("LastErrorDate", "LastEventDate");
if (document.Contains("MaxErrorsPerMonth"))
document.ChangeName("MaxErrorsPerMonth", "MaxEventsPerMonth");
if (document.Contains("SuspensionCode")) {
var value = document.GetValue("SuspensionCode");
document.Remove("SuspensionCode");
SuspensionCode suspensionCode;
if (value.IsString && Enum.TryParse(value.AsString, true, out suspensionCode))
document.Set("SuspensionCode", suspensionCode);
}
collection.Save(document);
}
示例4: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
if (document.Contains("OverageHours"))
document.Remove("OverageHours");
if (document.Contains("Usage"))
document.Remove("Usage");
collection.Save(document);
}
示例5: InsertOneBsonDocument
public void InsertOneBsonDocument()
{
var bsonDocument = new BsonDocument()
{
{"Name","Mehmet Çakır"},
{"Email","[email protected]"}
};
bsonDocument.Contains("_id").Should().BeFalse();
Func<Task> act = () => BlogContext.UserAsBson.InsertOneAsync(bsonDocument);
act.ShouldNotThrow();
bsonDocument.Contains("_id").Should().BeTrue();
bsonDocument["_id"].Should().NotBe(ObjectId.Empty);
}
示例6: GetUpdateFlags
/// <summary>
///
/// </summary>
/// <param name="document"></param>
/// <returns></returns>
private UpdateFlags GetUpdateFlags(BsonDocument document) {
var flags = UpdateFlags.None;
if (document.Contains("upsert")) {
flags = flags | ((document["upsert"].ToBoolean()) ? (UpdateFlags.Upsert) : (UpdateFlags.None));
}
if (document.Contains("multi")) {
flags = flags | ((document["multi"].ToBoolean()) ? (UpdateFlags.Upsert) : (UpdateFlags.None));
}
return flags;
}
示例7: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
if (document.Contains("OverageDays"))
document.Remove("OverageDays");
if (document.Contains("MaxErrorsPerDay")) {
document.ChangeName("MaxErrorsPerDay", "MaxErrorsPerMonth");
var maxErrorsPerMonth = document.GetValue("MaxErrorsPerMonth").AsInt32;
if (maxErrorsPerMonth > 0)
document.Set("MaxErrorsPerMonth", maxErrorsPerMonth * 30);
}
collection.Save(document);
}
示例8: AggregateResult
// constructors
/// <summary>
/// Initializes a new instance of the <see cref="AggregateResult" /> class.
/// </summary>
/// <param name="response">The response.</param>
public AggregateResult(BsonDocument response)
: base(response)
{
if (response.Contains("cursor"))
{
var cursorDocument = response["cursor"];
_cursorId = cursorDocument["id"].ToInt64();
_resultDocuments = cursorDocument["firstBatch"].AsBsonArray.Select(v => v.AsBsonDocument);
}
if (response.Contains("result"))
{
_resultDocuments = response["result"].AsBsonArray.Select(v => v.AsBsonDocument);
}
}
示例9: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
if (document.Contains("OrganizationId"))
document.ChangeName("OrganizationId", "oid");
if (document.Contains("ProjectId"))
document.ChangeName("ProjectId", "pid");
if (document.Contains("Version"))
document.Remove("Version");
document.Set("Version", "1.0.0.0");
collection.Save(document);
}
示例10: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
if (!document.Contains(OrganizationRepository.FieldNames.PlanId))
return;
string planId = document.GetValue(OrganizationRepository.FieldNames.PlanId).AsString;
if (String.IsNullOrEmpty(planId) || !String.Equals(planId, BillingManager.FreePlan.Id))
return;
if (!document.Contains(OrganizationRepository.FieldNames.RetentionDays))
document.Add(OrganizationRepository.FieldNames.RetentionDays, new BsonInt64(BillingManager.FreePlan.RetentionDays));
else
document.Set(OrganizationRepository.FieldNames.RetentionDays, new BsonInt64(BillingManager.FreePlan.RetentionDays));
collection.Save(document);
}
示例11: And
/// <summary>
/// Combines subqueries with an and operator.
/// </summary>
/// <param name="queries">The subqueries.</param>
/// <returns>The builder (so method calls can be chained).</returns>
public static QueryComplete And(
params QueryComplete[] queries
) {
var document = new BsonDocument();
foreach (var query in queries) {
foreach (var queryElement in query.ToBsonDocument()) {
// if result document has existing operations for same field append the new ones
if (document.Contains(queryElement.Name)) {
var existingOperations = document[queryElement.Name] as BsonDocument;
var newOperations = queryElement.Value as BsonDocument;
// make sure that no conditions are Query.EQ, because duplicates aren't allowed
if (existingOperations == null || newOperations == null) {
var message = string.Format("Query.And does not support combining equality comparisons with other operators (field: '{0}')", queryElement.Name);
throw new InvalidOperationException(message);
}
// add each new operation to the existing operations
foreach (var operation in newOperations) {
// make sure that there are no duplicate $operators
if (existingOperations.Contains(operation.Name)) {
var message = string.Format("Query.And does not support using the same operator more than once (field: '{0}', operator: '{1}')", queryElement.Name, operation.Name);
throw new InvalidOperationException(message);
} else {
existingOperations.Add(operation);
}
}
} else {
document.Add(queryElement);
}
}
}
return new QueryComplete(document);
}
示例12: GetMatchDocument
/// <summary>
/// 获取Match
/// </summary>
/// <returns></returns>
public BsonDocument GetMatchDocument()
{
BsonDocument Matchlist = new BsonDocument();
foreach (ctlMatchItem item in this.Controls)
{
BsonDocument match = item.getMatchItem();
if (match != null)
{
string MatchName = match.GetElement(0).Name;
if (Matchlist.Contains(MatchName))
{
BsonDocument AddMatch = match.GetElement(0).Value.AsBsonDocument;
Matchlist.GetElement(MatchName).Value.AsBsonDocument.Add(AddMatch);
}
else {
Matchlist.Add(match);
}
}
}
if (Matchlist.ElementCount > 0)
{
return new BsonDocument("$match", Matchlist);
}
else
{
return null;
}
}
示例13: GetMatchDocument
/// <summary>
/// 获取Match
/// </summary>
/// <returns></returns>
public BsonDocument GetMatchDocument()
{
var matchlist = new BsonDocument();
foreach (Control item in Controls)
{
if (item.GetType().FullName == typeof(Button).FullName) continue;
var match = ((CtlMatchItem)item).GetMatchItem();
if (match != null)
{
var matchName = match.GetElement(0).Name;
if (matchlist.Contains(matchName))
{
var addMatch = match.GetElement(0).Value.AsBsonDocument;
matchlist.GetElement(matchName).Value.AsBsonDocument.AddRange(addMatch);
}
else
{
matchlist.AddRange(match);
}
}
}
if (matchlist.ElementCount > 0)
{
return new BsonDocument("$match", matchlist);
}
return null;
}
示例14: GetDateTime
public static DateTime GetDateTime(BsonDocument doc, string propertyName)
{
DateTime result = DateTime.MinValue;
if (doc.Contains(propertyName))
result = doc[propertyName].ToUniversalTime();
return result;
}
示例15: GetArray
public static BsonArray GetArray(BsonDocument doc, string propertyName)
{
BsonArray result = null;
if (doc.Contains(propertyName))
result = doc[propertyName].AsBsonArray;
return result;
}