当前位置: 首页>>代码示例>>C#>>正文


C# BsonDocument.TryGetValue方法代码示例

本文整理汇总了C#中BsonDocument.TryGetValue方法的典型用法代码示例。如果您正苦于以下问题:C# BsonDocument.TryGetValue方法的具体用法?C# BsonDocument.TryGetValue怎么用?C# BsonDocument.TryGetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BsonDocument的用法示例。


在下文中一共展示了BsonDocument.TryGetValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AssertValid

        private void AssertValid(ConnectionString connectionString, BsonDocument definition)
        {
            if (!definition["valid"].ToBoolean())
            {
                Assert.Fail($"The connection string '{definition["uri"]}' should be invalid.");
            }

            BsonValue readConcernValue;
            if (definition.TryGetValue("readConcern", out readConcernValue))
            {
                var readConcern = ReadConcern.FromBsonDocument((BsonDocument)readConcernValue);

                connectionString.ReadConcernLevel.Should().Be(readConcern.Level);
            }

            BsonValue writeConcernValue;
            if (definition.TryGetValue("writeConcern", out writeConcernValue))
            {
                var writeConcern = WriteConcern.FromBsonDocument(MassageWriteConcernDocument((BsonDocument)writeConcernValue));

                connectionString.W.Should().Be(writeConcern.W);
                connectionString.WTimeout.Should().Be(writeConcern.WTimeout);
                connectionString.Journal.Should().Be(writeConcern.Journal);
                connectionString.FSync.Should().Be(writeConcern.FSync);
            }
        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:26,代码来源:ConnectionStringTestRunner.cs

示例2: UpdateDocument

        public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
            var errorCollection = Database.GetCollection(ErrorRepository.CollectionName);

            ObjectId stackId = document.GetValue(ErrorStackRepository.FieldNames.Id).AsObjectId;
            if (stackId == ObjectId.Empty)
                return;

            BsonValue value;
            bool isHidden = false;
            if (document.TryGetValue(ErrorStackRepository.FieldNames.IsHidden, out value))
                isHidden = value.AsBoolean;

            DateTime? dateFixed = null;

            if (document.TryGetValue(ErrorStackRepository.FieldNames.DateFixed, out value))
                dateFixed = value.ToNullableUniversalTime();

            IMongoQuery query = Query.EQ(ErrorRepository.FieldNames.ErrorStackId, new BsonObjectId(stackId));

            var update = new UpdateBuilder();
            if (isHidden)
                update.Set(ErrorRepository.FieldNames.IsHidden, true);
            if (dateFixed.HasValue)
                update.Set(ErrorRepository.FieldNames.IsFixed, true);

            if (isHidden || dateFixed.HasValue)
                errorCollection.Update(query, update);
        }
开发者ID:priestd09,项目名称:Exceptionless,代码行数:28,代码来源:v1.0.26.cs

示例3: Map

        /// <summary>
        /// Maps the specified response to a custom exception (if possible).
        /// </summary>
        /// <param name="response">The response.</param>
        /// <returns>The custom exception (or null if the response could not be mapped to a custom exception).</returns>
        public static Exception Map(BsonDocument response)
        {
            BsonValue code;
            if (response.TryGetValue("code", out code) && code.IsNumeric)
            {
                switch (code.ToInt32())
                {
                    case 50:
                    case 13475:
                    case 16986:
                    case 16712:
                        return new ExecutionTimeoutException("Operation exceeded time limit.");
                }
            }

            // the server sometimes sends a response that is missing the "code" field but does have an "errmsg" field
            BsonValue errmsg;
            if (response.TryGetValue("errmsg", out errmsg) && errmsg.IsString)
            {
                if (errmsg.AsString.Contains("exceeded time limit") ||
                    errmsg.AsString.Contains("execution terminated"))
                {
                    return new ExecutionTimeoutException("Operation exceeded time limit.");
                }
            }

            return null;
        }
开发者ID:Bogdan0x400,项目名称:mongo-csharp-driver,代码行数:33,代码来源:ExceptionMapper.cs

示例4: UpdateDocument

        public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document)
        {
            var errorCollection = Database.GetCollection("error");

            ObjectId stackId = document.GetValue("_id").AsObjectId;
            if (stackId == ObjectId.Empty)
                return;

            BsonValue value;
            bool isHidden = false;
            if (document.TryGetValue("hid", out value))
                isHidden = value.AsBoolean;

            DateTime? dateFixed = null;

            if (document.TryGetValue("fdt", out value))
                dateFixed = value.ToNullableUniversalTime();

            IMongoQuery query = Query.EQ("sid", new BsonObjectId(stackId));

            var update = new UpdateBuilder();
            if (isHidden)
                update.Set("hid", true);
            if (dateFixed.HasValue)
                update.Set("fix", true);

            if (isHidden || dateFixed.HasValue)
                errorCollection.Update(query, update, UpdateFlags.Multi);
        }
开发者ID:arpitgold,项目名称:Exceptionless,代码行数:29,代码来源:v1.0.28.cs

示例5: RunTestDefinition

        public void RunTestDefinition(BsonDocument definition)
        {
            BsonValue readConcernValue;
            if (definition.TryGetValue("readConcern", out readConcernValue))
            {
                ValidateReadConcern(definition);
            }

            BsonValue writeConcernValue;
            if (definition.TryGetValue("writeConcern", out writeConcernValue))
            {
                ValidateWriteConcern(definition);
            }
        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:14,代码来源:DocumentTestRunner.cs

示例6: Ins

        private static string Ins(BsonDocument doc)
        {
            try
            {
                BsonValue id;
            if (!doc.TryGetValue("_id", out id))
                throw new Exception("fant ikke _id");

                var exp = new ExpenseModel
                              {
                                  IsCommon = doc.GetValue("IsCommon", true).ToBoolean(),
                                  IsPossibleDuplicate = doc.GetValue("IsPossibleDuplicate", false).ToBoolean(),
                                  Means = doc.GetValue("Means", string.Empty).ToString(),
                                  Owner = doc.GetValue("Owner", string.Empty).ToString(),
                                  Amount = doc.GetValue("Amount", 0).ToDouble(),
                                  Description = doc.GetValue("Description", string.Empty).ToString(),
                                  Date = doc.GetValue("Date").AsDateTime
                              };
                var nu = ModelCollection<ExpenseModel>.InsertItem(exp);
                return "insert " + nu.Id;

            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
开发者ID:pronning,项目名称:punch,代码行数:27,代码来源:Importer.cs

示例7: DefaultImplementation

        // public static methods
        /// <summary>
        /// Default implementation of the CanCommandBeSentToSecondary delegate.
        /// </summary>
        /// <param name="document">The command.</param>
        /// <returns>True if the command can be sent to a secondary member of a replica set.</returns>
        public static bool DefaultImplementation(BsonDocument document)
        {
            if (document.ElementCount == 0)
            {
                return false;
            }

            var commandName = document.GetElement(0).Name;

            if (__secondaryOkCommands.Contains(commandName))
            {
                return true;
            }

            if (commandName.Equals("mapreduce", StringComparison.InvariantCultureIgnoreCase))
            {
                BsonValue outValue;
                if (document.TryGetValue("out", out outValue) && outValue.IsBsonDocument)
                {
                    return outValue.AsBsonDocument.Contains("inline");
                }
            }

            return false;
        }
开发者ID:Khosrow-Azizi,项目名称:MasterExperimentV2,代码行数:31,代码来源:CanCommandBeSentToSecondary.cs

示例8: Create

        // static methods
        public static BulkWriteBatchResult Create(
            bool isOrdered,
            IReadOnlyList<WriteRequest> requests,
            BsonDocument writeCommandResponse,
            IndexMap indexMap)
        {
            var writeErrors = CreateWriteErrors(writeCommandResponse);
            var writeConcernError = CreateWriteConcernError(writeCommandResponse);
            var processedRequests = CreateProcessedRequests(requests, writeErrors, isOrdered);
            var unprocessedRequests = CreateUnprocessedRequests(requests, writeErrors, isOrdered);
            var upserts = CreateUpserts(writeCommandResponse);

            var n = writeCommandResponse.GetValue("n", 0).ToInt64();
            var matchedCount = 0L;
            var deletedCount = 0L;
            var insertedCount = 0L;
            long? modifiedCount = 0L;
            var firstRequest = requests.FirstOrDefault();
            if (firstRequest != null)
            {
                switch (firstRequest.RequestType)
                {
                    case WriteRequestType.Delete:
                        deletedCount = n;
                        break;
                    case WriteRequestType.Insert:
                        insertedCount = n;
                        break;
                    case WriteRequestType.Update:
                        matchedCount = n - upserts.Count();
                        BsonValue nModified;
                        if (writeCommandResponse.TryGetValue("nModified", out nModified))
                        {
                            modifiedCount = nModified.ToInt64();
                        }
                        else
                        {
                            modifiedCount = null;
                        }
                        break;
                }
            }

            return new BulkWriteBatchResult(
                requests.Count,
                processedRequests,
                unprocessedRequests,
                matchedCount,
                deletedCount,
                insertedCount,
                modifiedCount,
                upserts,
                writeErrors,
                writeConcernError,
                indexMap);
        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:57,代码来源:BulkWriteBatchResult.cs

示例9: MapValue

 protected int? MapValue(BsonDocument document, string field, int? dontCare)
 {
     int? intValue = default(int?);
     BsonValue bsonField;
     if (document.TryGetValue(field, out bsonField))
     {
         intValue = bsonField.AsNullableInt32;
     }
     return intValue;
 }
开发者ID:qanwi1970,项目名称:dungeon-mart,代码行数:10,代码来源:BsonMapper.cs

示例10: CreateJsonFile

 private static void CreateJsonFile(string jsonReportsDirectory, BsonDocument report)
 {
     report.Remove("_id");
     BsonValue productIdAsBson;
     report.TryGetValue("product-id", out productIdAsBson);
     using (var file = new StreamWriter(jsonReportsDirectory + productIdAsBson.AsInt32 + ".json"))
     {
         file.WriteLine(report.ToJson());
     }
 }
开发者ID:TeamMojito,项目名称:SupermarketsDatabaseClient,代码行数:10,代码来源:MongoDBConnector.cs

示例11: GetString

        private static String GetString(BsonDocument doc, String key, String defaultValue = "")
        {
            BsonValue value;
            var contains = doc.TryGetValue(key, out value);

            if (!contains || !value.IsString)
                return defaultValue;

            return value.AsString;
        }
开发者ID:mmanole,项目名称:prototype,代码行数:10,代码来源:MongoTransitionSerializer.cs

示例12: ThrowIfHasWriteConcernError

 public static void ThrowIfHasWriteConcernError(ConnectionId connectionId, BsonDocument result)
 {
     BsonValue value;
     if (result.TryGetValue("writeConcernError", out value))
     {
         var message = (string)value.AsBsonDocument.GetValue("errmsg", null);
         var writeConcernResult = new WriteConcernResult(result);
         throw new MongoWriteConcernException(connectionId, message, writeConcernResult);
     }
 }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:10,代码来源:WriteConcernErrorHelper.cs

示例13: KeyOf

 public BsonValue KeyOf(BsonDocument document)
 {
     BsonValue value = null;
     if (document.TryGetValue(Field.RESOURCEID, out value))
     {
         return value;
     }
     else
     {
         return null;
     }
 }
开发者ID:Condeti,项目名称:spark,代码行数:12,代码来源:Transaction.cs

示例14: LoadDataFromBSON

 /// <summary>
 /// Inits record feld values from BSON document
 /// </summary>
 public static void LoadDataFromBSON(this Record rec, BsonDocument doc)
 {
   foreach(var fld in rec.Fields.Where(f => f.StoreFlag == StoreFlag.LoadAndStore || f.StoreFlag == StoreFlag.OnlyLoad))
   {
     BsonValue val;
     if (!doc.TryGetValue(fld.FieldName, out val)) continue;
     
     if (val is BsonDateTime)
      fld.ValueAsDateTime = val.ToUniversalTime();// .AsDateTime;
     else
      fld.ValueAsObject = val.AsBsonValue;//.RawValue;
   }
 }
开发者ID:sergey-msu,项目名称:nfx,代码行数:16,代码来源:MongoDBBSONGenerator.cs

示例15: MassageReply

        public virtual BsonDocument MassageReply(BsonDocument reply)
        {
            var massagedReply = new BsonDocument(reply);
            BsonValue ok;
            if (massagedReply.TryGetValue("ok", out ok))
            {
                // have to force every ok value into a double since the server
                // hasn't chosen a consistent representation.
                massagedReply["ok"] = ok.ToDouble();
            }

            return massagedReply;
        }
开发者ID:RainsSoft,项目名称:mongo-csharp-driver,代码行数:13,代码来源:CrudOperationTestBase.cs


注:本文中的BsonDocument.TryGetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。