Example #1
0
        public static void SetupCouchDb()
        {
            string connectionString = ConfigurationManager.ConnectionStrings["CouchDb"].ConnectionString;
            var uri = new Uri(connectionString);

            using (var s = new MyCouchServerClient(uri.Scheme + "://" + uri.Authority))
            {
                var dbName = uri.LocalPath.Substring(1);
                var karinsFilmerDb = s.Databases.PutAsync(dbName).Result;

                EnsureViewsAreUpToDate(karinsFilmerDb);
            }
        }
        /// <summary>
        /// Function in <see cref="LocalDB"/> to replicate the local DB to all other DBs in LAN. Sends a HTTP request. Database will handle replication afterwards.
        /// </summary>
        /// <param name="client">Target <see cref="MyCouchClient"/></param>
        /// <param name="DBName">Name of the database.</param>
        /// <param name="targetDBIP">The IP from the other Database</param>
        public static async void replicate(MyCouchServerClient client, string DBName, string targetDBIP)
        {
            //The Name of the Replication will be the Date, the SourceDBName is just the name from the localDBName
            //The targetDBIP must be a IP with the DBName at the end. e.g.: "test", "http://172.16.182.128/test"

            var request = new MyCouch.Requests.ReplicateDatabaseRequest(DateTime.Now.ToString(), DBName, targetDBIP)
            {
                Continuous = true,
            };

            MyCouch.Responses.ReplicationResponse response = await client.Replicator.ReplicateAsync(request);


        }
 public void ConfigureDB()
 {
     dbName = "todos";
     var settings = System.Environment.GetEnvironmentVariable("VCAP_SERVICES");
     if (settings == null)
     {
         Console.WriteLine("VCAP_SERVICES environment variable not set.");
     }
     var parsed = JObject.Parse(settings);
     if (parsed["cloudantNoSQLDB"] != null && parsed["cloudantNoSQLDB"][0] != null)
     {
         user = parsed["cloudantNoSQLDB"][0]["credentials"]["username"].ToString();
         password = parsed["cloudantNoSQLDB"][0]["credentials"]["password"].ToString();
         cloudantURL = parsed["cloudantNoSQLDB"][0]["credentials"]["url"].ToString();
         var uriBuilder = new MyCouchUriBuilder(cloudantURL).SetBasicCredentials(user, password);
         uri = uriBuilder.Build();
         db = new MyCouchServerClient(uriBuilder.Build());
     }
 }
Example #4
0
        public void ImportTestData()
        {
            // Remove the old database
            string connectionString = ConfigurationManager.ConnectionStrings["CouchDb"].ConnectionString;
            var uri = new Uri(connectionString);
            var dbName = uri.LocalPath.Substring(1);

            using (var s = new MyCouchServerClient(uri.Scheme + "://" + uri.Authority))
            {
                s.Databases.DeleteAsync(dbName).Wait();
            }

            // Create new database
            CouchConfig.SetupCouchDb();

            // Fill it with test data
            using (var c = new MyCouchStore(connectionString))
            {
                foreach (var testData in GetTestData())
                {
                    c.StoreAsync(testData).Wait();
                }
            }
        }