Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Sub InitializeNgrok(ct As CancellationToken)
- Dim oldngrokproc As New List(Of Process)(Process.GetProcessesByName("ngrok"))
- oldngrokproc.ForEach(Sub(p) p.Kill())
- ngrokurl = ""
- Dim psi As New ProcessStartInfo()
- psi.FileName = "ngrok.exe"
- psi.CreateNoWindow = True
- psi.UseShellExecute = False
- psi.RedirectStandardError = True
- psi.RedirectStandardOutput = True
- ngrokproc = New Process
- ngrokproc.StartInfo = psi
- While Not ct.IsCancellationRequested
- Try
- psi.Arguments = String.Format("http {0} -authtoken {1} -host-header=""localhost:{0}"" -log ""stdout""", webhookport, NgrokToken)
- ngrokproc.Start()
- Do
- Dim outputtask = ngrokproc.StandardOutput.ReadLineAsync
- Try
- outputtask.Wait(ct)
- Catch ex As OperationCanceledException
- Exit While
- End Try
- Dim Line = outputtask.Result
- If Not String.IsNullOrEmpty(Line) Then
- Debug.WriteLine(Line)
- Dim lineargs = ParseArguments(Line) '.Split({" "}, StringSplitOptions.RemoveEmptyEntries)
- If lineargs.Length > 6 AndAlso lineargs(2) = "msg=""started tunnel""" AndAlso lineargs(6).StartsWith("url=https") Then Bot.SetWebhookAsync(lineargs(6).Substring(4))
- End If
- Loop Until ngrokproc.HasExited Or ct.IsCancellationRequested
- If ngrokproc.ExitCode <> 0 Then
- Debug.WriteLine("ngrok closed suddenly")
- End If
- Catch ex As Exception
- Debug.WriteLine(ex.Message)
- Exit While
- End Try
- End While
- If Not ngrokproc.HasExited Then ngrokproc.Kill()
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement