private void importViewsToolStripMenuItem_Click(object sender, EventArgs e) { CouchDatabase targetDb = (CouchDatabase)_contextNode.Tag; if (folderBrowserDialog1.ShowDialog() != DialogResult.OK) { return; } foreach (var file in Directory.GetFiles(folderBrowserDialog1.SelectedPath)) { using (var reader = new StreamReader(File.OpenRead(file))) { var design = new GenericDesignDocument(); design.ReadJson((JObject)JToken.ReadFrom(new JsonTextReader(reader))); // need to make sure to overwrite the target if (targetDb.HasDocument(design.Id)) { design.Rev = targetDb.GetDocument(design.Id).Rev; } else { design.Rev = null; } design.Owner = targetDb; design.Synch(); } } }
private void extractViewsToolStripMenuItem_Click(object sender, EventArgs e) { CouchDatabase sourceDb = (CouchDatabase)_contextNode.Tag; if (folderBrowserDialog1.ShowDialog() != DialogResult.OK) { return; } foreach (var view in sourceDb.QueryAllDocuments().StartKey("_design").EndKey("_designZZZZZZZZZZZZZZZZZ").GetResult().RowDocuments()) { var design = sourceDb.GetDocument <GenericDesignDocument>(view.Key); using (var streamWriter = new StreamWriter(File.OpenWrite(Path.Combine(folderBrowserDialog1.SelectedPath, design.Id.Substring(8) + ".js")))) { var writer = new JsonTextWriter(streamWriter); writer.Indentation = 1; writer.IndentChar = '\t'; writer.Formatting = Formatting.Indented; writer.WriteStartObject(); design.WriteJson(writer); writer.WriteEndObject(); } } }
private void cloneViewsToolStripMenuItem_Click(object sender, EventArgs e) { CouchDatabase sourceDb = (CouchDatabase)_contextNode.Tag; using (var dialog = new dlgName("Specify Target", "Target Server/database")) { if (dialog.ShowDialog() != DialogResult.OK) { return; } var dbParts = dialog.EnteredName.Replace("//", "").Split('/'); var svr = CreateServer(dbParts[0].Split(':')); var targetDb = svr.GetDatabase(dbParts[1]); foreach (var view in sourceDb.QueryAllDocuments().StartKey("_design").EndKey("_designZZZZZZZZZZZZZZZZZ").GetResult().RowDocuments()) { var design = sourceDb.GetDocument <GenericDesignDocument>(view.Key); // need to make sure to overwrite the target if (targetDb.HasDocument(design.Id)) { design.Rev = targetDb.GetDocument(design.Id).Rev; } else { design.Rev = null; } design.Owner = targetDb; design.Synch(); } } }
/// <summary> /// Get's the user. /// </summary> /// <param name="userId"></param> /// <returns></returns> public Document GetUser(string userId) { var db = new CouchDatabase(baseUri, "_users", username, password, this.authType); userId = "org.couchdb.user:" + HttpUtility.UrlEncode(userId); return(db.GetDocument(userId)); }
/// <summary> /// Loads the database into the treeview, under the given parent. /// </summary> /// <param name="couchDatabase">The couch database.</param> /// <param name="parent">The parent.</param> private void LoadDatabase(CouchDatabase couchDatabase, TreeNode parent) { foreach (var view in couchDatabase.QueryAllDocuments().StartKey("_design").EndKey("_design0").GetResult().RowDocuments()) { var design = couchDatabase.GetDocument <GenericDesignDocument>(view.Key); design.Owner = couchDatabase; CreateDesignNode(design, parent); } }
/// <summary> /// Loads the database into the treeview, under the given parent. /// </summary> /// <param name="couchDatabase">The couch database.</param> /// <param name="parent">The parent.</param> private void LoadDatabase(CouchDatabase couchDatabase, TreeNode parent) { try { foreach (var view in couchDatabase.QueryAllDocuments().StartKey("_design").EndKey("_design0").GetResult().RowDocuments()) { var design = couchDatabase.GetDocument <GenericDesignDocument>(view.Key); design.Owner = couchDatabase; CreateDesignNode(design, parent); } } catch (Exception e) { MessageBox.Show(e.Message, "Error Loading Database", MessageBoxButtons.OK, MessageBoxIcon.Error); } }