-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBodyRetriever.cs
39 lines (35 loc) · 1.25 KB
/
BodyRetriever.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using AdfsMfa.Shared.Languages;
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Text;
namespace Samples.Core.SingleUseCodes.Emails
{
internal class BodyRetriever
{
public static string Execute(string singleUseCode)
{
return GetTemplate().Replace("{code}", singleUseCode);
}
private static string GetTemplate()
{
// ReSharper disable once PossibleNullReferenceException
var resourceName = MethodBase.GetCurrentMethod().DeclaringType.Namespace + "." +
$"EmailBody.html";
var assembly = Assembly.GetExecutingAssembly();
using (var stream = assembly.GetManifestResourceStream(resourceName))
{
if (stream == null)
{
Trace.TraceError($"Missing template: '{resourceName}'.");
throw new Exception($"Missing template: {resourceName}");
}
using (var streamReader = new StreamReader(stream, Encoding.GetEncoding("iso-8859-1")))
{
return streamReader.ReadToEnd();
}
}
}
}
}