private string AddOrChangeRule(ProxyRule rule)
        {
            if (rule.Listenaddress == rule.Connectaddress && rule.Listenport == rule.Connectport)
            {
                return("Connect address:port cannot be the same as listen address:port. for rule\r\n    " + rule.ToString());
            }
            int index = boundRules.IndexOf(rule);

            if (index == -1)
            {
                if (proxyDal.AddRule(rule))
                {
                    boundRules.Add(rule);
                    return("");
                }
                else
                {
                    return("Failed to add rule " + rule.ToString());
                }
            }
            else
            {
                if (proxyDal.SetRule(rule))
                {
                    boundRules[index] = rule;
                    return("");
                }
                else
                {
                    return("Failed to update rule " + rule.ToShortString());
                }
            }
        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to delete the selected rule(s)?", "Confirm Delete!", MessageBoxButtons.YesNo) != DialogResult.Yes)
            {
                return;
            }
            //return;
            int count = 0;

            foreach (ListViewItem item in listRules.SelectedItems)
            {
                ProxyRule rule = new ProxyRule();
                rule.Direction     = item.SubItems[0].Text;
                rule.Listenaddress = item.SubItems[1].Text;
                rule.Listenport    = item.SubItems[2].Text;

                if (proxyDal.DeleteRule(rule))
                {
                    int index = boundRules.IndexOf(rule);
                    boundRules.RemoveAt(index);
                    count++;
                }
                else
                {
                    MessageBox.Show("Failed to remove rule " + rule.ToShortString());
                }
            }
            if (count > 0)
            {
                ListViewReload();
            }
        }
        public bool DeleteRule(ProxyRule rule)
        {
            ExecResult result = ExecCommand("netsh", "interface portproxy delete " + rule.ToShortString());

            return(result.code == 0);
        }