// Disable "The variable ‘x’ is assigned but its value is never used": #pragma warning disable 219 // ReSharper disable NotAccessedVariable // ReSharper disable RedundantAssignment private void OnMakingApiRequest(object sender, ApiRequestEventArgs e) { bool hasContent; string content; string[] multipartContent; if (e.HttpContent == null) { hasContent = false; } else if (e.HttpContent is MultipartFormDataContent multipartFormDataContent) { hasContent = true; multipartContent = multipartFormDataContent .Select(c => c is StringContent ? $"{c.Headers}\n{c.ReadAsStringAsync().Result}" : c.Headers.ToString() ) .ToArray(); } else { hasContent = true; content = e.HttpContent.ReadAsStringAsync().Result; } /* Debugging Hint: set breakpoints with conditions here in order to investigate the HTTP request values. */ }
private void OnApiSearchFinished(object sender, ApiRequestEventArgs e) { //improve this by detecting the right search XDocument document = e.Document; if (first) { NotifyRequestBoardgameSearchCompleted(document); } else { NotifyRequestBoardgameCompleted(document); } first = false; }
private void OnMakingApiRequest(object sender, ApiRequestEventArgs e) { string content; string[] multipartContent; if (e.HttpContent is MultipartFormDataContent multipartFormDataContent) { multipartContent = multipartFormDataContent .Select(c => c is StringContent ? $"{c.Headers}\n{c.ReadAsStringAsync().Result}" : c.Headers.ToString() ) .ToArray(); } else { content = e.HttpContent.ReadAsStringAsync().Result; } }
// Disable "The variable ‘x’ is assigned but its value is never used": #pragma warning disable 219 // ReSharper disable NotAccessedVariable // ReSharper disable RedundantAssignment private async ValueTask OnMakingApiRequest( ITelegramBotClient botClient, ApiRequestEventArgs e, CancellationToken cancellationToken = default) { bool hasContent; string content; string[] multipartContent; if (e.HttpContent is null) { hasContent = false; } else if (e.HttpContent is MultipartFormDataContent multipartFormDataContent) { hasContent = true; var stringifiedFormContent = new List <string>(multipartFormDataContent.Count()); foreach (var formContent in multipartFormDataContent) { if (formContent is StringContent stringContent) { var stringifiedContent = await stringContent.ReadAsStringAsync(); stringifiedFormContent.Add(stringifiedContent); } else { stringifiedFormContent.Add(formContent.Headers.ToString()); } } multipartContent = stringifiedFormContent.ToArray(); } else { hasContent = true; content = await e.HttpContent.ReadAsStringAsync(); } /* Debugging Hint: set breakpoints with conditions here in order to investigate the HTTP request values. */ }
private static ValueTask Api_OnMakingApiRequest(ITelegramBotClient botClient, ApiRequestEventArgs args, CancellationToken cancellationToken = default(CancellationToken)) { var method = args.MethodName.ToLower(); if (method.StartsWith("getUpdate")) { Program.Log("Getting updates"); } if (method.StartsWith("send") || method.StartsWith("edit")) { MessagesSent++; } return(new ValueTask()); }
protected virtual async void On_MakingApiRequest(object?sender, ApiRequestEventArgs e) { }
private void PackageManager_ApiRequestUsed(object sender, ApiRequestEventArgs e) { RemainingRequests = e.Remaining; }