Introduction
This dialog enables user to submit various types of bugs with build in validation. The submitted information is then sent to a webservice.
Background
I have a few small applications that I developed to improve my coding knowledge. An easy way for users to submit feedback on my applications and report bugs would be very useful in all of them. I created this dialog for this purpose, while keeping in mind that it should be stable, user friendly, and very easy to implement in any of my applications.
Using the Code
The dialog itself can be integrated without much work into your application, but the webservice will require some attention.
Here you have a simple example of showing the dialog:
With New BugSubmitter
.SubmitterFile = "BN+converter-pro.php"
.SubmitterPath = "http://service.bn2vs.com/bugs"
.ApplicationVersion = GetAppVersion("[M].[m].[b].[r]")
.ShowDialog()
End With
GetAppVersion
is a simple sub
that returns the application version formatted as a string
. You can also manually get the version data or use a static
value.
Public Function GetAppVersion(Optional ByVal format As String = _
"v[M].[m].[b]") As String
With My.Application.Info
GetAppVersion = format.Replace("[M]", .Version.Major.ToString)
GetAppVersion = GetAppVersion.Replace("[m]", .Version.Minor.ToString)
GetAppVersion = GetAppVersion.Replace("[b]", .Version.Build.ToString)
GetAppVersion = GetAppVersion.Replace("[r]", .Version.Revision.ToString)
End With
End Function
That's all the code you need to display the dialog! Now let's have a closer look at some of the properties.
Before the bug report is submitted, the information is validated. This can be either done with an error provider when the user hits the submit button, or with live validation that will only enable the submit button when all fields are valid.
Public Property UseErrorProvider() As Boolean
Get
Return m_useErrorProvider
End Get
Set(ByVal value As Boolean)
m_useErrorProvider = value
End Set
End Property
The dialog has some events related to the submission progress, but you don't need to bother about these in most cases. There are three steps in the submission progress:
- Creation of the bug report (see screenshot at the top of this article)
- Submission
- Success screen (see screenshot underneath)
Every state will be clearly indicated to the user.
Now you can work with the dialog and understand how it works. Let's have a look at the webservice.
The Webservice
In my applications, I have chosen to use a PHP webservice that generates an email with the submitted data and then sends it over to my inbox. The example here follows the same principle, but keep in mind you can handle the submitted data any way you want, like for example storing it in a database. Also note you can use ASP or any other server script to write the webservice in.
This is a little script I created to easily construct multiple email webservices for different applications:
<?php
if (empty($_GET['type']) || empty($_GET['description']) ||
empty($_GET['version'])) die("Hack attempt");
$type = $_GET['type'];
$description = str_replace("[amp]", "&", $_GET['description']);
$email = strlen($_GET['email']) > 0 ? $_GET['email'] : "None provided";
$version = $_GET['version'];
require_once '../includes/phpMailer/class.phpmailer.php';
$mail = new PHPMailer();
$mail->From = "bug-report@your-server.com";
$mail->FromName = "Bug reporter @ your-server.com";
$body = "
<table border='1' width='100%'>
<tr bgcolor='gray'>
<td colspan='2'><u>Bug report for $app_name</u></td>
</tr>
<tr><td width='200'>Application version:</td><td>$version</td></tr>
<tr><td>Bug type:</td><td>$type</td></tr>
<tr><td>Bug description:</td><td>$description</td></tr>
<tr><td>User email:</td><td>$email</td></tr>
<tr bgcolor='gray'>
<td colspan='2'>Report send on ".date("F j, Y, g:i a")." (unix: ".time().")</td>
</tr>
</table>
";
$mail->Subject = "$mail_subject $type";
$mail->Body = $body;
$mail->AltBody = "Your client does not support html emails. Data cannot be accessed.";
$mail->AddAddress("your-mail@your-server.com", "yourName");
if ($mail->Send()) {
echo "Mail send successfully.<br />\n\n\n\n\n\n\n\n";
echo $body;
}
else {
echo "Error sending mail. ".$mail->ErrorInfo;
}
?>
A mail sent by this script will look similar to this one:
Now only a few lines of code are needed for each BugSubmitter
:
<?php
$app_name = "BugSubmitter demo application";
$mail_subject = "BUG REPORT: BugSubmitter demo:";
require_once 'common.php';
?>
Note that in this example, I assume you are either using this webservice only once, or sending all mails to the same address. If this is not the case, you can easily add a new variable in your-application-webservice.php, before you include common.php, containing the address for that webservice, and then add it to the mailer address list in common.php.
Points of Interest
This was a nice exercise for me in creating a .NET dialog that loosely communicates with a webservice. I'm very happy with the result, and I'm now using this dialog in all of my .NET applications. I also got quite some positive feedback from people, and the request to better document this dialog, which prompted me to create this article.
History
- April 28th 2009: Published article on The Code Project with webservice example
- April 13th 2009: Published version 1.0.0
References
- Dutch support for this class can be found here.