Example #1
0
        private void OnEnd()
        {
            client = null;

            this.progressBar.Visible = false;
            this.add_button.Text = "添加";
        }
Example #2
0
        private void add_button_Click(object sender, EventArgs e)
        {
            if (null == client)
            {
                try
                {
//                    type DiscoveryParams struct {
//    IP_Range     []string `json:"ip-range"`
//    Communities  []string `json:"communities"`
//    SnmpV3Params []string `json:"snmpv3_params"`
//    Depth        int      `json:"discovery_depth"`
//    IsReadLocal  bool     `json:"is_read_local"`
//}
                    var discoveryParams = new Dictionary<string, object>();
                    discoveryParams["ip-range"] = this.rangeListBox.Lines;
                    discoveryParams["communities"] = this.communityBox.Lines;
                    discoveryParams["is_read_local"] = false;
                    discoveryParams["discovery_depth"] = 0;
                    discoveryParams["timeout"] = 20;

                    this.messageBox.Text = "";// Newtonsoft.Json.JsonConvert.SerializeObject(discoveryParams);

                    client = new DiscoveryClient(SystemManager.GetBridge(), discoveryParams);

                     new Thread(() =>
                    {
                        try
                        {
                            using (client)
                            {
                                while (client.IsRunning())
                                {
                                    this.Invoke(this.OnMessage, new object[]{ client.Get().ToArray()});
                                }
                                this.Invoke(this.DiscoveryResult, new object[] { client.GetResult() });
                            }

                        }
                        catch (Exception ex)
                        {
                            this.Invoke(this.OnMessage, new object[] { new string[] { ex.ToString() } });
                        }
                        this.Invoke(this.DiscoveryEnd);

                    }).Start();

                    this.add_button.Text = "停止";
                    this.progressBar.Visible = true;

                }
                catch (Exception ex)
                {
                    MyMessageBox.ShowMessage("错误", ex.Message, ex.ToString());
                }
            }
            else
            {
                this.add_button.Text = "添加";
                client.Interrupt();
            }
            
        }