Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (button1.Tag == null)
                {
                    if (defaultNode == null)
                    {
                        MessageBox.Show("请选择监控节点!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    if (checkBox3.Checked)
                    {
                        var timer = Convert.ToInt32(numericUpDown2.Value);
                        var url = ConfigurationManager.AppSettings["ServerMonitorUrl"];

                        if (!string.IsNullOrEmpty(url))
                        {
                            if (url.IndexOf('?') > 0)
                                url = url + "&timer=" + timer;
                            else
                                url = url + "?timer=" + timer;
                            webBrowser2.Navigate(url);
                        }
                    }

                    var listener = new StatusListener(tabControl1, listConnect, listTimeout, listError,
                        Convert.ToInt32(numericUpDown3.Value), Convert.ToInt32(numericUpDown5.Value),
                        Convert.ToInt32(numericUpDown1.Value), Convert.ToInt32(numericUpDown4.Value), checkBox4.Checked);

                    service = CastleFactory.Create().GetChannel<IStatusService>(defaultNode, listener);

                    //var services = service.GetServiceList();

                    var options = new SubscribeOptions
                    {
                        PushCallError = checkBox1.Checked,
                        PushCallTimeout = checkBox2.Checked,
                        PushServerStatus = checkBox3.Checked,
                        PushClientConnect = true,
                        CallTimeout = Convert.ToDouble(numericUpDown1.Value) / 1000,
                        CallRowCount = Convert.ToInt32(numericUpDown5.Value),
                        ServerStatusTimer = Convert.ToInt32(numericUpDown2.Value)
                    };

                    try
                    {
                        service.Subscribe(options);

                        button1.Text = "停止监控";
                        button1.Tag = label1.Text;
                        label1.Text = "正在进行监控...";

                        checkBox1.Enabled = false;
                        checkBox2.Enabled = false;
                        checkBox3.Enabled = false;
                        comboBox1.Enabled = false;

                        numericUpDown1.Enabled = checkBox2.Enabled && checkBox2.Checked;
                        numericUpDown2.Enabled = checkBox3.Enabled && checkBox3.Checked;

                        checkBox4.Enabled = false;
                        numericUpDown3.Enabled = false;
                        numericUpDown4.Enabled = false;
                        numericUpDown5.Enabled = false;
                        //button1.Enabled = false;
                    }
                    catch (Exception ex)
                    {
                        SimpleLog.Instance.WriteLogForDir("Client", ex);
                        MessageBox.Show(ex.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    if (sender != null)
                    {
                        if (MessageBox.Show("确定停止监控吗?", "系统提示",
                            MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) return;
                    }

                    try
                    {
                        service.Unsubscribe();
                    }
                    catch (Exception ex)
                    {
                        SimpleLog.Instance.WriteLogForDir("Client", ex);
                        MessageBox.Show(ex.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    checkedListBox1.Items.Clear();
                    checkedListBox2.Items.Clear();

                    label1.Text = button1.Tag.ToString();
                    button1.Text = "开始监控";
                    button1.Tag = null;

                    //listConnect.Items.Clear();
                    //listError.Items.Clear();
                    //listTimeout.Items.Clear();

                    //listConnect.Invalidate();
                    //listError.Invalidate();
                    //listTimeout.Invalidate();

                    tabPage1.Text = "连接信息" + (listConnect.Items.Count == 0 ? "" : "(" + listConnect.Items.Count + ")");
                    tabPage2.Text = "警告信息" + (listTimeout.Items.Count == 0 ? "" : "(" + listTimeout.Items.Count + ")");
                    tabPage3.Text = "异常信息" + (listError.Items.Count == 0 ? "" : "(" + listError.Items.Count + ")");

                    checkBox1.Enabled = true;
                    checkBox2.Enabled = true;
                    checkBox3.Enabled = true;
                    comboBox1.Enabled = true;

                    numericUpDown1.Enabled = checkBox2.Enabled && checkBox2.Checked;
                    numericUpDown2.Enabled = checkBox3.Enabled && checkBox3.Checked;

                    try { webBrowser1.Document.GetElementsByTagName("body")[0].InnerHtml = string.Empty; }
                    catch { }

                    checkBox4.Enabled = true;
                    numericUpDown3.Enabled = true;
                    numericUpDown4.Enabled = true;
                    numericUpDown5.Enabled = true;
                    //button1.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                SimpleLog.Instance.WriteLogForDir("Client", ex);
                MessageBox.Show(ex.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }