当前位置: 首页>>代码示例>>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;未经允许,请勿转载。