/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BT_Add_Click(object sender, EventArgs e) { var contentTypeObj = (IContentTypeState)(this.cb_ContentType.SelectedItem as ComboboxItem).Value; string contentType = contentTypeObj.UsedContentType; var tmpRecord = new SslStripRecord(this.tb_HostName.Text.Trim(), contentType); try { this.AddRecord(tmpRecord); } catch (Exception ex) { var msg = $"Error occurred while adding SslStrip record for host name \"{this.tb_HostName.Text}\": {ex.Message}"; this.pluginProperties.HostApplication.LogMessage($"{this.Config.PluginName}: {ex.Message}"); MessageBox.Show(msg, "Can't add SslStrip record", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void AddRecord(SslStripRecord record) { if (this.InvokeRequired) { this.BeginInvoke(new AddRecordDelegate(this.AddRecord), new object[] { record }); return; } if (record == null) { return; } // Update DataGridView this.dgv_SslStrippingTargets.SuspendLayout(); lock (this) { // Verify if record already exists foreach (SslStripRecord tmpRecord in this.sslStripRecords) { if (tmpRecord.HostName == record.HostName && tmpRecord.ContentType == record.ContentType) { throw new Exception("A record with this host name already exists."); } } // Verify if HostName is correct if (!Regex.Match(record.HostName, @"^[\w\d\-_\.\*]+\.[\*\w]{1,10}$", RegexOptions.IgnoreCase).Success) { throw new Exception("Something is wrong with the host name."); } // Verify if ContentType is correct if (!Regex.Match(record.ContentType, @"^[\w\d\-_]+\/[\w\d\-_]+$", RegexOptions.IgnoreCase).Success) { throw new Exception("Something is wrong with the content type definition."); } this.sslStripRecords.Insert(0, record); this.dgv_SslStrippingTargets.ResumeLayout(); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TB_Host_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { e.SuppressKeyPress = true; IContentTypeState contentTypeObj = (IContentTypeState)(this.cb_ContentType.SelectedItem as ComboboxItem).Value; string contentType = contentTypeObj.UsedContentType; SslStripRecord tmpRecord = new SslStripRecord(this.tb_HostName.Text.Trim(), contentType); try { this.AddRecord(tmpRecord); } catch (Exception ex) { this.pluginProperties.HostApplication.LogMessage($"{this.Config.PluginName}: {ex.Message}"); MessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }