Skip to content
This repository has been archived by the owner on Jul 3, 2020. It is now read-only.

Commit

Permalink
Changed Templates to Embedded Resources.
Browse files Browse the repository at this point in the history
  • Loading branch information
bofirial committed Jun 12, 2017
1 parent c09f2e5 commit b9f9388
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
18 changes: 12 additions & 6 deletions Melody49Notifier/Melody49Notifier.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
<ItemGroup>
<None Remove="EmailShowingTemplate.html" />
<None Remove="EmailTemplate.html" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="EmailShowingTemplate.html">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="EmailTemplate.html">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="HtmlAgilityPack" Version="1.4.9.5" />
<PackageReference Include="Microsoft.Azure.WebJobs" Version="2.1.0-beta1" />
Expand All @@ -15,17 +27,11 @@
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<None Update="EmailShowingTemplate.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="EmailTemplate.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
16 changes: 14 additions & 2 deletions Melody49Notifier/Notification/NotificationEmailGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Melody49Notifier.Models;
using Microsoft.Azure.WebJobs.Host;
using System.IO;
using System.Reflection;

namespace Melody49Notifier.Notification
{
Expand All @@ -20,8 +21,8 @@ public NotificationEmailGenerator(TraceWriter log)

public string CreateFromTemplate(TheaterSchedule currentTheaterSchedule)
{
string email = File.ReadAllText("EmailTemplate.html");
string showingTemplate = File.ReadAllText("EmailShowingTemplate.html");
string email = GetEmbeddedResourceText("Melody49Notifier.EmailTemplate.html");
string showingTemplate = GetEmbeddedResourceText("Melody49Notifier.EmailShowingTemplate.html");

string showings = string.Empty;

Expand All @@ -42,5 +43,16 @@ public string CreateFromTemplate(TheaterSchedule currentTheaterSchedule)

return email;
}

private static string GetEmbeddedResourceText(string resourceName)
{
Assembly assembly = Assembly.GetExecutingAssembly();

using (Stream stream = assembly.GetManifestResourceStream(resourceName))
using (StreamReader reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}
}
}

0 comments on commit b9f9388

Please sign in to comment.