mirror of
https://github.com/fergalmoran/podnoms.git
synced 2025-12-26 11:17:47 +00:00
Boilerplate added
This commit is contained in:
@@ -2,16 +2,16 @@ using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace PodNoms.Api.Utils {
|
||||
|
||||
public static class ResourceReader {
|
||||
public static string ReadResource(string resourceName, ILogger logger) {
|
||||
public static async Task<string> ReadResource(string resourceName) {
|
||||
string ret = string.Empty;
|
||||
var assembly = Assembly.GetEntryAssembly();
|
||||
if (assembly != null) {
|
||||
logger.LogDebug($"Entry Assembly: {assembly.Location}");
|
||||
var resourceStream = assembly.GetManifestResourceStream($"PodNoms.Api.Resources.{resourceName}");
|
||||
if (resourceStream != null) {
|
||||
using (var reader = new StreamReader(resourceStream, Encoding.UTF8)) {
|
||||
@@ -23,16 +23,14 @@ namespace PodNoms.Api.Utils {
|
||||
try {
|
||||
using (StreamReader sr = new StreamReader(File.Open($"/app/Resources/{resourceName}", FileMode.Open))) {
|
||||
// Read the stream to a string, and write the string to the console.
|
||||
string data = sr.ReadToEnd();
|
||||
string data = await sr.ReadToEndAsync();
|
||||
return data;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.LogError($"Resource {resourceName} not found in assembly {assembly.Location}");
|
||||
logger.LogError($"{ex.Message}");
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.LogError("Unable to get executing assembly");
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user