Ejemplo n.º 1
0
        private void StartBenchmark()
        {
            if (!string.IsNullOrEmpty(txtUrl.Text) && Uri.IsWellFormedUriString(txtUrl.Text, UriKind.Absolute))
            {
                var arguments = GetArguments();

                if (null != arguments)
                {
                    _ApacheBench               = new ApacheBench(txtUrl.Text, arguments);
                    _ApacheBench.InProgress   += ApacheBench_InProgress;
                    _ApacheBench.DataReceived += ApacheBench_DataReceived;
                    _ApacheBench.Completed    += ApacheBench_Completed;

                    lblToolStripStatus.Text      = string.Format("Started Run {0} ...", _RepeatIndex + 1);
                    pbToolStripProgressBar.Value = 0;
                    btnCancel.Visible            = true;
                    if (!_ApacheBench.Start())
                    {
                        MessageBox.Show("Error starting 'ab.exe'", "Error Starting", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else
            {
                txtUrl.Focus();
                txtUrl.SelectionStart  = 0;
                txtUrl.SelectionLength = txtUrl.Text.Length;
                //toolTip1.ToolTipTitle = "Please enter valid URL";
                toolTip1.Show("Please enter valid URL", txtUrl, 3000);
                ToggleControls();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Runs the ApacheBench in sync.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns>The data on StandardOutput</returns>
        public static string RunSync(string url, params KeyValuePair <string, string>[] arguments)
        {
            string output = string.Empty;

            using (var ab = new ApacheBench(url, arguments)) {
                if (ab.Start())
                {
                    while (!ab.HasExited)
                    {
                        ;
                    }
                    output = ab.StandardOutput;
                }
            }
            return(output);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the version.
        /// </summary>
        /// <returns></returns>
        public static string GetVersion()
        {
            string version = null;

            if (IsApacheBenchPresent())
            {
                try {
                    var output = ApacheBench.RunSync(null, new KeyValuePair <string, string>(APACHE_BENCH_FLAG_VERSION, null));
                    if (!string.IsNullOrEmpty(output))
                    {
                        var lines = output.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                        version = lines[0].Split(',')[1].Trim();
                    }
                }
                catch {
                    //Log error
                }
            }
            return(version);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Handles the Load event of the frmMain control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        private void frmMain_Load(object sender, EventArgs e)
        {
            //Check ApacheBench is present
            if (ApacheBench.IsApacheBenchPresent())
            {
                string version = ApacheBench.GetVersion();
                lblToolStripStatus.Text = "ApacheBench Found " + version;
            }
            else
            {
                MessageBox.Show("Cannot find ApacheBench. Please place ApacheBench 'ab.exe' in the same folder as this application", "Not Found", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                lblToolStripStatus.Text = "ApacheBench NOT FOUND!";
            }

            //Enumerate all network interfaces
            var interfaces = Program.NetWorkInterfaces();

            foreach (var nic in interfaces)
            {
                cboAddress.Items.Add(nic);
            }
        }