Exemplo n.º 1
0
 public void Delete(IEnumerable <JToken> tokens)
 {
     foreach (var token in tokens)
     {
         database.DeleteDocument(token.Value <string>("_id"), token.Value <string>("_rev"));
     }
 }
Exemplo n.º 2
0
        public static void Delete(string library, string id)
        {
            CouchDatabase db = GetDatabase(library);
            Document      ca = db.GetDocument(id);

            db.DeleteDocument(ca.Id, ca.Rev);
        }
Exemplo n.º 3
0
        public void UpdateIfNecessary()
        {
            var repo = new CouchRepository <DesignDoc>(db);

            foreach (var file in Directory.GetFiles(this.filePath))
            {
                //get the hash of the file.  Compare against the hash on the design doc.  If they don't match then update.
                string designId = "_design/" + Path.GetFileNameWithoutExtension(file);
                string contents = File.ReadAllText(file);

                JObject obj  = JObject.Parse(contents);
                string  hash = Sha1Util.Sha1HashStringForUtf8String(contents);
                var     doc  = db.GetDocument <DesignDoc>(designId);
                if (doc != null)
                {
                    db.DeleteDocument(doc.Id, doc.Rev);
                }
                var newDoc = new DesignDoc
                {
                    Id    = designId,
                    Hash  = hash,
                    Views = obj
                };
                repo.Save(newDoc);
                return;
            }
        }
Exemplo n.º 4
0
        public void Should_Trigger_Replication_using_replicator_db()
        {
            CouchDatabase replDb = client.GetDatabase("_replicator");

            ICouchDocument existingDoc = replDb.GetDocument <JDocument>("C");

            if (existingDoc != null)
            {
                replDb.DeleteDocument(existingDoc);
            }

            CouchReplicationDocument doc = replDb.CreateDocument(
                new CouchReplicationDocument
            {
                Id          = "C",
                Source      = baseDatabase,
                Target      = String.Format("http://{0}:5984/{1}", couchdbHostName, replicateDatabase),
                Continuous  = true,
                UserContext = new UserContext {
                    Name = "bob", Roles = new[] { "role1", "role2" }
                }
            });

            //Sleep two second to ensure the replicationid is set by couchdb
            System.Threading.Thread.Sleep(2000);

            CouchReplicationDocument doc2 = replDb.GetDocument <CouchReplicationDocument>("C");

            Assert.IsNotEmpty(doc2.ReplicationId);
            Assert.IsNotEmpty(doc2.ReplicationState);
            Assert.IsTrue(doc2.Continuous);
            Assert.IsTrue(doc2.ReplicationStateTime.HasValue);
            Assert.IsNotNull(doc2.UserContext);
            Assert.AreEqual("bob", doc2.UserContext.Name);
            Assert.AreEqual(2, doc2.UserContext.Roles.Length);
            Assert.AreEqual("role1", doc2.UserContext.Roles[0]);
            Assert.AreEqual("role2", doc2.UserContext.Roles[1]);

            replDb.DeleteDocument(doc2);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Repository methods don't have the business validation.  Use the service methods to enforce.
 /// </summary>
 /// <param name="obj"></param>
 public virtual void Delete(T obj)
 {
     db.DeleteDocument(obj.Id.ToString(), obj.Rev);
 }