當前位置: 首頁>>代碼示例>>C#>>正文


C# BsonDocument.GetDocumentId方法代碼示例

本文整理匯總了C#中BsonDocument.GetDocumentId方法的典型用法代碼示例。如果您正苦於以下問題:C# BsonDocument.GetDocumentId方法的具體用法?C# BsonDocument.GetDocumentId怎麽用?C# BsonDocument.GetDocumentId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在BsonDocument的用法示例。


在下文中一共展示了BsonDocument.GetDocumentId方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: OnErrorUpdatingDocument

        protected virtual void OnErrorUpdatingDocument(BsonDocument document, Exception exception) {
            var error = new DocumentMigrationError(document.GetDocumentId().ToString(), exception.ToString());
            if (MigrationErrorCallback != null)
                MigrationErrorCallback(this, error);

            string message = String.Format("Failed updating document \"{0}\" in \"{1}\" for migration \"{2}\" for version {3} to database \"{4}\": {5}",
                document.GetDocumentId(), CollectionName, Description, Version, Database.Name, exception.Message);
            Trace.TraceError(message);
        }
開發者ID:khoussem,項目名稱:Exceptionless,代碼行數:9,代碼來源:CollectionMigration.cs

示例2: UpdateDocument

        public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
            if (document.Contains("oid")) {
                var organizationId = document.GetValue("oid").AsNullableObjectId;
                if (!organizationId.HasValue || organizationId.Value == ObjectId.Empty) {
                    document.Remove("oid");
                } else {
                    var organizationCollection = Database.GetCollection("organization");
                    var organization = organizationCollection.FindOneById(organizationId);

                    // The organization with this id could not be found.. Remove the webhook.
                    if (organization == null) {
                        collection.Remove(Query.EQ("_id", document.GetDocumentId()));
                        return;
                    }
                }
            }

            var projectCollection = Database.GetCollection("project");
            if (document.Contains("pid")) {
                var projectId = document.GetValue("pid").AsNullableObjectId;
                if (!projectId.HasValue || projectId.Value == ObjectId.Empty) {
                    document.Remove("pid");
                } else {
                    var project = projectCollection.FindOneById(projectId);

                    // The project with this id could not be found.. Remove the webhook.
                    if (project == null) {
                        collection.Remove(Query.EQ("_id", document.GetDocumentId()));
                        return;
                    }

                    if (!document.Contains("oid"))
                        document.Set("oid", project.GetValue("oid").AsObjectId);
                }
            }

            if (!document.Contains("oid") && !document.Contains("pid")) {
                collection.Remove(Query.EQ("_id", document.GetDocumentId()));
                return;
            }

            collection.Save(document);
        }
開發者ID:aamarber,項目名稱:Exceptionless,代碼行數:43,代碼來源:v1.0.37.cs

示例3: UpdateDocument

        public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
            if (document.Contains("oid")) {
                var organizationId = document.GetValue("oid").AsNullableObjectId;
                if (!organizationId.HasValue || organizationId.Value == ObjectId.Empty) {
                    // The organization id is invalid. Remove the token.
                    collection.Remove(Query.EQ("_id", document.GetDocumentId()));
                    return;
                }

                var organizationCollection = Database.GetCollection("organization");
                var organization = organizationCollection.FindOneById(organizationId.Value);

                // The organization with this id could not be found.. Remove the token.
                if (organization == null) {
                    collection.Remove(Query.EQ("_id", document.GetDocumentId()));
                    return;
                }
            }

            if (document.Contains("pid")) {
                var projectId = document.GetValue("pid").AsNullableObjectId;
                if (!projectId.HasValue || projectId.Value == ObjectId.Empty) {
                    // The project id is invalid. Remove the token.
                    collection.Remove(Query.EQ("_id", document.GetDocumentId()));
                    return;
                }

                var projectCollection = Database.GetCollection("project");
                var project = projectCollection.FindOneById(projectId.Value);

                // The project with this id could not be found.. Remove the token.
                if (project == null) {
                    collection.Remove(Query.EQ("_id", document.GetDocumentId()));
                    return;
                }
            }

            // Remove the token if it's not associated to an organization, project or user.
            if (!document.Contains("oid") && !document.Contains("pid") && !document.Contains("uid")) {
                collection.Remove(Query.EQ("_id", document.GetDocumentId()));
            }
        }
開發者ID:aamarber,項目名稱:Exceptionless,代碼行數:42,代碼來源:v1.0.38.cs

示例4: TestGetDocumentId

        public void TestGetDocumentId()
        {
            var document = new BsonDocument { { "_id", 1 }, { "x", "abc" } };
            object id;
            Type nominalType;
            IIdGenerator idGenerator;
#pragma warning disable 618 // GetDocumentId is obsolete
            Assert.IsTrue(document.GetDocumentId(out id, out nominalType, out idGenerator));
#pragma warning restore
            Assert.IsInstanceOf<int>(id); // TODO: in a future release id will be an instance of BsonInt32
            Assert.AreEqual(1, (int)id);
            Assert.AreEqual(typeof(BsonValue), nominalType);
            Assert.IsNull(idGenerator);
        }
開發者ID:nickgervasi,項目名稱:mongo-csharp-driver,代碼行數:14,代碼來源:CSharp446Tests.cs

示例5: UpdateDocument

        public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
            var errorRepository = new ErrorRepository(collection.Database, null, null, null);
            BsonValue id = document.GetDocumentId();
            if (id == null || !id.IsObjectId)
                return;

            Error error = errorRepository.GetById(id.ToString());
            if (error == null)
                return;

            if (document.Contains("sig"))
                document.Remove("sig");

            var signatureFactory = new ErrorSignatureFactory();
            // updates the document to set the IsSignatureTarget
            ErrorSignature signature = signatureFactory.GetSignature(error);
            errorRepository.Update(error);
        }
開發者ID:khoussem,項目名稱:Exceptionless,代碼行數:18,代碼來源:v1.0.11_Migration.cs

示例6: TestGetDocumentIdWhenIdIsMissing

 public void TestGetDocumentIdWhenIdIsMissing()
 {
     var document = new BsonDocument();
     object id;
     Type nominalType;
     IIdGenerator idGenerator;
     Assert.IsTrue(document.GetDocumentId(out id, out nominalType, out idGenerator));
     Assert.IsNull(id);
     Assert.AreEqual(typeof(BsonValue), nominalType);
     Assert.IsInstanceOf<BsonObjectIdGenerator>(idGenerator);
 }
開發者ID:doobiwan,項目名稱:mongo-csharp-driver,代碼行數:11,代碼來源:BsonDocumentTests.cs

示例7: TestGetDocumentIdWhenIdIsGuid

 public void TestGetDocumentIdWhenIdIsGuid()
 {
     var document = new BsonDocument("_id", Guid.Empty);
     object id;
     Type nominalType;
     IIdGenerator idGenerator;
     Assert.IsTrue(document.GetDocumentId(out id, out nominalType, out idGenerator));
     Assert.AreEqual(BsonValue.Create(Guid.Empty), id);
     Assert.AreEqual(typeof(BsonValue), nominalType);
     Assert.IsInstanceOf<BsonBinaryDataGuidGenerator>(idGenerator);
 }
開發者ID:doobiwan,項目名稱:mongo-csharp-driver,代碼行數:11,代碼來源:BsonDocumentTests.cs

示例8: TestGetDocumentId

 public void TestGetDocumentId()
 {
     var document = new BsonDocument("_id", 1);
     object id;
     Type nominalType;
     IIdGenerator idGenerator;
     Assert.IsTrue(document.GetDocumentId(out id, out nominalType, out idGenerator));
     Assert.AreEqual(BsonInt32.Create(1), id);
     Assert.AreEqual(typeof(BsonValue), nominalType);
     Assert.IsNull(idGenerator);
 }
開發者ID:doobiwan,項目名稱:mongo-csharp-driver,代碼行數:11,代碼來源:BsonDocumentTests.cs


注:本文中的BsonDocument.GetDocumentId方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。