Ejemplo n.º 1
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;
            }
        }
Ejemplo n.º 2
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 )
                {
                   var newDoc = new DesignDoc
                        {
                            Id = designId,
                            Hash = hash,
                            Views = obj
                        };
                    repo.Save(newDoc);
                    return;
                }
                var designDoc = doc.Item;

                designDoc.Views = obj;
                designDoc.Hash = hash;
                repo.Save(designDoc);
               }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            CouchRepository <Player> cr = new CouchRepository <Player>();
            Player player = cr.Find("U1");

            if (player == null)
            {
                player = new Player()
                {
                    Id = "U1", FirstName = "Sergio", SecondName = "Ronchi"
                };
                player.Profiles.Add(new PlayerProfile()
                {
                    DateOfBirth = new DateTime(1964, 11, 27)
                });
            }
            else
            {
                player.Follower.Add(new Player()
                {
                    Id = "2", FirstName = "Pippo"
                });
            }



            cr.Save(player);

            //c.Basics();
        }