The class contain the function that will run the server and get back the results.
Here's the class
Public Class runserver
Private startserver As Diagnostics.ProcessStartInfo
Private serveroutput As Diagnostics.Process
Sub New()
startserver = New Diagnostics.ProcessStartInfo
With startserver
.FileName = "dev_appserver"
.UseShellExecute = False
.RedirectStandardOutput = True
.CreateNoWindow = True
End With
End Sub
Public Function run_server(ByVal file_path As String, ByVal port As Integer, ByVal sendmail As Boolean, ByVal cleardatastore As Boolean, ByVal timeout As Integer) As Boolean
Dim enable_sending_mail As String = ""
Dim clear_data_store As String = ""
If sendmail = True Then enable_sending_mail = " --enable_sendmail "
If cleardatastore = True Then clear_data_store = " --clear_datastore "
Dim Status As Boolean = False
Try
startserver.Arguments = ("dev_appserver.py --port=" & port & clear_data_store & enable_sending_mail & file_path)
serveroutput = Process.Start(startserver)
serveroutput.WaitForExit(timeout + 1000)
If serveroutput.HasExited Then
Dim Reply As String = serveroutput.StandardOutput.ReadToEnd
If Reply.ToLower.IndexOf("reply") > -1 Then
Status = True
End If
End If
Catch ex As InvalidOperationException
MessageBox.Show(ex.ToString)
Catch ex As System.ComponentModel.Win32Exception
MessageBox.Show(ex.ToString)
Catch ex As ObjectDisposedException
MessageBox.Show(ex.ToString)
Finally
If Not serveroutput Is Nothing Then
serveroutput.Dispose()
serveroutput = Nothing
End If
End Try
Return Status
End Function
End Class
Good? Ok, if you have any suggestion or improvement for the code, then let me know.
No comments:
Post a Comment