Exemple #1
0
        private void btnSaveSetting_Click(object sender, EventArgs e)
        {
            if (txtMongoDbConnectionString.Text.Length == 0)
            {
                MessageBox.Show("日志数据库的连接字符串不能为空。", this.FindForm().Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (txtLoginCookieName.Text.Length == 0)
            {
                MessageBox.Show("登录Cookie名称不能为空。", this.FindForm().Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (txtLoginRequestRaw.Text.Length == 0)
            {
                MessageBox.Show("登录请求文本不能为空。", this.FindForm().Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            try {
                // 检验输入的请求文本是否正确
                HttpOption option = HttpOption.FromRawText(txtLoginRequestRaw.Text);
                Uri        uri    = new Uri(option.Url);

                if (option.Data == null)
                {
                    throw new ArgumentException("没有登录操作需要的提交数据。");
                }
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message, this.FindForm().Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            RunTimeSettings settings = new RunTimeSettings();

            settings.MongoDbConnectionString = txtMongoDbConnectionString.Text;
            settings.LoginCookieName         = txtLoginCookieName.Text;
            settings.LoginRequestRaw         = txtLoginRequestRaw.Text;

            XmlHelper.XmlSerializeToFile(settings, "RunTimeSettings.config", Encoding.UTF8);

            MessageBox.Show("保存操作成功完成。", this.FindForm().Text, MessageBoxButtons.OK, MessageBoxIcon.Information);

            EventHandler <SaveSettingsEventArgs> eventHandler = this.SaveSettingButtonClick;

            if (eventHandler != null)
            {
                SaveSettingsEventArgs args = new SaveSettingsEventArgs {
                    NewSettings = settings
                };
                eventHandler(btnCancelSetting, args);
            }
        }
 private void SettingsControl1_SaveSettingButtonClick(object sender, SaveSettingsEventArgs e)
 {
     _runTimeSettings = e.NewSettings;
 }