示例#1
0
        private void btnStartPortMonitor_Click(object sender, RoutedEventArgs e)
        {
            if (dgIFInfo.SelectedItems.Count < 1)
            {
                MessageBox.Show("请至少选择一个接口");
                return;
            }
            ObservableCollection <Interface> ifList = new ObservableCollection <Interface>();

            foreach (var item in dgIFInfo.SelectedItems)
            {
                IFInfomation ifInfo = item as IFInfomation;
                Interface    inf    = new Interface(equip.AdminIPAddress);
                inf.IfIndex          = ifInfo.IfIndex;
                inf.Descr            = ifInfo.IfDescr;
                inf.TimerInteral     = 1d;
                inf.MaxInSpeed       = -1d;
                inf.MaxOutSpeed      = -1d;
                inf.IsShowSpeedAlarm = false;
                ifList.Add(inf);
            }
            Thread t = new Thread(new ThreadStart(() =>
            {
                NCMMS.PortMonitor.PortMonitor portMonitor = new NCMMS.PortMonitor.PortMonitor(ifList);
                portMonitor.ShowDialog();
            }));

            t.SetApartmentState(ApartmentState.STA);
            t.IsBackground = true;
            t.Start();
        }
示例#2
0
 private void btnStartMonitor_Click(object sender, RoutedEventArgs e)
 {
     if ((bool)cbStartWithFile.IsChecked)
     {
         //读取xml保存的interface列表来生成监视
         string      fileFullName = ucFileBrowse.FileUrl;
         XmlDocument myXml        = new XmlDocument();
         myXml.Load(fileFullName);
         XmlNode rootNode = myXml.DocumentElement;
         ObservableCollection <Interface> ifList = new ObservableCollection <Interface>();
         foreach (XmlNode nodeIf in rootNode.ChildNodes)
         {
             int       ifIndex          = int.Parse(nodeIf.ChildNodes.Item(0).InnerText);
             string    ifDescr          = nodeIf.ChildNodes.Item(1).InnerText;
             IpAddress ip               = new IpAddress(nodeIf.ChildNodes.Item(2).InnerText);
             double    timerInteral     = double.Parse(nodeIf.ChildNodes.Item(3).InnerText);
             bool      isShowSpeedAlarm = nodeIf.ChildNodes.Item(4).InnerText.Equals("True") ? true : false;
             Interface i = new Interface(ip);
             i.IfIndex          = ifIndex;
             i.Descr            = ifDescr;
             i.IP               = ip;
             i.TimerInteral     = timerInteral;
             i.IsShowSpeedAlarm = isShowSpeedAlarm;
             if (isShowSpeedAlarm)
             {
                 double maxOutSpeed = double.Parse(nodeIf.ChildNodes.Item(5).InnerText);
                 double maxInSpeed  = double.Parse(nodeIf.ChildNodes.Item(6).InnerText);
                 i.MaxInSpeed  = maxInSpeed;
                 i.MaxOutSpeed = maxOutSpeed;
             }
             ifList.Add(i);
         }
         Thread threadPortMonitorPage = new Thread(() =>
         {
             PortMonitor portMonitor = new PortMonitor(ifList);
             portMonitor.Show();
         });
         threadPortMonitorPage.SetApartmentState(ApartmentState.STA);
         threadPortMonitorPage.IsBackground = true;
         threadPortMonitorPage.Start();
     }
     else
     {
         //使用listbox中的列表来打开
         if (selectedIFs.Count < 1)
         {
             MessageBox.Show("至少要选择一个接口!");
             return;
         }
         ObservableCollection <Interface> ifList = new ObservableCollection <Interface>(selectedIFs);
         Thread threadPortMonitorPage            = new Thread(() =>
         {
             PortMonitor portMonitor = new PortMonitor(ifList);
             portMonitor.ShowDialog();
         });
         threadPortMonitorPage.SetApartmentState(ApartmentState.STA);
         threadPortMonitorPage.IsBackground = true;
         threadPortMonitorPage.Start();
         selectedIFs.Clear();
     }
 }