コード例 #1
0
ファイル: RuntimeStorage.cs プロジェクト: nunb/interpretation
		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);
			}
		}
コード例 #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);
            }
        }
コード例 #3
0
            public CouchDbIntent(string name)
            {
                _intent          = new RuntimeStorage();
                _intent.filename = name;
                _intent.data     = new Dictionary <string, JToken>();

                CouchClient client = new CouchClient();

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

                CouchDatabase database = client.GetDatabase(DATABASE);

                CouchDbIntentData data = null;

                try{
                    Document d = database.GetDocument(name);
                    data = JsonConvert.DeserializeObject <CouchDbIntentData>(d.ToString());
                }catch {
                }

                if (data == null)
                {
                    data = new CouchDbIntentData();

                    data.data = new Dictionary <string, JToken>();
                    Document <CouchDbIntentData> tosave = new Document <CouchDbIntentData>(data);
                    tosave.Id = name;
                    database.CreateDocument(tosave);
                }

                if (data.data != null)
                {
                    foreach (var entry in data.data)
                    {
                        _intent.data.Add(entry.Key, entry.Value);
                    }
                }
            }
コード例 #4
0
ファイル: RuntimeStorage.cs プロジェクト: nunb/interpretation
			public CouchDbIntent(string name){
				_intent = new RuntimeStorage();
				_intent.filename = name;
				_intent.data = new Dictionary<string, JToken>();

				CouchClient client = new CouchClient();

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

				CouchDatabase database = client.GetDatabase(DATABASE);

				CouchDbIntentData data = null;
				try{
					Document d = database.GetDocument(name);
					data = JsonConvert.DeserializeObject<CouchDbIntentData>(d.ToString());
				}catch{

				}

				if(data == null)
				{
					data = new CouchDbIntentData();

					data.data = new Dictionary<string, JToken>();
					Document<CouchDbIntentData> tosave = new Document<CouchDbIntentData>(data);
					tosave.Id = name;
					database.CreateDocument( tosave );
				}

                if (data.data != null)
                {
                    foreach (var entry in data.data)
                    {
                        _intent.data.Add(entry.Key, entry.Value);
                    }
                }
			}
コード例 #5
0
 public void Clear()
 {
     _intent.data.Clear();
     RuntimeStorage.ToCouchDb(_intent);
 }
コード例 #6
0
 public void DeleteData(string key)
 {
     _intent.deleteData(key);
     RuntimeStorage.ToCouchDb(_intent);
 }
コード例 #7
0
 public void PutData(string key, JToken value)
 {
     _intent.putData(key, value);
     RuntimeStorage.ToCouchDb(_intent);
 }