示例#1
0
        //规则删除按钮
        private void deleteclick(object sender, MouseButtonEventArgs e)
        {
            IDPIRulesManage rulesmg = new DPIRulesManage();
            string          dev_ip  = (from devices in StaticGlobal.fwdev_list
                                       where devices.getDev_MAC() == StaticGlobal.firewallmac
                                       select devices).ToList <FWDeviceForm>()[0].getProtecDevIP_list()[0];
            string source      = (dataGrid.SelectedItem as FireWallRuleDataTable).source.ToString();
            string destination = (dataGrid.SelectedItem as FireWallRuleDataTable).destination.ToString();
            string min_addr    = (dataGrid.SelectedItem as FireWallRuleDataTable).coiladdressstart.ToString();
            string max_addr    = (dataGrid.SelectedItem as FireWallRuleDataTable).coiladdressend.ToString();
            string func        = (dataGrid.SelectedItem as FireWallRuleDataTable).func.ToString();
            int    min_data    = (dataGrid.SelectedItem as FireWallRuleDataTable).mindata;
            int    max_data    = (dataGrid.SelectedItem as FireWallRuleDataTable).maxdata;
            bool   log         = (dataGrid.SelectedItem as FireWallRuleDataTable).log;

            if (rulesmg.ChangeModbusTcpRules(destination, source, min_addr, max_addr, func, min_data, max_data, dev_ip, log, false))
            {
                StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list().Remove((dataGrid.SelectedItem as FireWallRuleDataTable));
                UserMessageBox.Show("提示", "规则删除成功!");
            }
            else
            {
                UserMessageBox.Show("提示", "规则删除失败,请检查设备连接!");
            }
        }
示例#2
0
        private void Applying()
        {
            Dispatcher.Invoke(new Action(() =>
            {
                NewRulebutton.IsEnabled = false;
                Applybutton.IsEnabled   = false;
                dataGrid.IsEnabled      = false;
                Closebutton.IsEnabled   = false;
            }));
            //找出需要删除的规则
            var deleteRules = StaticGlobal.oldrules.Where(deleteRule => !StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list().Contains(deleteRule)).ToList();

            //找出需要增加的规则
            var    addRules     = StaticGlobal.FireWalldevices[StaticGlobal.firewallindex].getFireWallRule_list().Where(addRule => !StaticGlobal.oldrules.Contains(addRule)).ToList();
            bool   allApplyFlag = true;
            string dev_ip       = (from devices in StaticGlobal.fwdev_list
                                   where devices.getDev_MAC() == StaticGlobal.firewallmac
                                   select devices).ToList <FWDeviceForm>()[0].getProtecDevIP_list()[0];

            IDPIRulesManage rulesmg = new DPIRulesManage();

            //增加规则
            for (int i = 0; i < addRules.Count(); i++)
            {
                string protocol         = addRules[i].protocol;
                string source           = addRules[i].source;
                string destination      = addRules[i].destination;
                string coiladdressstart = addRules[i].coiladdressstart;
                string coiladdressend   = addRules[i].coiladdressend;
                int    mindata          = addRules[i].mindata;
                int    maxdata          = addRules[i].maxdata;
                string functioncode     = addRules[i].func;
                bool   log = addRules[i].log;
                //string[] functioncode16 = fuctioncode.Split(';');
                //string[] functioncode10 = new string[functioncode16.Length];
                //if (fuctioncode == "")
                //{
                //    functioncode10 = null;
                //}
                //else
                //{
                //    for (int j = 0; j < functioncode16.Length; j++)
                //    {
                //        functioncode10[j] = Convert.ToInt16(functioncode16[j], 16).ToString();
                //    }
                //}

                //IRulesManage rulesmg = new RulesManage();
                switch (protocol)
                {
                case "ModbusTCP":
                    if (rulesmg.ChangeModbusTcpRules(destination, source, coiladdressstart, coiladdressend, functioncode, mindata, maxdata, dev_ip, log, true))
                    {
                        allApplyFlag = true;
                    }
                    else
                    {
                        allApplyFlag = false;
                    }
                    break;

                case "OPC":
                    if (rulesmg.ChangeOPCRules(destination, source, dev_ip, log, true))
                    {
                        allApplyFlag = true;
                    }
                    else
                    {
                        allApplyFlag = false;
                    }
                    break;

                case "DNP3":
                    if (rulesmg.ChangeDNP3Rules(destination, source, dev_ip, log, true))
                    {
                        allApplyFlag = true;
                    }
                    else
                    {
                        allApplyFlag = false;
                    }
                    break;
                }
            }
            //删除规则
            for (int i = 0; i < deleteRules.Count(); i++)
            {
                string protocol         = deleteRules[i].protocol;
                string source           = deleteRules[i].source;
                string destination      = deleteRules[i].destination;
                string coiladdressstart = deleteRules[i].coiladdressstart;
                string coiladdressend   = deleteRules[i].coiladdressend;
                int    mindata          = deleteRules[i].mindata;
                int    maxdata          = deleteRules[i].maxdata;
                string functioncode     = deleteRules[i].func;
                bool   log = deleteRules[i].log;
                //string[] functioncode16 = fuctioncode.Split(';');
                //string[] functioncode10 = new string[functioncode16.Length];
                //if (fuctioncode == "")
                //{
                //    functioncode10 = null;
                //}
                //else
                //{
                //    for (int j = 0; j < functioncode16.Length; j++)
                //    {
                //        functioncode10[j] = Convert.ToInt16(functioncode16[j], 16).ToString();
                //    }
                //}

                //IRulesManage rulesmg = new RulesManage();
                switch (protocol)
                {
                case "ModbusTCP":
                    if (rulesmg.ChangeModbusTcpRules(destination, source, coiladdressstart, coiladdressend, functioncode, mindata, maxdata, dev_ip, log, false))
                    {
                        allApplyFlag = true;
                    }
                    else
                    {
                        allApplyFlag = false;
                    }
                    break;

                case "OPC":
                    if (rulesmg.ChangeOPCRules(destination, source, dev_ip, log, false))
                    {
                        allApplyFlag = true;
                    }
                    else
                    {
                        allApplyFlag = false;
                    }
                    break;

                case "DNP3":
                    if (rulesmg.ChangeDNP3Rules(destination, source, dev_ip, log, false))
                    {
                        allApplyFlag = true;
                    }
                    else
                    {
                        allApplyFlag = false;
                    }
                    break;
                }
            }
            Dispatcher.Invoke(new Action(() =>
            {
                if (allApplyFlag)
                {
                    UserMessageBox.Show("提示", "所有规则已成功应用!");
                }
                else
                {
                    UserMessageBox.Show("提示", "部分规则未成功应用,请检查设备之间的连接!");
                }
                this.Close();
            }
                                         ));
            ApplyThread.Abort();
        }