Exemplo n.º 1
0
        private void ButtonHandler(object sender, EventArgs e)
        {
            FixClickFocus();

            if (sender == tbOpen || sender == btnOpen ||
               sender == tbOpenFromDropbox || sender == tbOpenFromOneDrive ||
               sender == txtProcessingTime)
            {
                string path = null;
                if (sender == tbOpenFromDropbox)
                    path = CloudFolders.DropboxDirectory;
                else if (sender == tbOpenFromOneDrive)
                    path = CloudFolders.OneDriveDirectory;

                var fd = new OpenFileDialog
                {
                    DefaultExt = ".websurge;.txt;.log",
                    Filter = "WebSurge files (*.websurge)|*.websurge|Text files (*.txt)|*.txt|Log Files (*.log)|*.log|All Files (*.*)|*.*",
                    CheckFileExists = true,
                    RestoreDirectory = true,
                    FileName = "",
                    Title = "Open WebSurge Request File"
                };
                if (!string.IsNullOrEmpty(path))
                    fd.InitialDirectory = path;

                    var dr = fd.ShowDialog();
                if (dr != DialogResult.Cancel)
                {
                    FileName = Path.GetFullPath(fd.FileName);
                    OpenFile(FileName);
                }
            }
            else if (sender == btnClose)
            {
                CloseSession();
            }
            else if (sender == tbCapture || sender == btnCapture)
            {
                var fiddlerForm = new FiddlerCapture(this);
                fiddlerForm.Owner = this;
                fiddlerForm.Show();
            }
            else if (sender == tbStart || sender == btnStart)
            {
                StartProcessing();
            }
            else if (sender == tbStop || sender == btnStop)
            {
                StressTester.CancelThreads = true;
                ShowStatus("Stopping request processing...");
            }
            else if (sender == tbEditFile || sender == btnEditFile)
            {
                if (!string.IsNullOrEmpty(FileName))
                {
                    Process.Start(new ProcessStartInfo("notepad.exe", FileName) {UseShellExecute = true});
                    AttachWatcher(FileName);
                }
            }
            else if (sender == btnAbout)
            {
                var splashForm = new Splash();
                splashForm.StartPosition = FormStartPosition.Manual;
                splashForm.Left = Left + Width / 2 - splashForm.Width / 2;
                splashForm.Top = Top + Height / 2 - splashForm.Height / 2;
                splashForm.Show();
            }
            else if (sender == btnGotoWebSite)
                ShellUtils.GoUrl("http://websurge.west-wind.com");
            else if (sender == btnGotoRegistration)
                ShellUtils.GoUrl("http://store.west-wind.com/product/websurge");
            else if (sender == btnRegistration)
            {
                var regForm = new UnlockKeyForm("Web Surge");
                regForm.Left = Left + Width / 2 - regForm.Width / 2;
                regForm.Top = Top + Height / 2 - regForm.Height / 2 + 40;
                regForm.ShowDialog();
                UpdateButtonStatus();
            }
            else if (sender == tbExportXml || sender == btnExportXml)
                Export("xml");
            else if (sender == tbExportJson || sender == btnExportJson)
                Export("json");
            else if (sender == tbExportRaw || sender == btnExportHtml)
                Export("raw");
            else if (sender == btnExportResultSummary)
                Export("results");

            if (sender == tbTimeTakenPerUrl || sender == tbTimeTakenPerUrlChart || sender == btnTimeTakenPerUrlChart)
            {
                if (ListResults.SelectedItems.Count > 0)
                {
                    var listItem = ListResults.SelectedItems[0];
                    var request = listItem.Tag as HttpRequestData;
                    var form = new ChartFormZed(StressTester.Results, request.Url, ChartTypes.TimeTakenPerRequest);
                    form.ParentForm = this;
                    form.Show();
                }
            }
            if (sender == tbRequestsPerSecondChart || sender == tbRequestPerSecondChart ||
                sender == btnRequestsPerSecondChart)
            {
                if (StressTester.Results.Count() > 0)
                {
                    var form = new ChartFormZed(StressTester.Results, null, ChartTypes.RequestsPerSecond);
                    form.ParentForm = this;
                    form.Show();
                }
            }
            if (sender == tbDeleteRequest || sender == tbDeleteRequest2)
            {
                if (ListRequests.SelectedItems.Count > 0)
                {
                    foreach (ListViewItem listItem in ListRequests.SelectedItems)
                    {
                        var request = listItem.Tag as HttpRequestData;
                        Requests.Remove(request);
                        var index = listItem.Index;
                        ListRequests.Items.Remove(listItem);
                        if (index < ListRequests.Items.Count)
                            ListRequests.Items[index].Selected = true;
                    }
                }
            }
            if (sender == tbToggleActive)
            {
                if (ListRequests.SelectedItems.Count > 0)
                {
                    int index = 0;
                    foreach (ListViewItem listItem in ListRequests.SelectedItems)
                    {
                        index = listItem.Index;
                        var request = listItem.Tag as HttpRequestData;
                        request.IsActive = !request.IsActive;
                    }
                    RenderRequests(Requests,index);
                }
            }
            if (sender == tbMoveUp || sender == tbMoveDown)
            {
                if (ListRequests.SelectedItems.Count > 0)
                {
                    // assign current sort order
                    for(var x=0; x < Requests.Count-1; x++)
                        Requests[x].SortOrder = Requests.Count - 1 - x;

                    int newVal = 0;
                    int index = -1;
                    foreach (ListViewItem listItem in ListRequests.SelectedItems)
                    {
                        var request = listItem.Tag as HttpRequestData;
                        HttpRequestData swap;

                        if (sender == tbMoveUp)
                        {
                            newVal = request.SortOrder + 1;
                            if (newVal > Requests.Count - 1)
                                newVal = request.SortOrder;
                            index = Requests.Count - 1 - newVal;
                        }
                        if (sender == tbMoveDown)
                        {
                            newVal = request.SortOrder - 1 ;
                            if (newVal < 0)
                                newVal = 0;
                            index = Requests.Count - 1 - newVal;
                        }

                        swap = Requests.FirstOrDefault(req => req.SortOrder == newVal);
                        if (swap != null)
                             swap.SortOrder = request.SortOrder;
                         request.SortOrder = newVal;
                    }
                    Requests = Requests.OrderByDescending(req => req.SortOrder).ToList();
                    RenderRequests(Requests,index);
                }
            }
            if (sender == tbEditRequest || sender == tbEditRequest2)
            {
                if (ListRequests.SelectedItems.Count > 0)
                {
                    var listItem = ListRequests.SelectedItems[0];
                    var request = listItem.Tag as HttpRequestData;
                    LoadRequest(request);
                    TabsResult.SelectedTab = tabRequest;
                }
            }
            if (sender == tbNewRequest || sender == tbNewRequest2)
            {
                txtRequestUrl.Tag = null;

                txtHttpMethod.Text = "GET";
                txtRequestUrl.Text = "http://";

                txtRequestHeaders.Text = "Accept-Encoding: gzip,deflate";
                txtRequestContent.Text = string.Empty;
                TabsResult.SelectedTab = tabRequest;
                chkIsActive.Checked = true;
                txtRequestUrl.Focus();
            }
            if (sender == tbCopyFromRequest)
            {
                var req = txtRequestUrl.Tag as HttpRequestData;
                if (req == null)
                    return;

                var newRequest = HttpRequestData.Copy(req);
                if (!newRequest.Url.EndsWith("_COPIED"))
                    newRequest.Url += "_COPIED";

                LoadRequest(newRequest);
                txtRequestUrl.Tag = null; // it's a new request

                TabsResult.SelectedTab = tabRequest;
                txtRequestUrl.Focus();

            }
            if (sender == btnSaveRequest)
            {
                var req = txtRequestUrl.Tag as HttpRequestData;
                bool isNew = req == null;
                req = SaveRequest(req);

                if (isNew)
                {
                    Requests.Add(req);
                    txtRequestUrl.Tag = req;
                }

                RenderRequests(Requests);
            }
            if (sender == btnRunRequest || sender == tbTestRequest2 || sender == tbTestRequest)
            {
                var req = txtRequestUrl.Tag as HttpRequestData;
                req = SaveRequest(req);

                TestSiteUrl(req);
            }
            if (sender == tbTestAll)
            {
                TestAllSiteUrls();
            }

            if (sender == btnOpenInDefaultBrowser)
            {
                var context = ((ToolStripItem) sender).GetCurrentParent() as ContextMenuStrip;
                if (context == null)
                    return;

                var browser = context.SourceControl as WebBrowser;
                ShellUtils.GoUrl(browser.Url.ToString());
            }

            if (sender == tbSaveAllRequests || sender == tbSaveAllRequests2 ||
                sender == btnSaveAllRequests || sender == btnSaveAllRequestsAs ||
                sender == tbSaveToDropbox || sender == tbSaveToOneDrive)
            {
                var parser = new SessionParser();

                var path = App.UserDataPath;

                if (sender == tbSaveToDropbox)
                    path = CloudFolders.DropboxDirectory;
                else if(sender == tbSaveToOneDrive)
                    path = CloudFolders.OneDriveDirectory;
                else if (!string.IsNullOrEmpty(FileName))
                    path = Path.GetDirectoryName(FileName);

                StressTester.Options.LastSecondsToRun = StringUtils.ParseInt(tbtxtTimeToRun.Text, 20);
                StressTester.Options.LastThreads = StringUtils.ParseInt(tbtxtThreads.Text, 5);

                var file = string.Empty;
                if (!string.IsNullOrEmpty(FileName))
                    file = Path.GetFileName(FileName);

                if (sender != btnSaveAllRequestsAs &&
                    sender != tbSaveToDropbox && sender != tbSaveToOneDrive &&
                    File.Exists(FileName))
                {
                    parser.Save(Requests, FileName, StressTester.Options);
                    ShowStatus("Session saved.", 1, 4000);
                }
                else
                {
                    SaveFileDialog sd = new SaveFileDialog
                    {
                        Filter = "websurge files (*.websurge)|*.websurge|txt files (*.txt)|*.txt|All files (*.*)|*.*",
                        FilterIndex = 1,
                        FileName = file,
                        CheckFileExists = false,
                        OverwritePrompt = false,
                        AutoUpgradeEnabled = true,
                        CheckPathExists = true,
                        InitialDirectory = path,
                        RestoreDirectory = true
                    };

                    var result = sd.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        FileName = sd.FileName;
                        parser.Save(Requests, sd.FileName, StressTester.Options);
                    }
                }

            }
            else if (sender == btnFeedback)
            {
                string msg =
            @"We really appreciate your feedback, good and bad!

            Please use our message board to post any feedback about
            what doesn't work quite the way you'd like it to, or
            to request functionality that's not there at the moment.
            Comments about what you like or how WebSurge is helping
            you get your job done are also very welcome.

            Your feedback is important and helps us improve WebSurge
            so please don't be shy.

            It takes a only a few seconds to create an account
            to post a message. We want to hear from you and we
            reply to all messages promptly with frank discussions.

            Thank you!";
                var res = MessageBox.Show(msg, App.Configuration.AppName + " Bug Report",MessageBoxButtons.OKCancel,
                    MessageBoxIcon.Information);
                if (res == DialogResult.OK)
                    ShellUtils.GoUrl("http://west-wind.com/wwThreads/default.asp?forum=West%20Wind%20WebSurge");
            }
            else if (sender == btnBugReport)
            {
                string msg =
            @"Please use our issue tracker to report bugs or enhancement
            requests on the GitHub repository.

            When describing your issue, please provide as much detail
            as possible, and if possible provide steps to reproduce
            the behavior, so we can replicate and fix the issue as
            quickly as possible.

            You can also look at the WebSurge Error Log by using the
            Help | Show Error Log menu option. You can copy and paste
            the relevant error section into the issue text.

            If you're not sure whether you have discovered a bug or
            need clarification of functionality, please use the
            Feedback and Suggestions link from the Help menu.

            We want to hear from you, and we respond promptly to
            any reported issues.";

                var res =  MessageBox.Show(msg, App.Configuration.AppName + " Feedback", MessageBoxButtons.OKCancel,
                    MessageBoxIcon.Information);
                if (res == DialogResult.OK)
                    ShellUtils.GoUrl("https://github.com/RickStrahl/WestWindWebSurge/issues");
            }
            else if (sender == btnShowErrorLog)
            {
                ShellUtils.GoUrl(App.UserDataPath + "WebSurgeErrors.log");
            }
            else if (sender == btnGotoSettingsFolder)
            {
                ShellUtils.GoUrl(App.UserDataPath);
            }
            else if (sender == btnCheckForNewVersion)
                CheckForNewVersion(true);
            else if (sender == btnHelp)
                System.Windows.Forms.Help.ShowHelp(this,"websurge.chm",HelpNavigator.TableOfContents);
            else if(sender == btnHelpIndex)
                System.Windows.Forms.Help.ShowHelp(this, "websurge.chm", HelpNavigator.KeywordIndex);
            else if (sender == btnExit)
                Close();

            UpdateButtonStatus();
        }
Exemplo n.º 2
0
        void Export(string mode)
        {
            string filePrefix = "WebSurge";
            if (!string.IsNullOrEmpty(FileName))
            {
                string tFileName = Path.GetFileNameWithoutExtension(FileName);
                if (!string.IsNullOrEmpty(tFileName))
                    filePrefix = tFileName;
            }
            string fileName = filePrefix + "_Result_" + DateTime.Now.ToString("yyyy-MM-dd");

            if (mode == "xml")
            {
                var diag = new SaveFileDialog
                {
                    AutoUpgradeEnabled = true,
                    CheckPathExists = true,
                    DefaultExt = "xml",
                    Filter = "Xml files (*.xml)|*.xml|All Files (*.*)|*.*",
                    OverwritePrompt = false,
                    Title = "Export Results as XML",
                    RestoreDirectory = true,
                    FileName = fileName + ".xml"
                };
                var res = diag.ShowDialog();

                if (res == DialogResult.OK)
                {
                    if (File.Exists(diag.FileName))
                        File.Delete(diag.FileName);

                    if (SerializationUtils.SerializeObject(StressTester.Results, diag.FileName, false))
                    {
                        int fileSize = (int) new FileInfo(diag.FileName).Length;
                        if(MessageBox.Show( string.Format("Data saved to:\r\n{0} ({1})",diag.FileName, (fileSize / 1024).ToString("n2").ToLower()) +
                                        "\r\n\r\n" +
                                        "Do you want to view the file?",
                                        App.Configuration.AppName,
                                        MessageBoxButtons.YesNo,MessageBoxIcon.Information) == DialogResult.Yes)
                        ShellUtils.GoUrl(diag.FileName);
                    }
                }
            }
            else if (mode == "json")
            {
                var diag = new SaveFileDialog
                {
                    AutoUpgradeEnabled = true,
                    CheckPathExists = true,
                    DefaultExt = "JSON",
                    Filter = "JSON files (*.json)|*.json|All Files (*.*)|*.*",
                    OverwritePrompt = false,
                    Title = "Export Results as JSON",
                    RestoreDirectory = true,
                    FileName = fileName + ".json"
                };
                var res = diag.ShowDialog();

                if (res == DialogResult.OK)
                {
                    if (File.Exists(diag.FileName))
                        File.Delete(diag.FileName);
                    string json = JsonSerializationUtils.Serialize(StressTester.Results, false, true);

                    if (json != null)
                    {
                        File.WriteAllText(diag.FileName, json);
                        int fileSize = (int) new FileInfo(diag.FileName).Length;
                        if (MessageBox.Show(string.Format("Data saved to:\r\n{0} ({1})", diag.FileName, (fileSize / 1024).ToString("n2").ToLower()) +
                                        "\r\n\r\n" +
                                        "Do you want to view the file?",
                                        App.Configuration.AppName,
                                        MessageBoxButtons.YesNo,MessageBoxIcon.Information) == DialogResult.Yes)
                        ShellUtils.GoUrl(diag.FileName);
                    }
                }
            }
            else if (mode == "raw")
            {
                var diag = new SaveFileDialog
                {
                    AutoUpgradeEnabled = true,
                    CheckPathExists = true,
                    DefaultExt = "websurge",
                    Filter = "websurge files (*.websurge)|*.websurge|txt files (*.txt)|*.txt|All Files (*.*)|*.*",
                    OverwritePrompt = false,
                    Title = "Export Results",
                    RestoreDirectory = true,
                    FileName = fileName + ".websurge"
                };
                var res = diag.ShowDialog();
                if (res == DialogResult.OK)
                {
                    if (File.Exists(diag.FileName))
                        File.Delete(diag.FileName);

                    var parser = new SessionParser();
                    if (parser.Save(StressTester.Results, diag.FileName))
                    {

                        int fileSize = (int) new FileInfo(diag.FileName).Length;
                        if (MessageBox.Show(
                            string.Format("Data saved to:\r\n{0} ({1})", diag.FileName, (fileSize / 1024).ToString("n2").ToLower()) +
                            "\r\n\r\n" +
                            "Do you want to view the file?",
                            App.Configuration.AppName,
                            MessageBoxButtons.YesNo, MessageBoxIcon.Information) ==
                            DialogResult.Yes)
                            ShellUtils.GoUrl(diag.FileName);
                        ShellUtils.GoUrl(diag.FileName);
                    }
                }
            }
            else if (mode == "results")
            {
                var diag = new SaveFileDialog
                {
                    AutoUpgradeEnabled = true,
                    CheckPathExists = true,
                    DefaultExt = "txt",
                    Filter = "txt files (*.json)|*.json|All Files (*.*)|*.*",
                    OverwritePrompt = false,
                    Title = "Export Summary Results",
                    RestoreDirectory = true,
                    FileName = filePrefix + "_Result_Summary_" + DateTime.Now.ToString("yyyy-MM-dd") + ".json"
                };
                if (!string.IsNullOrEmpty(FileName))
                {
                    var file = Path.GetFileNameWithoutExtension(FileName);
                    var dt = DateTime.Now;
                }

                var res = diag.ShowDialog();
                if (res == DialogResult.OK)
                {
                    if (File.Exists(diag.FileName))
                        File.Delete(diag.FileName);

                    var result = StressTester.ResultsParser.GetResultReport(
                                                StressTester.Results,
                                                StressTester.TimeTakenForLastRunMs,
                                                StressTester.ThreadsUsed);
                    string json = JsonSerializationUtils.Serialize(result, false, true);
                    File.WriteAllText(diag.FileName, json);

                    ShellUtils.GoUrl(diag.FileName);
                }
            }
        }
Exemplo n.º 3
0
        void Export(string mode)
        {
            string filePrefix = "WebSurge";
            if (!string.IsNullOrEmpty(FileName))
            {
                string tFileName = Path.GetFileNameWithoutExtension(FileName);
                if (!string.IsNullOrEmpty(tFileName))
                    filePrefix = tFileName;
            }
            string fileName = filePrefix + "_Result_" + DateTime.Now.ToString("yyyy-MM-dd");

            if (mode == "xml")
            {
                var diag = new SaveFileDialog
                {
                    AutoUpgradeEnabled = true,
                    CheckPathExists = true,
                    DefaultExt = "xml",
                    Filter = "Xml files (*.xml)|*.xml|All Files (*.*)|*.*",
                    OverwritePrompt = false,
                    Title = "Export Results as XML",
                    RestoreDirectory = true,
                    FileName = fileName + ".xml"
                };
                var res = diag.ShowDialog();

                if (res == DialogResult.OK)
                {
                    if (File.Exists(diag.FileName))
                        File.Delete(diag.FileName);

                    if (SerializationUtils.SerializeObject(StressTester.Results, diag.FileName, false))
                       App.OpenFileInExplorer(diag.FileName);

                }
            }
            else if (mode == "json")
            {
                var diag = new SaveFileDialog
                {
                    AutoUpgradeEnabled = true,
                    CheckPathExists = true,
                    DefaultExt = "JSON",
                    Filter = "JSON files (*.json)|*.json|All Files (*.*)|*.*",
                    OverwritePrompt = false,
                    Title = "Export Results as JSON",
                    RestoreDirectory = true,
                    FileName = fileName + ".json"
                };
                var res = diag.ShowDialog();

                if (res == DialogResult.OK)
                {
                    if (File.Exists(diag.FileName))
                        File.Delete(diag.FileName);
                    string json = JsonSerializationUtils.Serialize(StressTester.Results, false, true);

                    if (json != null)
                    {
                        File.WriteAllText(diag.FileName, json);
                        App.OpenFileInExplorer(diag.FileName);
                    }
                }
            }
            else if (mode == "raw")
            {
                var diag = new SaveFileDialog
                {
                    AutoUpgradeEnabled = true,
                    CheckPathExists = true,
                    DefaultExt = "websurge",
                    Filter = "websurge files (*.websurge)|*.websurge|txt files (*.txt)|*.txt|All Files (*.*)|*.*",
                    OverwritePrompt = false,
                    Title = "Export Results",
                    RestoreDirectory = true,
                    FileName = fileName + ".websurge"
                };
                var res = diag.ShowDialog();
                if (res == DialogResult.OK)
                {
                    if (File.Exists(diag.FileName))
                        File.Delete(diag.FileName);

                    var parser = new SessionParser();
                    if (parser.Save(StressTester.Results, diag.FileName))
                        App.OpenFileInExplorer(diag.FileName);
                }
            }
            else if (mode == "results")
            {
                var diag = new SaveFileDialog
                {
                    AutoUpgradeEnabled = true,
                    CheckPathExists = true,
                    DefaultExt = "txt",
                    Filter = "txt files (*.json)|*.json|All Files (*.*)|*.*",
                    OverwritePrompt = false,
                    Title = "Export Summary Results",
                    RestoreDirectory = true,
                    FileName = filePrefix + "_Result_Summary_" + DateTime.Now.ToString("yyyy-MM-dd") + ".json"
                };
                if (!string.IsNullOrEmpty(FileName))
                {
                    var file = Path.GetFileNameWithoutExtension(FileName);
                    var dt = DateTime.Now;
                }

                var res = diag.ShowDialog();
                if (res == DialogResult.OK)
                {
                    if (File.Exists(diag.FileName))
                        File.Delete(diag.FileName);

                    var result = StressTester.ResultsParser.GetResultReport(
                        StressTester.Results,
                        StressTester.TimeTakenForLastRunMs,
                        StressTester.ThreadsUsed);
                    string json = JsonSerializationUtils.Serialize(result, false, true);
                    File.WriteAllText(diag.FileName, json);

                    App.OpenFileInExplorer(diag.FileName);
                }
            }
        }