예제 #1
0
        /// <summary>
        ///     OK
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmdOK_Click(object sender, EventArgs e)
        {
            //不支持中文 JIRA ticket is created : SERVER-4412
            //SERVER-4412已经在2013/03解决了
            //collection names are limited to 121 bytes after converting to UTF-8.
            if (txtCollectionName.Text == string.Empty)
            {
                return;
            }
            CollectionName = txtCollectionName.Text.Trim();
            try
            {
                string errMessage;
                RuntimeMongoDbContext.GetCurrentDataBase().IsCollectionNameValid(txtCollectionName.Text, out errMessage);
                if (errMessage != null)
                {
                    MyMessageBox.ShowMessage("Create Collection", "Argument Exception", errMessage, true);
                    return;
                }
                if (chkAdvance.Checked)
                {
                    var option = new CollectionOptionsBuilder();

                    if (chkIsCapped.Checked)
                    {
                        if (numMaxSize.Value == 0 || numMaxDocument.Value == 0)
                        {
                            MyMessageBox.ShowMessage("Create Collection", "Argument Exception", "Please Input MaxSize Or MaxDocument When IsCapped", true);
                            return;
                        }
                        option.SetCapped(chkIsCapped.Checked);
                        if (numMaxSize.Value != 0)
                        {
                            option.SetMaxSize((long)numMaxSize.Value);
                        }
                        if (numMaxDocument.Value != 0)
                        {
                            option.SetMaxDocuments((long)numMaxDocument.Value);
                        }
                    }

                    //CappedCollection Default is AutoIndexId After MongoDB 2.2.2
                    option.SetAutoIndexId(chkIsAutoIndexId.Checked);

                    if (chkValidation.Checked)
                    {
                        //Start From MongoDB 3.2.0
                        BsonDocument  query    = BsonSerializer.Deserialize <BsonDocument>(txtValidation.Text);
                        QueryDocument queryDoc = new QueryDocument(query);
                        option.SetValidator(queryDoc);
                        //Validation Level
                        if (radLevel_off.Checked)
                        {
                            option.SetValidationLevel(DocumentValidationLevel.Off);
                        }
                        if (radLevel_strict.Checked)
                        {
                            option.SetValidationLevel(DocumentValidationLevel.Strict);
                        }
                        if (radLevel_moderate.Checked)
                        {
                            option.SetValidationLevel(DocumentValidationLevel.Moderate);
                        }
                        //Validation Action
                        if (radAction_error.Checked)
                        {
                            option.SetValidationAction(DocumentValidationAction.Error);
                        }
                        if (radAction_warn.Checked)
                        {
                            option.SetValidationAction(DocumentValidationAction.Warn);
                        }
                    }

                    Result = Operater.CreateCollectionWithOptions(StrSvrPathWithTag, txtCollectionName.Text,
                                                                  option, RuntimeMongoDbContext.GetCurrentDataBase());
                }
                else
                {
                    Result = Operater.CreateCollection(StrSvrPathWithTag, txtCollectionName.Text,
                                                       RuntimeMongoDbContext.GetCurrentDataBase());
                }
                Close();
            }
            catch (ArgumentException ex)
            {
                Utility.ExceptionDeal(ex, "Create MongoDatabase", "Argument Exception");
                Result = false;
            }
        }