Commits

Kevi...@ccitec.com)  committed 18d246b

BsonConsole updates to enhance usability.

  • Participants
  • Parent commits a6a55b3

Comments (0)

Files changed (6)

File BsonSql.Console/BsonSql.Console.csproj

     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="frmConsole2.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="frmConsole2.Designer.cs">
+      <DependentUpon>frmConsole2.cs</DependentUpon>
+    </Compile>
     <Compile Include="frmConsole.cs">
       <SubType>Form</SubType>
     </Compile>
     <Compile Include="SelectableTextBox.cs">
       <SubType>Component</SubType>
     </Compile>
+    <EmbeddedResource Include="frmConsole2.resx">
+      <DependentUpon>frmConsole2.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="frmConsole.resx">
       <DependentUpon>frmConsole.cs</DependentUpon>
     </EmbeddedResource>

File BsonSql.Console/Program.cs

 		{
 			Application.EnableVisualStyles();
 			Application.SetCompatibleTextRenderingDefault(false);
-			Application.Run(new frmConsole());
+			Application.Run(new frmConsole2());
 		}
 	}
 }

File BsonSql.Console/frmConsole.cs

 		{
 			txtResponse.Text = string.Empty;
 
-			if (txtServer.Text.Trim().Length == 0)
-			{
-				MessageBox.Show("Enter a connection string first please");
-				return;
-			}
+            if (button1.Text == "connect")
+            {
+                if (txtServer.Text.Trim().Length == 0)
+                {
+                    MessageBox.Show("Enter a connection string first please");
+                    return;
+                }
 
-			txtResponse.Text = "connecting....";
+                txtResponse.Text = "connecting....";
 
-			try
-			{
-				_server = BsonSqlServer.Connect(txtServer.Text.Trim());
-				txtResponse.Text = "connected";
-			}
-			catch (System.Exception ex)
-			{
-				txtResponse.Text = ex.Message + Environment.NewLine + ex.StackTrace;
-			}
+                try
+                {
+                    _server = BsonSqlServer.Connect(txtServer.Text.Trim());
+                    txtResponse.Text = "connected";
+                    button1.Text = "disconnect";
+                }
+                catch (System.Exception ex)
+                {
+                    txtResponse.Text = ex.Message + Environment.NewLine + ex.StackTrace;
+                }
+            }
+            else if (button1.Text == "disconnect")
+            {
+                try
+                {
+                    _server = null;
+                }
+                finally
+                {
+                    button1.Text = "connect";
+                }
+            }
+            
 		}
 
 		private void button2_Click(object sender, EventArgs e)
 		{
+            //force clearing if response window before command execution
+            txtResponse.Text = string.Empty;
+            this.Refresh();
+
 			if (_server == null || _server.ActiveHost == null)
 			{
 				MessageBox.Show("not connected to a server yet");
 				return;
 			}
 
-			txtResponse.Text = string.Empty;
-
 			try
 			{
 				BsonDocument doc = BsonSerializer.Deserialize(request, typeof(BsonDocument)) as BsonDocument;

File BsonSql.Console/frmConsole2.Designer.cs

+namespace BsonSql.Console
+{
+	partial class frmConsole2
+	{
+		/// <summary>
+		/// Required designer variable.
+		/// </summary>
+		private System.ComponentModel.IContainer components = null;
+
+		/// <summary>
+		/// Clean up any resources being used.
+		/// </summary>
+		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+		protected override void Dispose(bool disposing)
+		{
+			if (disposing && (components != null))
+			{
+				components.Dispose();
+			}
+			base.Dispose(disposing);
+		}
+
+		#region Windows Form Designer generated code
+
+		/// <summary>
+		/// Required method for Designer support - do not modify
+		/// the contents of this method with the code editor.
+		/// </summary>
+		private void InitializeComponent()
+		{
+            this.txtServer = new System.Windows.Forms.TextBox();
+            this.txtData = new BsonSql.Console.SelectableTextBox();
+            this.lblServer = new System.Windows.Forms.Label();
+            this.lblData = new System.Windows.Forms.Label();
+            this.btnConnect = new System.Windows.Forms.Button();
+            this.button2 = new System.Windows.Forms.Button();
+            this.cbAction = new System.Windows.Forms.ComboBox();
+            this.lblAction = new System.Windows.Forms.Label();
+            this.cbDomain = new System.Windows.Forms.ComboBox();
+            this.cbCollection = new System.Windows.Forms.ComboBox();
+            this.lblDomain = new System.Windows.Forms.Label();
+            this.lblCollection = new System.Windows.Forms.Label();
+            this.panel1 = new System.Windows.Forms.Panel();
+            this.txtId = new System.Windows.Forms.TextBox();
+            this.lblId = new System.Windows.Forms.Label();
+            this.tabs = new System.Windows.Forms.TabControl();
+            this.tpCollection = new System.Windows.Forms.TabPage();
+            this.dgvCollection = new System.Windows.Forms.DataGridView();
+            this.tpItem = new System.Windows.Forms.TabPage();
+            this.gbOptions = new System.Windows.Forms.GroupBox();
+            this.txtResult = new BsonSql.Console.SelectableTextBox();
+            this.panel1.SuspendLayout();
+            this.tabs.SuspendLayout();
+            this.tpCollection.SuspendLayout();
+            ((System.ComponentModel.ISupportInitialize)(this.dgvCollection)).BeginInit();
+            this.tpItem.SuspendLayout();
+            this.gbOptions.SuspendLayout();
+            this.SuspendLayout();
+            // 
+            // txtServer
+            // 
+            this.txtServer.Location = new System.Drawing.Point(146, 6);
+            this.txtServer.Name = "txtServer";
+            this.txtServer.Size = new System.Drawing.Size(289, 20);
+            this.txtServer.TabIndex = 0;
+            this.txtServer.Text = "http://localhost:1972";
+            // 
+            // txtData
+            // 
+            this.txtData.AcceptsTab = true;
+            this.txtData.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
+            this.txtData.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+            this.txtData.ImeMode = System.Windows.Forms.ImeMode.Off;
+            this.txtData.Location = new System.Drawing.Point(45, 72);
+            this.txtData.MaxLength = 2000000;
+            this.txtData.Multiline = true;
+            this.txtData.Name = "txtData";
+            this.txtData.ScrollBars = System.Windows.Forms.ScrollBars.Both;
+            this.txtData.Size = new System.Drawing.Size(430, 103);
+            this.txtData.TabIndex = 1;
+            // 
+            // lblServer
+            // 
+            this.lblServer.AutoSize = true;
+            this.lblServer.Location = new System.Drawing.Point(12, 9);
+            this.lblServer.Name = "lblServer";
+            this.lblServer.Size = new System.Drawing.Size(128, 13);
+            this.lblServer.TabIndex = 3;
+            this.lblServer.Text = "Server Connection String:";
+            // 
+            // lblData
+            // 
+            this.lblData.AutoSize = true;
+            this.lblData.Location = new System.Drawing.Point(9, 75);
+            this.lblData.Name = "lblData";
+            this.lblData.Size = new System.Drawing.Size(30, 13);
+            this.lblData.TabIndex = 4;
+            this.lblData.Text = "Data";
+            // 
+            // btnConnect
+            // 
+            this.btnConnect.Location = new System.Drawing.Point(441, 4);
+            this.btnConnect.Name = "btnConnect";
+            this.btnConnect.Size = new System.Drawing.Size(75, 23);
+            this.btnConnect.TabIndex = 6;
+            this.btnConnect.Text = "connect";
+            this.btnConnect.UseVisualStyleBackColor = true;
+            this.btnConnect.Click += new System.EventHandler(this.button1_Click);
+            // 
+            // button2
+            // 
+            this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+            this.button2.Location = new System.Drawing.Point(400, 181);
+            this.button2.Name = "button2";
+            this.button2.Size = new System.Drawing.Size(75, 23);
+            this.button2.TabIndex = 7;
+            this.button2.Text = "Exectue";
+            this.button2.UseVisualStyleBackColor = true;
+            this.button2.Click += new System.EventHandler(this.itemExecute_Click);
+            // 
+            // cbAction
+            // 
+            this.cbAction.FormattingEnabled = true;
+            this.cbAction.Items.AddRange(new object[] {
+            "driver.showConfig",
+            "delete",
+            "update",
+            "lookup",
+            "index.drop"});
+            this.cbAction.Location = new System.Drawing.Point(45, 19);
+            this.cbAction.Name = "cbAction";
+            this.cbAction.Size = new System.Drawing.Size(121, 21);
+            this.cbAction.TabIndex = 8;
+            // 
+            // lblAction
+            // 
+            this.lblAction.AutoSize = true;
+            this.lblAction.Location = new System.Drawing.Point(6, 22);
+            this.lblAction.Name = "lblAction";
+            this.lblAction.Size = new System.Drawing.Size(37, 13);
+            this.lblAction.TabIndex = 4;
+            this.lblAction.Text = "Action";
+            // 
+            // cbDomain
+            // 
+            this.cbDomain.FormattingEnabled = true;
+            this.cbDomain.Location = new System.Drawing.Point(10, 23);
+            this.cbDomain.Name = "cbDomain";
+            this.cbDomain.Size = new System.Drawing.Size(121, 21);
+            this.cbDomain.TabIndex = 8;
+            // 
+            // cbCollection
+            // 
+            this.cbCollection.FormattingEnabled = true;
+            this.cbCollection.Location = new System.Drawing.Point(144, 23);
+            this.cbCollection.Name = "cbCollection";
+            this.cbCollection.Size = new System.Drawing.Size(121, 21);
+            this.cbCollection.TabIndex = 8;
+            // 
+            // lblDomain
+            // 
+            this.lblDomain.AutoSize = true;
+            this.lblDomain.Location = new System.Drawing.Point(7, 7);
+            this.lblDomain.Name = "lblDomain";
+            this.lblDomain.Size = new System.Drawing.Size(43, 13);
+            this.lblDomain.TabIndex = 4;
+            this.lblDomain.Text = "Domain";
+            // 
+            // lblCollection
+            // 
+            this.lblCollection.AutoSize = true;
+            this.lblCollection.Location = new System.Drawing.Point(141, 7);
+            this.lblCollection.Name = "lblCollection";
+            this.lblCollection.Size = new System.Drawing.Size(53, 13);
+            this.lblCollection.TabIndex = 4;
+            this.lblCollection.Text = "Collection";
+            // 
+            // panel1
+            // 
+            this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
+            | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
+            this.panel1.Controls.Add(this.cbDomain);
+            this.panel1.Controls.Add(this.cbCollection);
+            this.panel1.Controls.Add(this.lblDomain);
+            this.panel1.Controls.Add(this.lblCollection);
+            this.panel1.Location = new System.Drawing.Point(12, 33);
+            this.panel1.Name = "panel1";
+            this.panel1.Size = new System.Drawing.Size(504, 61);
+            this.panel1.TabIndex = 9;
+            // 
+            // txtId
+            // 
+            this.txtId.Location = new System.Drawing.Point(45, 46);
+            this.txtId.Name = "txtId";
+            this.txtId.Size = new System.Drawing.Size(279, 20);
+            this.txtId.TabIndex = 9;
+            // 
+            // lblId
+            // 
+            this.lblId.AutoSize = true;
+            this.lblId.Location = new System.Drawing.Point(23, 49);
+            this.lblId.Name = "lblId";
+            this.lblId.Size = new System.Drawing.Size(16, 13);
+            this.lblId.TabIndex = 4;
+            this.lblId.Text = "Id";
+            // 
+            // tabs
+            // 
+            this.tabs.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
+            | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
+            this.tabs.Controls.Add(this.tpCollection);
+            this.tabs.Controls.Add(this.tpItem);
+            this.tabs.Location = new System.Drawing.Point(12, 100);
+            this.tabs.Name = "tabs";
+            this.tabs.SelectedIndex = 0;
+            this.tabs.Size = new System.Drawing.Size(504, 520);
+            this.tabs.TabIndex = 10;
+            // 
+            // tpCollection
+            // 
+            this.tpCollection.Controls.Add(this.dgvCollection);
+            this.tpCollection.Location = new System.Drawing.Point(4, 22);
+            this.tpCollection.Name = "tpCollection";
+            this.tpCollection.Padding = new System.Windows.Forms.Padding(3);
+            this.tpCollection.Size = new System.Drawing.Size(496, 494);
+            this.tpCollection.TabIndex = 1;
+            this.tpCollection.Text = "Collection";
+            this.tpCollection.UseVisualStyleBackColor = true;
+            // 
+            // dgvCollection
+            // 
+            this.dgvCollection.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+            this.dgvCollection.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.dgvCollection.Location = new System.Drawing.Point(3, 3);
+            this.dgvCollection.Name = "dgvCollection";
+            this.dgvCollection.Size = new System.Drawing.Size(490, 488);
+            this.dgvCollection.TabIndex = 0;
+            // 
+            // tpItem
+            // 
+            this.tpItem.Controls.Add(this.gbOptions);
+            this.tpItem.Controls.Add(this.txtResult);
+            this.tpItem.Location = new System.Drawing.Point(4, 22);
+            this.tpItem.Name = "tpItem";
+            this.tpItem.Padding = new System.Windows.Forms.Padding(3);
+            this.tpItem.Size = new System.Drawing.Size(496, 494);
+            this.tpItem.TabIndex = 0;
+            this.tpItem.Text = "Item";
+            this.tpItem.UseVisualStyleBackColor = true;
+            // 
+            // gbOptions
+            // 
+            this.gbOptions.Controls.Add(this.button2);
+            this.gbOptions.Controls.Add(this.txtId);
+            this.gbOptions.Controls.Add(this.lblAction);
+            this.gbOptions.Controls.Add(this.cbAction);
+            this.gbOptions.Controls.Add(this.lblData);
+            this.gbOptions.Controls.Add(this.lblId);
+            this.gbOptions.Controls.Add(this.txtData);
+            this.gbOptions.Location = new System.Drawing.Point(7, 7);
+            this.gbOptions.Name = "gbOptions";
+            this.gbOptions.Size = new System.Drawing.Size(481, 211);
+            this.gbOptions.TabIndex = 0;
+            this.gbOptions.TabStop = false;
+            this.gbOptions.Text = "Options";
+            // 
+            // txtResult
+            // 
+            this.txtResult.AcceptsTab = true;
+            this.txtResult.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
+            this.txtResult.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+            this.txtResult.ImeMode = System.Windows.Forms.ImeMode.Off;
+            this.txtResult.Location = new System.Drawing.Point(7, 224);
+            this.txtResult.MaxLength = 2000000;
+            this.txtResult.Multiline = true;
+            this.txtResult.Name = "txtResult";
+            this.txtResult.ScrollBars = System.Windows.Forms.ScrollBars.Both;
+            this.txtResult.Size = new System.Drawing.Size(481, 264);
+            this.txtResult.TabIndex = 1;
+            // 
+            // frmConsole2
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(532, 632);
+            this.Controls.Add(this.tabs);
+            this.Controls.Add(this.panel1);
+            this.Controls.Add(this.btnConnect);
+            this.Controls.Add(this.lblServer);
+            this.Controls.Add(this.txtServer);
+            this.Name = "frmConsole2";
+            this.Text = "BsonSqlServer Console";
+            this.panel1.ResumeLayout(false);
+            this.panel1.PerformLayout();
+            this.tabs.ResumeLayout(false);
+            this.tpCollection.ResumeLayout(false);
+            ((System.ComponentModel.ISupportInitialize)(this.dgvCollection)).EndInit();
+            this.tpItem.ResumeLayout(false);
+            this.tpItem.PerformLayout();
+            this.gbOptions.ResumeLayout(false);
+            this.gbOptions.PerformLayout();
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+		}
+
+		#endregion
+
+		private System.Windows.Forms.TextBox txtServer;
+        private SelectableTextBox txtData;
+		private System.Windows.Forms.Label lblServer;
+        private System.Windows.Forms.Label lblData;
+		private System.Windows.Forms.Button btnConnect;
+		private System.Windows.Forms.Button button2;
+        private System.Windows.Forms.ComboBox cbAction;
+        private System.Windows.Forms.Label lblAction;
+        private System.Windows.Forms.ComboBox cbDomain;
+        private System.Windows.Forms.ComboBox cbCollection;
+        private System.Windows.Forms.Label lblDomain;
+        private System.Windows.Forms.Label lblCollection;
+        private System.Windows.Forms.Panel panel1;
+        private System.Windows.Forms.TextBox txtId;
+        private System.Windows.Forms.Label lblId;
+        private System.Windows.Forms.TabControl tabs;
+        private System.Windows.Forms.TabPage tpItem;
+        private System.Windows.Forms.GroupBox gbOptions;
+        private SelectableTextBox txtResult;
+        private System.Windows.Forms.TabPage tpCollection;
+        private System.Windows.Forms.DataGridView dgvCollection;
+	}
+}

File BsonSql.Console/frmConsole2.cs

+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Windows.Forms;
+using BsonSql.Driver;
+using MongoDB.Bson;
+using MongoDB.Bson.Serialization;
+using MongoDB.Bson.IO;
+
+namespace BsonSql.Console
+{
+    public partial class frmConsole2 : Form
+    {
+        private BsonSqlServer _server;
+
+        public frmConsole2()
+        {
+            InitializeComponent();
+
+            cbDomain.SelectedIndexChanged += new EventHandler(cbDomain_SelectedIndexChanged);
+            cbCollection.SelectedIndexChanged += new EventHandler(cbCollection_SelectedIndexChanged);
+            dgvCollection.DataError += new DataGridViewDataErrorEventHandler(dgvCollection_DataError);
+            dgvCollection.CellDoubleClick += new DataGridViewCellEventHandler(dgvCollection_CellDoubleClick);
+
+        }
+
+        void dgvCollection_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
+        {
+            DataGridViewRow row = dgvCollection.Rows[e.RowIndex];
+            string id = row.Cells["_id"].Value.ToString();
+            Guid selectedId = Guid.Parse(id);
+
+        }
+
+        void dgvCollection_DataError(object sender, DataGridViewDataErrorEventArgs e)
+        {
+            //throw new NotImplementedException();
+        }
+
+
+        private void button1_Click(object sender, EventArgs e)
+        {
+            txtResult.Text = string.Empty;
+
+            if (btnConnect.Text == "connect")
+            {
+                if (txtServer.Text.Trim().Length == 0)
+                {
+                    MessageBox.Show("Enter a connection string first please");
+                    return;
+                }
+
+                txtResult.Text = "connecting....";
+
+                try
+                {
+                    _server = BsonSqlServer.Connect(txtServer.Text.Trim());
+                    txtResult.Text = "connected";
+                    btnConnect.Text = "disconnect";
+                    OnServerConnected();
+                }
+                catch (System.Exception ex)
+                {
+                    txtResult.Text = ex.Message + Environment.NewLine + ex.StackTrace;
+                }
+            }
+            else if (btnConnect.Text == "disconnect")
+            {
+                try
+                {
+                    _server = null;
+                }
+                finally
+                {
+                    btnConnect.Text = "connect";
+                }
+            }
+
+        }
+
+        private void OnServerConnected()
+        {
+            cbDomain.DataSource = null;
+            cbCollection.DataSource = null;
+
+            BsonDocument config = _server.GetActiveConfiguration();
+            cbDomain.DisplayMember = "Name";
+            BsonArray domains = (config.Contains("Domains")) ? config["Domains"].AsBsonArray : null;
+            if (domains != null)
+            {
+                foreach (BsonDocument doc in domains)
+                {
+                    BsonDomain domain = new BsonDomain(doc);
+                    cbDomain.Items.Add(domain);
+                }
+            }
+        }
+
+        void cbDomain_SelectedIndexChanged(object sender, EventArgs e)
+        {
+            cbCollection.DataSource = null;
+            BsonDomain domain = cbDomain.SelectedItem as BsonDomain;
+            if (domain != null)
+            {
+                cbCollection.DisplayMember = "Name";
+                cbCollection.DataSource = domain.Collections;
+            }
+        }
+
+        void cbCollection_SelectedIndexChanged(object sender, EventArgs e)
+        {
+            //setup datagridview 
+            dgvCollection.ReadOnly = true;
+            //dgvCollection.Rows.Clear();
+            //dgvCollection.AutoGenerateColumns = false;
+            //dgvCollection.Columns.Clear();
+            dgvCollection.AllowUserToDeleteRows = false;
+            dgvCollection.AllowUserToAddRows = false;
+            dgvCollection.AllowDrop = false;
+            dgvCollection.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
+
+            BsonCollection collection = cbCollection.SelectedItem as BsonCollection;
+
+            if (cbCollection.SelectedItem != null)
+            {
+                BsonSqlCollection bsqlCollection = GetBsonSqlCollection(collection);
+
+                var query = Driver.Builders.QueryBuilder.Where(
+                Driver.Builders.WhereClauseBuilder.CreateBound("SchemaVersion", Driver.Builders.Enums.Comparison.GreaterOrEquals));
+
+                var bsqlCursor = bsqlCollection.FindAs<BsonDocument>(
+                    query.Bind(new BsonDocument() 
+                        { 
+                            { "SchemaVersion", 0 }
+                        }));
+
+                DataSet ds = new DataSet(collection.Domain.Name);
+                DataTable dt = new DataTable(collection.Name);
+                foreach (string fieldName in collection.IndexedFields)
+                {
+                    DataColumn dc = new DataColumn(fieldName);
+                    dt.Columns.Add(dc);
+
+                }
+
+                foreach (BsonDocument d in bsqlCursor)
+                {
+                    DataRow row = dt.NewRow();
+
+                    foreach (string fieldName in collection.IndexedFields)
+                    {
+                        if (d.Contains(fieldName))
+                        {
+                            row[fieldName] = (fieldName == "_id") ? d[fieldName].AsGuid.ToString() : d[fieldName].ToString();
+                        }
+                        else
+                        {
+                            row[fieldName] = String.Empty;
+                        }
+                    }
+
+                    dt.Rows.Add(row);
+                }
+
+                ds.Tables.Add(dt);
+
+                dgvCollection.DataSource = dt;
+                //dgvCollection.DataMember = ;
+            }
+        }
+
+        private BsonSqlCollection GetBsonSqlCollection()
+        {
+            BsonSqlCollection bsqlCollection = null;
+            BsonCollection collection = cbCollection.SelectedItem as BsonCollection;
+            if (cbCollection.SelectedItem != null)
+            {
+                bsqlCollection = GetBsonSqlCollection(collection);
+            }
+
+            return bsqlCollection;
+        }
+
+        private BsonSqlCollection GetBsonSqlCollection(BsonCollection collection)
+        {
+            BsonSqlCollection bsqlCollection = null;
+            if (collection != null)
+            {
+                bsqlCollection = _server.GetDomain(collection.Domain.Name).GetCollection(collection.Name);
+            }
+            return bsqlCollection;
+        }
+
+        private class BsonDomain
+        {
+            BsonDocument _doc;
+
+            public BsonDocument BsonDocument { get { return _doc; } }
+
+            public BsonDomain(BsonDocument domain)
+            {
+                _doc = domain;
+            }
+
+            public string Name
+            {
+                get { return (_doc.Contains("DomainId")) ? _doc["DomainId"].AsString : String.Empty; }
+                set { _doc["DomainId"] = value; }
+            }
+
+            public List<BsonCollection> Collections
+            {
+                get
+                {
+                    List<BsonCollection> collections = new List<BsonCollection>();
+                    if (_doc.Contains("Collections"))
+                    {
+                        BsonArray array = _doc["Collections"].AsBsonArray;
+                        foreach (BsonDocument collection in array)
+                        {
+                            collections.Add(new BsonCollection(this, collection));
+                        }
+                    }
+
+                    return collections;
+                }
+            }
+        }
+
+        private class BsonCollection
+        {
+            BsonDocument _doc;
+            List<string> _indexedFields = new List<string>();
+            public BsonDocument BsonDocument { get { return _doc; } }
+
+            public BsonDomain Domain { get; set; }
+            public BsonCollection(BsonDomain domain, BsonDocument collection)
+            {
+                Domain = domain;
+                _doc = collection;
+            }
+
+            public string Name
+            {
+                get { return (_doc.Contains("CollectionName")) ? _doc["CollectionName"].AsString : String.Empty; }
+                set { _doc["CollectionName"] = value; }
+            }
+
+
+            public List<string> IndexedFields
+            {
+                get
+                {
+                    if (_indexedFields.Count == 0)
+                    {
+                        _indexedFields.Add("_id");   //default indexed field/primary key
+
+                        if (_doc.Contains("Indexes"))
+                        {
+                            BsonArray indexArray = _doc["Indexes"].AsBsonArray;
+                            foreach (BsonDocument indexDef in indexArray)
+                            {
+                                if (indexDef.Contains("Keys"))
+                                {
+                                    BsonArray indexKeys = indexDef["Keys"].AsBsonArray;
+                                    foreach (BsonDocument key in indexKeys)
+                                    {
+                                        if (key.Contains("FieldName"))
+                                        {
+                                            _indexedFields.Add(key["FieldName"].AsString);
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+
+                    return _indexedFields;
+                }
+            }
+        }
+
+        private void itemExecute_Click(object sender, EventArgs e)
+        {
+            ItemExecute();
+        }
+
+        private void ItemExecute()
+        {
+            //force clearing if response window before command execution
+            txtResult.Text = string.Empty;
+            this.Refresh();
+
+            if (_server == null || _server.ActiveHost == null)
+            {
+                MessageBox.Show("not connected to a server yet");
+                return;
+            }
+
+            //string request = txtData.Text.Trim();
+            //if (request.Length == 0)
+            //{
+            //    MessageBox.Show("enter a request first");
+            //    return;
+            //}
+
+            //validate collection selected
+            BsonCollection collection = cbCollection.SelectedItem as BsonCollection;
+            if (collection == null)
+            {
+                MessageBox.Show("Select a valid domain and collection");
+                return;
+            }
+
+            string action = cbAction.SelectedValue as string;
+            if (String.IsNullOrEmpty(action))
+            {
+                txtResult.Text = "Select a valid action";
+                return;
+            }
+
+            try
+            {
+                //get bson sql collection
+                BsonSqlCollection bsqlCollection = GetBsonSqlCollection();
+
+                //BsonDocument doc = BsonSerializer.Deserialize(request, typeof(BsonDocument)) as BsonDocument;
+                //if (!doc.Contains("action") || !doc["action"].IsString)
+                //{
+                //    txtResult.Text = "missing action property";
+                //    return;
+                //}
+
+                ////string action = doc["action"].AsString;
+                JsonWriterSettings writerSettings = new JsonWriterSettings();
+                writerSettings.Indent = true;
+                writerSettings.NewLineChars = Environment.NewLine;
+                writerSettings.IndentChars = " ";
+
+                //some actions will just spit stuff back
+                switch (action)
+                {
+                    case "driver.showConfig":
+                        txtResult.Text = CleanJson(_server.GetActiveConfiguration().ToJson(writerSettings));
+                        return;
+                    case "delete":
+                    case "update":
+                    case "lookup":
+                    case "index.drop":
+                        ProcessCollectionAction(bsqlCollection, action, writerSettings);
+                        return;
+
+                }
+
+                //if (!doc.Contains("request") || !doc["request"].IsBsonDocument)
+                //{
+                //    txtResult.Text = "missing request property, or is not correct type";
+                //    return;
+                //}
+
+                //bool updatedConfiguration;
+                //BsonDocument docResponse = _server.SubmitRequest(doc["action"].AsString, doc["request"].AsBsonDocument, out updatedConfiguration);
+                //if (updatedConfiguration)
+                //    txtResult.Text = "*** updated config ***" + Environment.NewLine + Environment.NewLine;
+                //txtResult.Text += CleanJson(docResponse.ToJson(writerSettings));
+            }
+            catch (System.Exception ex)
+            {
+                txtResult.Text = ex.Message + Environment.NewLine + ex.StackTrace;
+            }
+        }
+
+        private void ProcessCollectionAction(BsonSqlCollection collection, string action, JsonWriterSettings writerSettings)
+        {
+            //BsonSqlCollection collection = _server.GetDomain(doc["domain"].AsString).GetCollection(doc["collection"].AsString);
+            BsonDocument docResponse = null;
+
+            switch (action)
+            {
+                case "lookup":
+                    docResponse = collection.FindOneByIdAs<BsonDocument>(new Guid(txtId.Text));
+                    break;
+                case "update":
+                    BsonDocument updateDoc = BsonDocument.Parse(txtData.Text);
+                    collection.Upsert(updateDoc);
+                    break;
+                case "delete":
+                    collection.RemoveById(new Guid(txtId.Text));
+                    break;
+                case "index.drop":
+                    collection.DropIndex(txtId.Text);
+                    break;
+            }
+
+            if (docResponse != null)
+                txtResult.Text = CleanJson(docResponse.ToJson(writerSettings));
+            else
+                txtResult.Text = "*** no return value ***";
+        }
+
+        private static Regex _pattern = new Regex("BinData\\(3, \".*\"\\)");
+        private string CleanJson(string json)
+        {
+            if (json == null)
+                return null;
+
+            MatchCollection match = _pattern.Matches(json);
+            foreach (Match m in match)
+            {
+                string byteString = m.Value.Substring(m.Value.IndexOf("3,") + 4);
+                byteString = byteString.Substring(0, byteString.Length - 2);
+                Guid id = new Guid(Convert.FromBase64String(byteString));
+                json = json.Replace(m.Value, "\"" + id.ToString() + "\"");
+            }
+
+            return json;
+        }
+
+        private void LoadItemTab(Guid id)
+        {
+            tabs.SelectedTab = tpItem;
+            cbAction.SelectedItem = "lookup";
+            txtId.Text = id.ToString();
+
+        }
+    }
+}

File BsonSql.Console/frmConsole2.resx

+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>