Skip to content

Commit

Permalink
Version 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wduffy committed Jun 10, 2011
1 parent 4419ebf commit d64e39e
Show file tree
Hide file tree
Showing 104 changed files with 35,471 additions and 251 deletions.
19 changes: 19 additions & 0 deletions Core/Abstractions/FileReader.cs
@@ -0,0 +1,19 @@
using System.IO;

namespace RazorMail
{
internal class FileReader : IFileReader
{

public bool Exists(string path)
{
return File.Exists(path);
}

public Stream OpenRead(string path)
{
return File.OpenRead(path);
}

}
}
10 changes: 10 additions & 0 deletions Core/Abstractions/IFileReader.cs
@@ -0,0 +1,10 @@
using System.IO;

namespace RazorMail
{
public interface IFileReader
{
bool Exists(string path);
Stream OpenRead(string path);
}
}
8 changes: 7 additions & 1 deletion Core/Core.csproj
Expand Up @@ -47,7 +47,13 @@
<Reference Include="System.XML" />
</ItemGroup>
<ItemGroup>
<Compile Include="Extensions\CollectionExtensions.cs" />
<Compile Include="Templates\TemplateCollection.cs" />
<Compile Include="Extensions\MailAddressCollectionExtensions.cs" />
<Compile Include="Templates\ITemplateFactory.cs" />
<Compile Include="Templates\TemplateFactory.cs" />
<Compile Include="Abstractions\FileReader.cs" />
<Compile Include="Abstractions\IFileReader.cs" />
<Compile Include="Extensions\IEnumerableExtensions.cs" />
<Compile Include="Parsers\HtmlAgilityPackParser.cs" />
<Compile Include="Parsers\IParser.cs" />
<Compile Include="IRazorMailSender.cs" />
Expand Down
@@ -1,17 +1,17 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Linq;

namespace RazorMail.Extensions
namespace RazorMail
{
internal static class CollectionExtensions
internal static class IEnumerableExtensions
{

/// <summary>
/// Performs the specified action on each element of the source
/// </summary>
/// <remarks></remarks>
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action) where T : class
internal static void ForEach<T>(this IEnumerable<T> source, Action<T> action) where T : class
{
if (source != null)
foreach (T element in source)
Expand All @@ -29,4 +29,4 @@ internal static bool IsEmpty<T>(this IEnumerable<T> s)
}

}
}
}
18 changes: 18 additions & 0 deletions Core/Extensions/MailAddressCollectionExtensions.cs
@@ -0,0 +1,18 @@
using System.Net.Mail;

namespace RazorMail
{
public static class MailAddressCollectionExtensions
{
/// <summary>
/// Adds an email address to the end of the System.Net.Mail.MailAddressCollection
/// </summary>
/// <param name="source"></param>
/// <param name="address">A System.String that contains an e-mail address.</param>
/// <param name="displayName">A System.String that contains the display name associated with address.</param>
public static void Add(this MailAddressCollection source, string address, string displayName)
{
source.Add(new MailAddress(address, displayName));
}
}
}
18 changes: 8 additions & 10 deletions Core/Parsers/HtmlAgilityPackParser.cs
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using HtmlAgilityPack;
using RazorMail.Extensions;

namespace RazorMail.Parsers
{
Expand All @@ -26,7 +24,7 @@ public HtmlAgilityPackParser(Uri uri)
Parsers.Add(ReplaceBrElements);
}

public virtual string BaseUrls(string html)
public string BaseUrls(string html)
{
var doc = new HtmlDocument();
doc.OptionFixNestedTags = true;
Expand All @@ -39,7 +37,7 @@ public virtual string BaseUrls(string html)
return doc.DocumentNode.InnerHtml;
}

public virtual string StripHtml(string html)
public string StripHtml(string html)
{
var doc = new HtmlDocument();
doc.OptionFixNestedTags = true;
Expand All @@ -50,7 +48,7 @@ public virtual string StripHtml(string html)
return Regex.Replace(doc.DocumentNode.InnerText, "[\r\n]{3,}", "\r\n\r\n");
}

protected virtual void ReplaceHrefElements(HtmlNode root)
protected void ReplaceHrefElements(HtmlNode root)
{
root.SelectNodes("//a[@href]").ForEach(x =>
{
Expand All @@ -66,30 +64,30 @@ protected virtual void ReplaceHrefElements(HtmlNode root)
});
}

protected virtual void RemoveUnwantedElements(HtmlNode root)
protected void RemoveUnwantedElements(HtmlNode root)
{
root.SelectNodes("//style|//img|//comment()").ForEach(x => x.Remove());
}

protected virtual void RemoveWhitespace(HtmlNode root)
protected void RemoveWhitespace(HtmlNode root)
{
root.DescendantNodes().ForEach(x => x.InnerHtml = Regex.Replace(x.InnerHtml, "\\s+", " "));
root.DescendantNodes().ForEach(x => x.InnerHtml = x.InnerHtml.Trim());
}

protected virtual void AppendBrToBlockElements(HtmlNode root)
protected void AppendBrToBlockElements(HtmlNode root)
{
var blocks = new[] { "//address", "//blockquote", "//center", "//div", "//dl", "//fieldset", "//h1", "//h2", "//h3", "//h4", "//h5", "//h6", "//hr", "//li", "//p", "//pre" };
root.SelectNodes(string.Join("|", blocks)).ForEach(x => x.AppendChild(HtmlTextNode.CreateNode("<br />")));
}

protected virtual void AppendTableDividers(HtmlNode root)
protected void AppendTableDividers(HtmlNode root)
{
root.SelectNodes("//td[position()<last()]|//th[position()<last()]").ForEach(x => { if (!string.IsNullOrWhiteSpace(x.InnerText)) x.AppendChild(HtmlTextNode.CreateNode(", ")); });
root.SelectNodes("//td[last()]|//th[last()]").ForEach(x => x.AppendChild(HtmlTextNode.CreateNode("<br />")));
}

protected virtual void ReplaceBrElements(HtmlNode root)
protected void ReplaceBrElements(HtmlNode root)
{
root.SelectNodes("//br").ForEach(x => x.ParentNode.ReplaceChild(HtmlTextNode.CreateNode("\r\n"), x));
}
Expand Down
6 changes: 1 addition & 5 deletions Core/Parsers/IParser.cs
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace RazorMail.Parsers
{
public interface IParser
Expand Down
12 changes: 7 additions & 5 deletions Core/Properties/AssemblyInfo.cs
Expand Up @@ -6,13 +6,15 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("RazorMail")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("RazorMail allows sending of email using the razor template engine outwith the context of an MVC project, keeping the concerns of email generation within your domain rather than the UI.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCompany("William Duffy Software")]
[assembly: AssemblyProduct("RazorMail")]
[assembly: AssemblyCopyright("Copyright © 2011")]
[assembly: AssemblyCopyright("Copyright © 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] // Namespace of Moq Proxy Generator
[assembly: InternalsVisibleTo("RazorMail.Tests")] // Namespace of Unit Tests

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
Expand All @@ -32,5 +34,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]
15 changes: 12 additions & 3 deletions Core/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Core/Properties/Resources.resx
Expand Up @@ -117,15 +117,18 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ExceptionNoBody" xml:space="preserve">
<value>RazorMail: The body cannot be null or empty.</value>
<data name="ExceptionArgumentNullOrEmpty" xml:space="preserve">
<value>RazorMail: Parameter cannot be null or empty.</value>
</data>
<data name="ExceptionNoRecipient" xml:space="preserve">
<value>RazorMail: At least one recipient must be specified before sending email.</value>
</data>
<data name="ExceptionNoSubject" xml:space="preserve">
<value>RazorMail: The subject cannot be null or empty.</value>
</data>
<data name="ExceptionNoTemplates" xml:space="preserve">
<value>RazorMail: At least one template must be specified before sending email.</value>
</data>
<data name="TestingRecipientName" xml:space="preserve">
<value>Testing Recipient</value>
</data>
Expand Down

0 comments on commit d64e39e

Please sign in to comment.