<commit_before>﻿using System;
using System.IO;
using System.Net.Mail;
using System.Threading.Tasks;
using RazorEngine.Configuration;
using RazorEngine.Templating;

namespace RazorMailer.Core
{
    public class RazorMailerEngine : IDisposable
    {
        private readonly string _fromName;
        private readonly string _fromEmail;
        private readonly IEmailDispatcher _dispatcher;
        private readonly IRazorEngineService _service;

        /// <summary>
        /// Constructs a RazorMailerEngine instance responsible for converting Razor templates into strings only and can't be used to create or send MailMessages.
        /// N.B. As this class loads up templates from the file system, it should only be created once per instance of your application.
        /// </summary>
        /// <param name="templatePath">The path to load the Razor templates from.  e.g. @"email\templates".  The template's Build Action should be set to Content and the Copy to Output Directory flag set to Copy Always</param>
        public RazorMailerEngine(string templatePath) : this(templatePath, null, null, null)
        {
        }

        /// <summary>
        /// Constructs a RazorMailerEngine instance responsible for converting Razor templates into either a MailMessage or string.  This constructor defaults to the build in SmtpDispatcher that takes its settings from the <mailSettings></mailSettings> section within your application config file.
        /// N.B. As this class loads up templates from the file system, it should only be created once per instance of your application.
        /// </summary>
        /// <param name="templatePath">The path to load the Razor templates from.  e.g. @"email\templates".  The template's Build Action should be set to Content and the Copy to Output Directory flag set to Copy Always</param>
        /// <param name="fromEmail">The address the email is from. e.g. <EMAIL></param>
        /// <param name="fromName">The name the email is from. e.g. Your Site</param>
        public RazorMailerEngine(string templatePath, string fromEmail, string fromName) : this(templatePath, fromEmail, fromName, new SmtpDispatcher())
        {
        }

        /// <summary>
        /// Constructs a RazorMailerEngine instance responsible for converting Razor templates into either a MailMessage or string.
        /// N.B. As this class loads up templates from the file system, it should only be created once per instance of your application.
        /// </summary>
        /// <param name="templatePath">The path to load the Razor templates from.  e.g. @"email\templates".  The template's Build Action should be set to Content and the Copy to Output Directory flag set to Copy Always</param>
        /// <param name="fromEmail">The address the email is from. e.g. <EMAIL></param>
        /// <param name="fromName">The name the email is from. e.g. Your Site</param>
        /// <param name="dispatcher">The method by which to send the email.  Custom dispatchers can be implemented using the IEmailDispatcher interface</param>
        public RazorMailerEngine(string templatePath, string fromEmail, string fromName, IEmailDispatcher dispatcher)
        {
            _fromName = fromName;
            _fromEmail = fromEmail;
            _dispatcher = dispatcher;

            // Find templates in a web application
            var webPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin", templatePath);
            // Find templates from a unit test or console application
            var libraryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, templatePath);<commit_msg>More comment updates (#10)<commit_after>﻿using System;
using System.IO;
using System.Net.Mail;
using System.Threading.Tasks;
using RazorEngine.Configuration;
using RazorEngine.Templating;

namespace RazorMailer.Core
{
    /// <summary>
    /// The core RazorMailer engine responsible for converting Razor templates into MailMessages
    /// </summary>
    public class RazorMailerEngine : IDisposable
    {
        private readonly string _fromName;
        private readonly string _fromEmail;
        private readonly IEmailDispatcher _dispatcher;
        private readonly IRazorEngineService _service;

        /// <summary>
        /// Constructs a RazorMailerEngine instance responsible for converting Razor templates into strings only and can't be used to create or send MailMessages.
        /// <para />N.B. As this class loads up templates from the file system, it should only be created once per instance of your application.
        /// </summary>
        /// <param name="templatePath">The path to load the Razor templates from.  e.g. @"email\templates".  The template's Build Action should be set to Content and the Copy to Output Directory flag set to Copy Always</param>
        public RazorMailerEngine(string templatePath) : this(templatePath, null, null, null)
        {
        }

        /// <summary>
        /// Constructs a RazorMailerEngine instance responsible for converting Razor templates into either a MailMessage or string.  This constructor defaults to the build in SmtpDispatcher that takes its settings from the <mailSettings></mailSettings> section within your application config file.
        /// <para />N.B. As this class loads up templates from the file system, it should only be created once per instance of your application.
        /// </summary>
        /// <param name="templatePath">The path to load the Razor templates from.  e.g. @"email\templates".  The template's Build Action should be set to Content and the Copy to Output Directory flag set to Copy Always</param>
        /// <param name="fromEmail">The address the email is from. e.g. <EMAIL></param>
        /// <param name="fromName">The name the email is from. e.g. Your Site</param>
        public RazorMailerEngine(string templatePath, string fromEmail, string fromName) : this(templatePath, fromEmail, fromName, new SmtpDispatcher())
        {
        }

        /// <summary>
        /// Constructs a RazorMailerEngine instance responsible for converting Razor templates into either a MailMessage or string.
        /// <para />N.B. As this class loads up templates from the file system, it should only be created once per instance of your application.
        /// </summary>
        /// <param name="templatePath">The path to load the Razor templates from.  e.g. @"email\templates".  The template's Build Action should be set to Content and the Copy to Output Directory flag set to Copy Always</param>
        /// <param name="fromEmail">The address the email is from. e.g. <EMAIL></param>
        /// <param name="fromName">The name the email is from. e.g. Your Site</param>
        /// <param name="dispatcher">The method by which to send the email.  Custom dispatchers can be implemented using the IEmailDispatcher interface</param>
        public RazorMailerEngine(string templatePath, string fromEmail, string fromName, IEmailDispatcher dispatcher)
        {
            _fromName = fromName;
            _fromEmail = fromEmail;
            _dispatcher = dispatcher;

            // Find templates in a web application
            var webPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin", templatePath);
            // Find templates from a unit test or console application
            var libraryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, templatePath);
{'fraction_non_alphanumeric': 0.08132489565100309, 'fraction_numerical': 0.00026928773394371884, 'mean_word_length': 2.9637139807897546, 'pattern_counts': {'":': 0, '<': 60, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6601542', 'n_tokens_mistral': 1837, 'n_tokens_neox': 1786, 'n_words': 788}