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);
        }
        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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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()));
            }
        }
        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);
        }
        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);
        }
        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);
        }
 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);
 }
 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);
 }
 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);
 }