public void LoadResults(QueryResult queryResult, MongoCollectionInfo mongoCollectionInfo)
        {
            AddGridTabpage(queryResult);
            AddTreeTabpage(queryResult, mongoCollectionInfo);
            AddJsonTabpage(queryResult);

            tabControlResults.SelectedIndex = Settings.Instance.Preferences.DefaultResultsView;

            tabControlResults_SelectedIndexChanged(tabControlResults, null);
        }
        private TabPage AddTreeTabpage(QueryResult queryResult, MongoCollectionInfo mongoCollectionInfo)
        {
            var treeTabPage        = new TabPage("Tree View");
            var queryResultControl = new UserControlQueryResultsTree
            {
                Dock = DockStyle.Fill
            };

            queryResultControl.LoadResults(queryResult, mongoCollectionInfo);
            treeTabPage.Controls.Add(queryResultControl);
            tabControlResults.TabPages.Add(treeTabPage);

            return(treeTabPage);
        }
Пример #3
0
        private void CreateIndexJsonMode()
        {
            string indexJson = textBoxIndexJson.Text.Trim();

            if (string.IsNullOrWhiteSpace(indexJson))
            {
                throw new Exception("Enter index json.");
            }

            IndexKeysDocument keys = null;

            try
            {
                keys = BsonSerializer.Deserialize <IndexKeysDocument>(indexJson);
            }
            catch (Exception ex1)
            {
                throw new Exception($"Invalid index json.\r\n\r\n{ex1.Message}");
            }

            string optionJson            = textBoxIndexOptionsJson.Text.Trim();
            IndexOptionsDocument options = null;

            if (string.IsNullOrWhiteSpace(optionJson))
            {
                options = new IndexOptionsDocument();
            }
            else
            {
                try
                {
                    options = BsonSerializer.Deserialize <IndexOptionsDocument>(optionJson);
                }
                catch (Exception ex1)
                {
                    throw new Exception($"Invalid options json.\r\n\r\n{ex1.Message}");
                }
            }

            if (!options.Contains("name"))
            {
                string indexName = txtBoxIndexName.Text;
                if (string.IsNullOrWhiteSpace(indexName))
                {
                    throw new Exception("Please enter an index name.");
                }

                options.Add("name", indexName);
            }

            if (!options.Contains("unique"))
            {
                options.Add("unique", checkBoxUnique.Checked);
            }
            if (!options.Contains("dropDups") && checkBoxUnique.Checked)
            {
                options.Add("dropDups", checkBoxDropDups.Checked);
            }
            if (!options.Contains("background"))
            {
                options.Add("background", checkBoxBackground.Checked);
            }
            if (!options.Contains("sparse"))
            {
                options.Add("sparse", checkBoxSparse.Checked);
            }

            var mongoCollection = MongoCollectionInfo.GetMongoCollection();
            WriteConcernResult writeConcernResult = mongoCollection.CreateIndex(keys, options);

            if (writeConcernResult.HasLastErrorMessage)
            {
                throw new Exception(writeConcernResult.LastErrorMessage);
            }
        }
Пример #4
0
        private void CreateIndexBasicMode()
        {
            string indexName = txtBoxIndexName.Text;

            if (string.IsNullOrWhiteSpace(indexName))
            {
                throw new Exception("Please enter an index name.");
            }

            var mongoCollection = MongoCollectionInfo.GetMongoCollection();
            var indexes         = mongoCollection.GetIndexes();

            if (indexes != null && indexes.Any())
            {
                if (indexes.ToList().Exists(i => i.Name == indexName))
                {
                    throw new Exception("An index with that name already exists.");
                }
            }

            var keys = GetChoosenKeys();

            if (!keys.Any())
            {
                throw new Exception("You must choose at least one key.");
            }

            var keyBuilder = new IndexKeysBuilder();

            foreach (var key in keys)
            {
                if (key.SortType == 1)
                {
                    keyBuilder = keyBuilder.Ascending(key.Key);
                }
                else if (key.SortType == -1)
                {
                    keyBuilder = keyBuilder.Descending(key.Key);
                }
                else if (key.SortType == 2)
                {
                    keyBuilder = keyBuilder.GeoSpatial(key.Key);
                }
                else if (key.SortType == 3)
                {
                    keyBuilder = keyBuilder.GeoSpatialHaystack(key.Key);
                }
            }
            var optionBuilder = new IndexOptionsBuilder();

            optionBuilder.SetUnique(checkBoxUnique.Checked);
            optionBuilder.SetBackground(checkBoxBackground.Checked);
            optionBuilder.SetDropDups(checkBoxUnique.Checked && checkBoxDropDups.Checked);
            optionBuilder.SetSparse(checkBoxSparse.Checked);
            optionBuilder.SetName(indexName);

            var writeConcernResult = mongoCollection.CreateIndex(keyBuilder, optionBuilder);

            if (writeConcernResult.HasLastErrorMessage)
            {
                throw new Exception(writeConcernResult.LastErrorMessage);
            }
        }
Пример #5
0
 public CollectionNodeTag(MongoCollectionInfo col)
 {
     MongoCollectionInfo = col;
 }