Boilerplate added

This commit is contained in:
Fergal Moran
2018-05-02 22:17:22 +01:00
parent 5c51c531f1
commit 15f681254b
11 changed files with 101 additions and 9 deletions

View File

@@ -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;
}
}