Esempio n. 1
0
        public void Store(Summoner summoner)
        {
            var existing = _summoners.GetDocument <Summoner>(summoner.Id);

            if (existing != null)
            {
                existing = UpdateExisting(existing, summoner);
            }

            var result = _summoners.SaveDocument(new Document <Summoner>(existing));
        }
Esempio n. 2
0
        public static void ToCouchDb(RuntimeStorage intent)
        {
            CouchClient client = new CouchClient();

            if (!client.HasDatabase(DATABASE))
            {
                client.CreateDatabase(DATABASE);
            }

            CouchDatabase     db = client.GetDatabase(DATABASE);
            CouchDbIntentData dbIntent;

            try{
                Document doc = db.GetDocument(intent.filename);
                dbIntent      = new CouchDbIntentData();
                dbIntent.data = intent.data;

                Document <CouchDbIntentData> tosave = new Document <CouchDbIntentData>(dbIntent);
                tosave.Id  = doc.Id;
                tosave.Rev = doc.Rev;
                db.SaveDocument(tosave);
            }catch {
                dbIntent      = new CouchDbIntentData();
                dbIntent.data = intent.data;
                Document <CouchDbIntentData> tosave = new Document <CouchDbIntentData>(dbIntent);
                tosave.Id = intent.filename;

                db.CreateDocument(tosave);
            }
        }
        public T Update <T>(long id, T data) where T : BaseModel
        {
            var doc        = _db.GetDocument <T>(id.ToString());
            var serialized = _db.ObjectSerializer.Serialize(data);

            _db.SaveDocument(new Document(serialized));
            return(doc);
        }
Esempio n. 4
0
        public virtual void Save(T item)
        {
            if (item.Id == "")
            {
                item.Id = Guid.NewGuid().ToString();
            }
            var doc = new Document <T>(item);

            db.SaveDocument(doc);
        }
Esempio n. 5
0
        public void SetUp()
        {
            var host = ConfigurationManager.AppSettings["CouchHost"] ?? "localhost";
            var port = Convert.ToInt32(ConfigurationManager.AppSettings["CouchPort"] ?? "5984");
            server = new CouchServer(host, port);
            db = server.GetNewDatabase(DbName);
            Car car = null;

            for (int i = 0; i < 10; i++)
            {
                car = new Car("Saab", "93", 170 + i);
                db.SaveDocument(car);
            }
            tempView = db.NewTempView("test", "test", "if (doc.docType && doc.docType == 'car') emit(doc.Hps, doc);");
        }
Esempio n. 6
0
        public static ImageAnnotation UpdateExisting(string library, string id, JObject data)
        {
            CouchDbAnnotation toUpdate = null;
            CouchDatabase     db       = GetDatabase(library);

            try
            {
                toUpdate = db.GetDocument <CouchDbAnnotation>(id);
            }
            catch {
                return(null);
            }

            toUpdate.data = data;

            Document <CouchDbAnnotation> document = new Document <CouchDbAnnotation>(toUpdate);

            db.SaveDocument(document);

            return(CouchDbAnnotationToImageAnnotation(toUpdate));
        }