Used as the starting point for any communication with CouchDB
Inheritance: LoveSeat.Support.CouchBase
示例#1
0
 public LoveSeat.ViewResult List()
 {
     var client = new CouchClient("dannylane.iriscouch.com", 6984, "dannylane", "adminpass", true, AuthenticationType.Cookie);
     var udb = client.GetDatabase("testing");
     return udb.GetAllDocuments();
    // return new JsonResult {Data = db, JsonRequestBehavior = JsonRequestBehavior.AllowGet};
 }
        public ActionResult New(string projectName)
        {
            var client = new CouchClient("dannylane.iriscouch.com", 6984, "dannylane", "adminpass", true, AuthenticationType.Cookie);
            var userresult = client.CreateUser(projectName, projectName);
            //var newUid = userresult.Value<string>("id");
            
            var u = client.GetUser(projectName);
            u["roles"] = new JArray(projectName + "reader_");
            var udb = client.GetDatabase("_users");
            udb.SaveDocument(u);

            var res = client.CreateDatabase(projectName);
            var db = client.GetDatabase(projectName);

            var security = db.getSecurityConfiguration();
            security.readers.roles.Add(projectName + "reader_");
            db.UpdateSecurityDocument(security);

            var readerClient = new CouchClient("localhost", 5984, projectName, projectName, false,
                                               AuthenticationType.Cookie);
            
           // var result = CouchBase.GetSession("localhost:5984", projectName, projectName);
            Response.Cookies.Add(new HttpCookie("auth", readerClient.GetSession().Value));
            return View();
        }
示例#3
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);
			}
		}
示例#4
0
        public ActionResult Index(string errorMessage)
        {
            var client = new CouchClient("dannylane.iriscouch.com", 6984, "dannylane", "adminpass", true, AuthenticationType.Cookie);
            var udb = client.GetDatabase("testing");

            JObject jObject = new JObject();

            jObject.Add("DateTime", DateTime.UtcNow);
            jObject.Add("UserHostAddress", Request.UserHostAddress);
            jObject.Add("UserHostName", Request.UserHostName);
          //  jObject.Add("UserLanguages", Request.UserLanguages.ToString());
            
            foreach (var param in Request.QueryString.AllKeys)
            {
                jObject.Add(param, Request.QueryString[param]);
            }

            foreach (var param in Request.Headers.AllKeys)
            {
                jObject.Add(param, Request.Headers[param]);
            }

            var info = new LoveSeat.Document(jObject);
            
            udb.SaveDocument(info);
            return File("favicon.ico","image");
        }
示例#5
0
文件: Program.cs 项目: alwalker/POCs
        static void Main(string[] args)
        {
            var client = new CouchClient("alwalker.cloudant.com", 443, "alwalker", "PASSWORD",
                true, AuthenticationType.Basic);
            var db = client.GetDatabase("cloudant-tutorial");

            Document untyped = db.GetDocument("966f8b38cba7a782899997c3487345ea");
            Thingy typed = db.GetDocument<Thingy>("966f8b38cba7a782899997c3487345ea");

            Console.WriteLine("balls");
            Console.ReadLine();
        }
示例#6
0
 public void Setup()
 {
     client = new CouchClient(host, port, username, password, false,AuthenticationType.Cookie);
     if (!client.HasDatabase(baseDatabase))
     {
         client.CreateDatabase(baseDatabase);
     }
     if (!client.HasDatabase(replicateDatabase))
     {
         client.CreateDatabase(replicateDatabase);
     }
 }
示例#7
0
 public void Setup()
 {
     client = new CouchClient(host, port, username, password);
     if (!client.HasDatabase(baseDatabase))
     {
         client.CreateDatabase(baseDatabase);
     }
     if (!client.HasDatabase(replicateDatabase))
     {
         client.CreateDatabase(replicateDatabase);
     }
 }
示例#8
0
        public void WriteData(Vector2 position, int level, int diedInPhase, int totalPhases, bool died = false)
        {
            //Create the object.
            JsonObject obj = new JsonObject();
            obj.X = (int)position.X;
            obj.Y = (int)position.Y;
            obj.Level = level;
            obj.DiedInPhase = diedInPhase;
            obj.TotalPhases = totalPhases;
            obj.Died = died;

            //Use string json = JsonConvert.SerializeObject(object); to get the object in json format.
            string json = JsonConvert.SerializeObject(obj);

            //Connect with the database.
            var client = new CouchClient("admin", "admin");
            var db = client.GetDatabase("heatmap");

            //Now add the object to the database.
            db.CreateDocument(json);
        }
示例#9
0
文件: Program.cs 项目: Slesa/Poseidon
        static void Main(string[] args)
        {

            var ccAdmin = new CouchClient("localhost", 5984, null, null, false, AuthenticationType.Cookie);

            var dbName = "firsttry";
            if (!ccAdmin.HasDatabase(dbName))
            {
                ccAdmin.CreateDatabase(dbName);
            }


            var table = new Table {Id = "5"};
            table.Families.AddRange(Family.CreateFamilies());
            table.FamilyGroups.AddRange(FamilyGroup.CreateFamilyGroups());
            var doc = new Document<Table>(table);

            var db = ccAdmin.GetDatabase(dbName);
            db.SetDefaultDesignDoc("docs"); 

            db.SaveDocument(doc);
        }
示例#10
0
 public bool Isinitialised()
 {
     var client = new CouchClient("admin", "admin");
     return client.HasDatabase("heatmap");
 }
示例#11
0
        private void ScavengeByNumber(int deleteBatchSize)
        {
            if (ConfigurationManager.AppSettings["MaxDocsInDatabase"] == null) return;

            var maxDocs = long.Parse(ConfigurationManager.AppSettings["MaxDocsInDatabase"]);
            var options = new ViewOptions();
            options.StartKey.Add(MessageIdManager.Create(new DateTime(1970, 1, 1)).ToDocId());
            options.EndKey.Add(MessageIdManager.Create(DateTime.UtcNow).ToDocId());
            var db = new CouchClient(ConfigurationManager.AppSettings["HydraServer"], int.Parse(ConfigurationManager.AppSettings["Port"]), null, null, false, AuthenticationType.Basic).
                GetDatabase(ConfigurationManager.AppSettings["Database"]);
            // Getting the empty document returns general database info
            var deleteCount = db.GetDocument("").Value<long>("doc_count") - maxDocs;
            while (deleteCount > 0) {
                options.Limit = (int) Math.Min(deleteCount, deleteBatchSize);
                var rows = db.GetAllDocuments(options).Rows;
                if (!rows.Any()) break;
                DeleteDocs(rows, db);
                deleteCount -= deleteBatchSize;
            }
        }
示例#12
0
        private void ScavengeByDate(int deleteBatchSize)
        {
            if (ConfigurationManager.AppSettings["MessageExpiryDays"] == null) return;

            var expiryDays = double.Parse(ConfigurationManager.AppSettings["MessageExpiryDays"]);
            var options = new ViewOptions();
            options.StartKey.Add(MessageIdManager.Create(new DateTime(1970, 1, 1)).ToDocId());
            options.EndKey.Add(MessageIdManager.Create(DateTime.UtcNow.AddDays(-expiryDays)).ToDocId());
            options.Limit = deleteBatchSize;
            var db = new CouchClient(ConfigurationManager.AppSettings["HydraServer"], int.Parse(ConfigurationManager.AppSettings["Port"]), null, null, false, AuthenticationType.Basic).
                GetDatabase(ConfigurationManager.AppSettings["Database"]);
            var rows = db.GetAllDocuments(options).Rows;
            while (rows.Any()) {
                DeleteDocs(rows, db);
                rows = db.GetAllDocuments(options).Rows;
            }
        }
示例#13
0
        public static List<ImageAnnotation> GetAllAnnotationsForImage(string library, string imageId, IBoundingBox region)
        {
            CouchClient client = new CouchClient();
            
            CouchDatabase db = GetDatabase(library);
            var options = new ViewOptions();
            options.Key.Add(imageId);
            options.IncludeDocs = true;

            var cannotations = db.View<CouchDbAnnotation>("by_screenshot", options, "annotations");
            List<ImageAnnotation> annotations = new List<ImageAnnotation>();
            foreach (CouchDbAnnotation ca in cannotations.Items)
            {
                BoundingBox bb = new BoundingBox(ca.left, ca.top, ca.width, ca.height);
                if (BoundingBox.Equals(region, bb))
                {
                    ImageAnnotation ia = new ImageAnnotation(bb, ca.data, ca.screenshotId);
                    annotations.Add(ia);
                }
            }

            return annotations;
        }
示例#14
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);
                    }
                }
			}
示例#15
0
 public SummonerProducer(CouchClient db)
 {
     _summoners = db.GetDatabase(DatabaseName);
     _summoners.SetDefaultDesignDoc(IndexName);
 }
示例#16
0
 static AuthRepository()
 {
     couchClient = new CouchClient("tcloud1.bonastoco.com", 5984, "admin", "S31panas", false, AuthenticationType.Basic);
 }
示例#17
0
 public void Setup()
 {
     var connection = new CouchConnection()
     {
         Username = username,
         Password = password,
         AuthenticationType = AuthenticationType.Cookie,
         DbType = DbType.CouchDb,
         DatabaseName = baseDatabase
     };
     connection.ConfigureBaseUri(host, port, false);
     client = new CouchClient(connection);
     if (!client.HasDatabase(baseDatabase))
     {
         client.CreateDatabase(baseDatabase);
     }
     if (!client.HasDatabase(replicateDatabase))
     {
         client.CreateDatabase(replicateDatabase);
     }
 }
示例#18
0
        private static CouchDatabase GetDatabase(string library)
        {
            CouchClient client = new CouchClient();
            CouchDatabase db = null;
            if (!client.HasDatabase(library))
            {
                client.CreateDatabase(library);
                JObject annotationViewsJson = JObject.Parse(File.ReadAllText(_annotationViewsFile));
                JObject annotationDesignDoc = new JObject();
                annotationDesignDoc["language"] = "javascript";
                annotationDesignDoc["views"] = annotationViewsJson;

                JObject screenshotViewsJson = JObject.Parse(File.ReadAllText(_screenshotViewsFile));
                JObject screenshotDesignDoc = new JObject();
                screenshotDesignDoc["language"] = "javascript";
                screenshotDesignDoc["views"] = screenshotViewsJson;

                
                db = client.GetDatabase(library);

                Document aView = new Document(annotationDesignDoc);
                aView.Id = "_design/annotations";
                

                Document sView = new Document(screenshotDesignDoc);
                sView.Id = "_design/screenshots";


                db.CreateDocument(aView);
                db.CreateDocument(sView);
            }

            db = client.GetDatabase(library);

            return db;
        }