Advertisement
Guest User

Untitled

a guest
May 7th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.95 KB | None | 0 0
  1.     Private Sub InitializeNgrok(ct As CancellationToken)
  2.         Dim oldngrokproc As New List(Of Process)(Process.GetProcessesByName("ngrok"))
  3.         oldngrokproc.ForEach(Sub(p) p.Kill())
  4.  
  5.         ngrokurl = ""
  6.  
  7.         Dim psi As New ProcessStartInfo()
  8.         psi.FileName = "ngrok.exe"
  9.         psi.CreateNoWindow = True
  10.         psi.UseShellExecute = False
  11.         psi.RedirectStandardError = True
  12.         psi.RedirectStandardOutput = True
  13.         ngrokproc = New Process
  14.         ngrokproc.StartInfo = psi
  15.  
  16.  
  17.         While Not ct.IsCancellationRequested
  18.             Try
  19.                 psi.Arguments = String.Format("http {0} -authtoken {1} -host-header=""localhost:{0}"" -log ""stdout""", webhookport, NgrokToken)
  20.                 ngrokproc.Start()
  21.  
  22.                 Do
  23.                     Dim outputtask = ngrokproc.StandardOutput.ReadLineAsync
  24.  
  25.                     Try
  26.                         outputtask.Wait(ct)
  27.                     Catch ex As OperationCanceledException
  28.                         Exit While
  29.                     End Try
  30.  
  31.                     Dim Line = outputtask.Result
  32.                     If Not String.IsNullOrEmpty(Line) Then
  33.                         Debug.WriteLine(Line)
  34.                         Dim lineargs = ParseArguments(Line) '.Split({" "}, StringSplitOptions.RemoveEmptyEntries)
  35.                         If lineargs.Length > 6 AndAlso lineargs(2) = "msg=""started tunnel""" AndAlso lineargs(6).StartsWith("url=https") Then Bot.SetWebhookAsync(lineargs(6).Substring(4))
  36.                     End If
  37.                 Loop Until ngrokproc.HasExited Or ct.IsCancellationRequested
  38.  
  39.                 If ngrokproc.ExitCode <> 0 Then
  40.                     Debug.WriteLine("ngrok closed suddenly")
  41.                 End If
  42.  
  43.             Catch ex As Exception
  44.                 Debug.WriteLine(ex.Message)
  45.                 Exit While
  46.             End Try
  47.         End While
  48.  
  49.         If Not ngrokproc.HasExited Then ngrokproc.Kill()
  50.     End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement