private async Task <bool> PerformLineCoverageUpload(string originalTraceFilePath, string timestampParameter, string timestampValue, string url, MemoryStream stream) { using (HttpResponseMessage response = await HttpClientUtils.UploadMultiPart(client, url, "report", stream, "report.simple")) { if (response.IsSuccessStatusCode) { logger.Info("Successfully uploaded line coverage from {trace} with {parameter}={parameterValue} to {teamscale}", originalTraceFilePath, timestampParameter, timestampValue, server.ToString()); return(true); } else { string body = await response.Content.ReadAsStringAsync(); logger.Error("Upload of line coverage to {teamscale} failed with status code {statusCode}. This coverage is lost." + "\n{responseBody}", server.ToString(), response.StatusCode, body); return(false); } } }
/// <summary> /// Performs the upload asynchronously. /// </summary> /// <param name="filePath">Path to the file to upload.</param> /// <param name="version">The application version (read from a version assembly).</param> /// <returns>Whether the upload was successful.</returns> public async Task <bool> UploadAsync(string filePath, string version) { logger.Debug("Uploading {trace} with version {version} to {teamscale}", filePath, version, server.ToString()); string message = messageFormatter.Format(version); string encodedMessage = HttpUtility.UrlEncode(message); string encodedProject = HttpUtility.UrlEncode(server.Project); string encodedVersion = HttpUtility.UrlEncode(version); string encodedPartition = HttpUtility.UrlEncode(server.Partition); string url = $"{server.Url}/p/{encodedProject}/dotnet-ephemeral-trace-upload?version={encodedVersion}" + $"&message={encodedMessage}&partition={encodedPartition}&adjusttimestamp=true&movetolastcommit=true"; try { using (HttpResponseMessage response = await HttpClientUtils.UploadMultiPart(client, url, "report", filePath)) { if (response.IsSuccessStatusCode) { logger.Info("Successfully uploaded {trace} with version {version} to {teamscale}", filePath, version, server.ToString()); return(true); } else { string body = await response.Content.ReadAsStringAsync(); logger.Error("Upload of {trace} to {teamscale} failed with status code {statusCode}\n{responseBody}", filePath, server.ToString(), response.StatusCode, body); return(false); } } } catch (Exception e) { logger.Error(e, "Upload of {trace} to {teamscale} failed due to an exception", filePath, server.ToString()); return(false); } }