public Task StartListening() { try { _Client = _Parent.CreateHttpClient(); _Client.Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite); var request = new HttpRequestMessage(HttpMethod.Get, _Parent.BaseUrl.WithTrailingSlash() + "v1/invoices/subscribe"); _Parent._Authentication.AddAuthentication(request); _ListenLoop = ListenLoop(request); } catch { Dispose(); } return(Task.CompletedTask); }
public async void StartListening() { var urlBuilder = new StringBuilder(); urlBuilder.Append(_Parent.BaseUrl).Append("/v1/invoices/subscribe"); try { using (var client = _Parent.CreateHttpClient()) { client.Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite); var request = new HttpRequestMessage(HttpMethod.Get, urlBuilder.ToString()); using (var response = await client.SendAsync( request, HttpCompletionOption.ResponseHeadersRead, _Cts.Token)) { using (var body = await response.Content.ReadAsStreamAsync()) using (var reader = new StreamReader(body)) { while (!_Cts.IsCancellationRequested) { string line = await reader.ReadLineAsync().WithCancellation(_Cts.Token); if (line != null && line.StartsWith("{\"result\":", StringComparison.OrdinalIgnoreCase)) { var invoiceString = JObject.Parse(line)["result"].ToString(); LnrpcInvoice parsedInvoice = _Parent.Deserialize <LnrpcInvoice>(invoiceString); await _Invoices.Writer.WriteAsync(ConvertLndInvoice(parsedInvoice)); } } } } } } catch when(_Cts.IsCancellationRequested) { } finally { _Stopped.Set(); } }
public async Task StartListening() { try { _Client = _Parent.CreateHttpClient(); _Client.Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite); var request = new HttpRequestMessage(HttpMethod.Get, _Parent.BaseUrl.WithTrailingSlash() + "v1/invoices/subscribe"); _Parent._Authentication.AddAuthentication(request); _Response = await _Client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, _Cts.Token); _Body = await _Response.Content.ReadAsStreamAsync(); _Reader = new StreamReader(_Body); _ListenLoop = ListenLoop(); } catch { Dispose(); } }
public async Task StartListening() { try { _Client = _Parent.CreateHttpClient(); _Client.Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite); var request = new HttpRequestMessage(HttpMethod.Get, _Parent.BaseUrl.WithTrailingSlash() + "v1/invoices/subscribe"); _Response = await _Client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, _Cts.Token); _Body = await _Response.Content.ReadAsStreamAsync(); _Reader = new StreamReader(_Body); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed ListenLoop(); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } catch { _Stopped.Set(); Dispose(); } }
internal HttpClient CreateHttpClient() { return(LndSwaggerClient.CreateHttpClient(_LndSettings)); }