public ResultsDisplayForm(StressTestIncomingResults results, StressTestOutgoingConfiguration configurations, StressTestSettings settings) { this.results = results; this.clientConfigurations = configurations; this.settings = settings; InitializeComponent(); }
private void saveConfig_Click(object sender, EventArgs e) { SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.Filter = "Json files (*.json)|*.json"; saveDialog.Title = "Save Configuration"; saveDialog.ShowDialog(); if (saveDialog.FileName != "") { FileStream fs = (FileStream)saveDialog.OpenFile(); var options = new JsonSerializerOptions { WriteIndented = true, }; StressTestOutgoingConfiguration config = new StressTestOutgoingConfiguration { GracePeriodSeconds = this.gracePeriodSeconds, Clients = this.clientConfigurations }; string serializedConfiguration = JsonSerializer.Serialize(config, options); byte[] bytes = Encoding.UTF8.GetBytes(serializedConfiguration); fs.Write(bytes, 0, bytes.Length); fs.Close(); } }
private void ShowResultsWindow(StressTestIncomingResults results, StressTestOutgoingConfiguration configuration, StressTestSettings settings) { ResultsDisplayForm resultForm = new ResultsDisplayForm(results, configuration, settings); resultForm.Show(); this.Hide(); }
// TODO: This validation could likely be heavily cleaned up, I'm just not very familiar with .NET and did this quickly... private void startStressTest_Click(object sender, EventArgs e) { // Fetches and validates each input in the form string brokerHost = brokerIpAddrInput.Text; int brokerPort; try { brokerPort = Int32.Parse(brokerPortInput.Text); } catch (Exception) { MessageBox.Show("Invalid port number supplied. Please try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Establishes a new MQTT client on the given host name and port try { // Moved the below two lines into the try-catch statement in order to fix invalid string input in IP address field client = new MqttClient(brokerHost, brokerPort, false, null, null, MqttSslProtocols.None); string clientId = "stress_test/ui"; client.Connect(clientId); client.MqttMsgPublishReceived += onMessageReceived; client.Subscribe(new string[] { "stress_test/results" }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE }); } catch (Exception) { MessageBox.Show("Connection could not be established. Please check your inputs and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } StressTestOutgoingConfiguration config = new StressTestOutgoingConfiguration { GracePeriodSeconds = this.gracePeriodSeconds, Clients = this.clientConfigurations }; string serializedConfiguration = JsonSerializer.Serialize(config); // Send a packet to the broker supplying all the arguments for starting a stress test client.Publish("stress_test/start", Encoding.UTF8.GetBytes(serializedConfiguration)); HideAllControls(); loadingPanel.Visible = true; StartLoadingTimer(); }
private void loadConfig_Click(object sender, EventArgs e) { OpenFileDialog openDialog = new OpenFileDialog(); openDialog.Filter = "Json files (*.json)|*.json"; openDialog.Title = "Load Configuration"; if (openDialog.ShowDialog() == DialogResult.OK) { try { Stream stream; if ((stream = openDialog.OpenFile()) != null) { using (stream) { StreamReader reader = new StreamReader(stream); string line; string totalJsonStr = ""; while ((line = reader.ReadLine()) != null) { totalJsonStr += line; } Console.WriteLine(totalJsonStr); StressTestOutgoingConfiguration config = JsonSerializer.Deserialize <StressTestOutgoingConfiguration>(totalJsonStr); gracePeriodSeconds = config.GracePeriodSeconds; clientConfigurations = config.Clients; OnLoadConfigFile(); } } } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } } }
/// <summary> /// When returned to from the ResultsDisplayForm, populates the fields based off of the previously given data. /// </summary> /// <param name="settings">Base settings (i.e. broker IP, broker port, number of clients, grace period)</param> /// <param name="resultClientConfigurations">Client configurations (packet rate, duration, etc.)</param> public void GrabResultSettings(StressTestSettings settings, StressTestOutgoingConfiguration resultClientConfigurations) { // Sets field texts accordingly brokerIpAddrInput.Text = settings.BrokerHost; brokerPortInput.Text = settings.BrokerPort.ToString(); numClients.Value = settings.NumClients; gracePeriod.Value = settings.GracePeriod; // Updates this clientConfigurations files with the clients from the ResultsDisplayForm clientConfigurations = resultClientConfigurations.Clients; // Clears out current comboBox clientSelection.Items.Clear(); // Updates combobox values to be accurate to the newly populated clientConfigurations amounts for (int i = 1; i <= clientConfigurations.Count; i++) { clientSelection.Items.Add($"Client {i}"); } // Sets default index to 0 for good measure. clientSelection.SelectedIndex = 0; }