<commit_before>﻿/*
 * Copyright (c) <NAME>.  All rights reserved.
 * see license.txt
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BrockAllen.MembershipReboot
{
    public class EmailEventHandler
    {
        IMessageFormatter messageFormatter;
        IMessageDelivery messageDelivery;
        public EmailEventHandler(IMessageFormatter messageFormatter, IMessageDelivery messageDelivery)
        {
            this.messageFormatter = messageFormatter;
            this.messageDelivery = messageDelivery;
        }

        public virtual void Process(UserAccountEvent evt, string email = null)
        {
            var msg = this.messageFormatter.Format(evt);
            if (msg != null)
            {
                msg.To = email ?? evt.Account.Email;
                this.messageDelivery.Send(msg);
            }
        }
    }

    public class EmailAccountCreatedEventHandler
        : EmailEventHandler, IEventHandler<AccountCreatedEvent>
    {
        public EmailAccountCreatedEventHandler(IMessageFormatter messageFormatter, IMessageDelivery messageDelivery)
            : base(messageFormatter, messageDelivery)
        {
        }

        public void Handle(AccountCreatedEvent evt)
        {
            Process(evt);
        }
    }

    public class EmailAccountEventsHandler :
        EmailEventHandler,
        IEventHandler<AccountVerifiedEvent>,
        IEventHandler<PasswordResetRequestedEvent>,
        IEventHandler<PasswordChangedEvent>,
        IEventHandler<UsernameReminderRequestedEvent>,
        IEventHandler<AccountClosedEvent>,
        IEventHandler<UsernameChangedEvent>,
        IEventHandler<EmailChangeRequestedEvent>,
        IEventHandler<EmailChangedEvent>
    {
        public EmailAccountEventsHandler(IMessageFormatter messageFormatter, IMessageDelivery messageDelivery)
            : base(messageFormatter, messageDelivery)
        {
        }
<commit_msg>add overloaded ctor to use smtp delivery by default<commit_after>﻿/*
 * Copyright (c) <NAME>.  All rights reserved.
 * see license.txt
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BrockAllen.MembershipReboot
{
    public class EmailEventHandler
    {
        IMessageFormatter messageFormatter;
        IMessageDelivery messageDelivery;

        public EmailEventHandler(IMessageFormatter messageFormatter)
            : this(messageFormatter, new SmtpMessageDelivery())
        {
        }
        
        public EmailEventHandler(IMessageFormatter messageFormatter, IMessageDelivery messageDelivery)
        {
            if (messageFormatter == null) throw new ArgumentNullException("messageFormatter");
            if (messageDelivery == null) throw new ArgumentNullException("messageDelivery");

            this.messageFormatter = messageFormatter;
            this.messageDelivery = messageDelivery;
        }

        public virtual void Process(UserAccountEvent evt, string email = null)
        {
            var msg = this.messageFormatter.Format(evt);
            if (msg != null)
            {
                msg.To = email ?? evt.Account.Email;
                this.messageDelivery.Send(msg);
            }
        }
    }

    public class EmailAccountCreatedEventHandler
        : EmailEventHandler, IEventHandler<AccountCreatedEvent>
    {
        public EmailAccountCreatedEventHandler(IMessageFormatter messageFormatter)
            : base(messageFormatter)
        {
        }
        
        public EmailAccountCreatedEventHandler(IMessageFormatter messageFormatter, IMessageDelivery messageDelivery)
            : base(messageFormatter, messageDelivery)
        {
        }

        public void Handle(AccountCreatedEvent evt)
        {
            Process(evt);
        }
    }

    public class EmailAccountEventsHandler :
        EmailEventHandler,
        IEventHandler<AccountVerifiedEvent>,
        IEventHandler<PasswordResetRequestedEvent>,
        IEventHandler<PasswordChangedEvent>,
        IEventHandler<UsernameReminderRequestedEvent>,
        IEventHandler<AccountClosedEvent>,
        IEventHandler<UsernameChangedEvent>,
        IEventHandler<EmailChangeRequestedEvent>,
        IEventHandler<EmailChangedEvent>
    {
        public EmailAccountEventsHandler(IMessageFormatter messageFormatter)
            : base(messageFormatter)
        {
        }
        public EmailAccountEventsHandler(IMessageFormatter messageFormatter, IMessageDelivery messageDelivery)
            : base(messageFormatter, messageDelivery)
        {
        }

{'fraction_non_alphanumeric': 0.06570753704101352, 'fraction_numerical': 0.0, 'mean_word_length': 2.6333853354134167, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '7593833', 'n_tokens_mistral': 1084, 'n_tokens_neox': 1108, 'n_words': 216}