public async Task <string> ReadFromDocumentAsync(HttpRequestMessage requestMessage) { UtilityFunctions.CheckArgumentNull(requestMessage, nameof(requestMessage)); // Mock reading from an HTTP source. return(await ReadFromFile(requestMessage.RequestUri.OriginalString)); }
public async Task <string> ReadFromFile(string filePathSource) { UtilityFunctions.CheckArgumentNull(filePathSource, nameof(filePathSource)); // Prepend the root directory notation since we're reading off of a relative folder location filePathSource = Path.Combine(Environment.CurrentDirectory, filePathSource); if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) // path separator kinds are mixed on linux platforms because of the configuration files, which leads to failures { filePathSource = filePathSource.Replace('\\', Path.DirectorySeparatorChar); } using StreamReader streamReader = new StreamReader(filePathSource); return(await streamReader.ReadToEndAsync()); }
/// <summary> /// Reads the contents of a document from an HTTP source. /// </summary> /// <param name="requestMessage">The HTTP request message.</param> /// <returns>The document contents from the HTTP source.</returns> public async Task <string> ReadFromDocumentAsync(HttpRequestMessage requestMessage) { UtilityFunctions.CheckArgumentNull(requestMessage, nameof(requestMessage)); requestMessage.Method ??= HttpMethod.Get; // default is GET using var httpResponseMessage = await _httpClient?.SendAsync(requestMessage); if (httpResponseMessage == null) { throw new InvalidOperationException("Invalid HttpRequestMessage provided"); } return(await httpResponseMessage.Content?.ReadAsStringAsync()); }