Esempio n. 1
0
        /// <summary>
        /// 当鼠标点击修改按钮时发生。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnUpdate_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                AssertUtil.FormDataValidate("请输入合法的键。", () => { return(string.IsNullOrWhiteSpace(this.tbNewKey.Text.Trim())); });

                if (GlobalBusiness.RedisCaches[configId].Get(this.tbNewKey.Text.Trim(), this.index) != null)
                {
                    MessageBox.Show("已存在键。");
                    return;
                }
                GlobalBusiness.RedisCaches[configId].RenameKey(this.key, this.tbNewKey.Text.Trim(), this.index);
                this.OnUpdatedKey?.Invoke(this.tbNewKey.Text.Trim());

                this.Close();
            }
            catch (IllegalFormDataException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (RedisException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 当鼠标点击保存按钮时发生。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                AssertUtil.FormDataValidate("名称不能为空。", () => { return(string.IsNullOrWhiteSpace(this.tbConnName.Text)); });
                AssertUtil.FormDataValidate("地址不能为空。", () => { return(string.IsNullOrWhiteSpace(this.tbConnIP.Text)); });
                AssertUtil.FormDataValidate("端口不能为空。", () => { return(string.IsNullOrWhiteSpace(this.tbConnPort.Text)); });
                AssertUtil.FormDataValidate("端口不合法。", () => { return(!Regex.IsMatch(this.tbConnPort.Text, @"^[+-]?\d*$")); });

                ConnectionConfig config = new ConnectionConfig()
                {
                    Name     = this.tbConnName.Text.Trim(),
                    IP       = this.tbConnIP.Text.Trim(),
                    Port     = Convert.ToInt32(this.tbConnPort.Text.Trim()),
                    Password = this.tbConnPassword.Text.Trim()
                };
                if (configOperationType == ConfigOperationType.ADD)
                {
                    config.Id = Guid.NewGuid().ToString("N");
                    GlobalBusiness.SaveConfig(config);
                }
                else
                {
                    config.Id = this.configId;
                    GlobalBusiness.UpdateConfig(config);
                }

                MessageBox.Show("保存成功!");

                this.SavedConnectionConfig?.Invoke(config, this.configOperationType);

                this.Close();
            }
            catch (IllegalFormDataException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (DuplicateMemberException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (KeyNotFoundException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 当鼠标点击查询按钮时发生
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnSearch_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                AssertUtil.FormDataValidate("请输入键", () => { return(string.IsNullOrEmpty(this.tbKey.Text.Trim())); });
                string key = this.tbKey.Text.Trim();

                RedisValue redisValue = GlobalBusiness.RedisCaches[this.configId].Get(key, this.dbIndex);
                this.tbValue.Text = redisValue.Value;
            }
            catch (IllegalFormDataException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (RedisException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (Exception ex)
            {
                this.OnError?.Invoke(ex.Message);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 当鼠标点击测试连接按钮时发生。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnTestConnect_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                AssertUtil.FormDataValidate("名称不能为空。", () => { return(string.IsNullOrWhiteSpace(this.tbConnName.Text)); });
                AssertUtil.FormDataValidate("地址不能为空。", () => { return(string.IsNullOrWhiteSpace(this.tbConnIP.Text)); });
                AssertUtil.FormDataValidate("端口不能为空。", () => { return(string.IsNullOrWhiteSpace(this.tbConnPort.Text)); });
                AssertUtil.FormDataValidate("端口不合法。", () => { return(!Regex.IsMatch(this.tbConnPort.Text, @"^[+-]?\d*$")); });


                ConnectionConfig config = new ConnectionConfig()
                {
                    Name     = this.tbConnName.Text.Trim(),
                    IP       = this.tbConnIP.Text.Trim(),
                    Port     = Convert.ToInt32(this.tbConnPort.Text.Trim()),
                    Password = this.tbConnPassword.Text.Trim()
                };

                string      host   = (string.IsNullOrEmpty(config.Password) ? "" : $"{config.Password}@") + $"{config.IP}:{config.Port}";
                string[]    hosts  = new string[] { host };
                IRedisCache redis  = new RedisCache(hosts, hosts);
                string      result = redis.ConnectTest();
                if ("SUCCESS".Equals(result))
                {
                    MessageBox.Show("连接成功!");
                }
                else
                {
                    MessageBox.Show($"连接失败!({result})");
                }
            }
            catch (IllegalFormDataException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }