public async Task End() { try { HttpRetryHelper httpRetryHelper = new HttpRetryHelper(RetryAttempts); await httpRetryHelper.Invoke(async() => { await EndPage().ConfigureAwait(false); }); } finally { Directory.Delete(pagesFolder, true); } }
public async Task Log(string message) { if (!string.IsNullOrEmpty(message) && message.Length > 1024) { Console.WriteLine("Web console line is more than 1024 chars, truncate to first 1024 chars"); message = $"{message.Substring(0, 1024)}..."; } var line = $"{DateTime.UtcNow:O} {message}"; HttpRetryHelper httpRetryHelper = new HttpRetryHelper(RetryAttempts); await httpRetryHelper.Invoke(async() => { await taskClient.AppendTimelineRecordFeedAsync(new List <string> { line }).ConfigureAwait(false); await LogPage(line).ConfigureAwait(false); }); }
private static async Task UpdateCheckSuiteResult( string accountUrl, string authToken, Guid projectId, Guid checkSuiteId, bool succeeded, string message, ILogger log, TaskLogger taskLogger, IDictionary <string, string> variables) { using (var httpClient = new HttpClient()) { string authTokenString = string.Format("{0}:{1}", "", authToken); string base64AuthString = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(authTokenString)); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", base64AuthString); HttpRetryHelper httpRetryHelper = new HttpRetryHelper(NumberOfHttpRetries); var checkSuiteUpdate = new Dictionary <string, dynamic>(); dynamic checkRunResult = new { status = succeeded ? "approved" : "rejected", resultMessage = message }; checkSuiteUpdate.Add(checkSuiteId.ToString(), checkRunResult); try { var updatedCheckSuiteBuffer = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(checkSuiteUpdate)); var updatedCheckByteContent = new ByteArrayContent(updatedCheckSuiteBuffer); updatedCheckByteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var updateCheckRunUrl = string.Format("{0}/{1}/_apis/pipelines/checks/runs/{2}?api-version=5.0", accountUrl, projectId, checkSuiteId); CommonUtilities.LogInformation(string.Format("Invoking {0} to post current check status", updateCheckRunUrl), log, taskLogger, variables, null); var updateCheckSuiteResponse = await httpRetryHelper.Invoke(async() => await httpClient.PostAsync(updateCheckRunUrl, updatedCheckByteContent)); } catch (Exception e) { await taskLogger?.Log($"Failed to fetch update check status with error message : {e.Message}"); CommonUtilities.LogInformation($"Error stack: {e.ToString()}", log, taskLogger, variables, null); } } }