Beispiel #1
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            List <string> keys = GetSelectKeys();

            if (keys.Count == 0)
            {
                Response.Write("<script>alert('至少选中一项进行删除')</script>");
                return;
            }
            else
            {
                MSMQConfig            config      = this.TempConfig;
                List <MSMQConfigNode> removeNodes = new List <MSMQConfigNode>();
                foreach (string key in keys)
                {
                    foreach (MSMQConfigNode node in config.Nodes)
                    {
                        if (key == node.ToString())
                        {
                            removeNodes.Add(node);
                        }
                    }
                }
                if (removeNodes.Count > 0)
                {
                    removeNodes.ForEach(p => {
                        config.Nodes.Remove(p);
                    });

                    //更新session
                    TempConfig = config;
                    //保存config
                    XmlHelper.Enity2Xml(ConfigPath, config);
                    //刷新表格
                    BindGridView(config);
                    //clear
                    Clear();

                    //更新服务配置文件时间
                    MonitorExe.UpdateLastConfigTime();
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //非空判断
            string ip       = txtIP.Text.Trim();
            string domain   = txtDomain.Text.Trim();
            string account  = txtAccount.Text.Trim();
            string pwd      = txtPwd.Text.Trim();
            string category = ddlCategory.SelectedValue;
            string counter  = ddlCounter.SelectedValue;
            string instance = txtInstance.Text.Trim();

            if (string.IsNullOrEmpty(ip))
            {
                Response.Write("<script>alert('IP必须填写')</script>");
                return;
            }
            if (string.IsNullOrEmpty(domain))
            {
                Response.Write("<script>alert('所属域必须填写')</script>");
                return;
            }
            if (string.IsNullOrEmpty(account))
            {
                Response.Write("<script>alert('账号必须填写')</script>");
                return;
            }
            if (string.IsNullOrEmpty(pwd))
            {
                Response.Write("<script>alert('密码必须填写')</script>");
                return;
            }
            if (string.IsNullOrEmpty(category))
            {
                Response.Write("<script>alert('监控类型必须选择')</script>");
                return;
            }
            if (string.IsNullOrEmpty(counter))
            {
                Response.Write("<script>alert('计数器必须选择')</script>");
                return;
            }
            if (category == "MSMQ Queue" && string.IsNullOrEmpty(instance))
            {
                Response.Write("<script>alert('实例必须填写')</script>");
                return;
            }

            MSMQConfig config = TempConfig;

            List <string> keys = GetSelectKeys();

            if (keys.Count == 0)
            {
                //新增

                string key = ip + category + counter + (instance ?? "");
                if (config.Nodes.Any(p => p.ToString() == key))
                {
                    //已经有这个配置
                    Response.Write("<script>alert('不能重复进行配置')</script>");
                    return;
                }
                else
                {
                    config.Nodes.Add(new MSMQConfigNode()
                    {
                        Domain       = ip,
                        CategoryName = category,
                        CounterName  = counter,
                        Instance     = instance
                    });
                }
            }
            else if (keys.Count == 1)
            {
                //修改情况
                MSMQConfigNode node = config.Nodes.Find(p => { return(p.ToString() == keys[0]); });
                if (node != null)
                {
                    node.Domain       = ip;
                    node.CategoryName = category;
                    node.CounterName  = counter;
                    node.Instance     = instance;
                }
            }
            else
            {
                //多个时不处理
                Response.Write("<script>alert('不能同时修改多个值')</script>");
                return;
            }
            //更新domain
            var    listDomains = config.Domains.Where(p => { return(p.Name == ip); }).ToList <ConfigDomain>();
            string domainValue = EncryptHelper.EncryptDES(ip + "|" + domain + "|" + account + "|" + pwd);

            if (listDomains.Count == 0)
            {
                //新增情况
                config.Domains.Add(new ConfigDomain()
                {
                    Name  = ip,
                    Value = domainValue
                });
            }
            else
            {
                //修改
                listDomains[0].Value = domainValue;
            }
            //更新session
            TempConfig = config;
            //保存config
            XmlHelper.Enity2Xml(ConfigPath, config);
            //刷新表格
            BindGridView(config);
            //clear
            Clear();

            //更新服务配置文件时间
            MonitorExe.UpdateLastConfigTime();
        }