Exemplo n.º 1
0
 public EmailTemplateModel(EmailTemplateId templateId, string subj, string html, string text)
 {
     this.TemplateId = templateId;
     this.Subject    = subj;
     this.Html       = html;
     this.Text       = text;
 }
Exemplo n.º 2
0
        public override int GetHashCode()
        {
            var hashCode = 1296822809;

            hashCode = hashCode * -1521134295 + EmailTemplateId.GetHashCode();
            hashCode = hashCode * -1521134295 + PartId.GetHashCode();
            return(hashCode);
        }
Exemplo n.º 3
0
        private async Task EnqueueEmail(EmailTemplateId id, string recipient, IReadOnlyDictionary <string, string> fields, params IEntity[] entities)
        {
            var template = await emailRepository.GetEmailTemplateAsync(id);

            Email email = template.CreateEmail(recipient, fields, entities);

            emailRepository.Add(email);
            await UnitOfWork.SaveAsync();
        }
Exemplo n.º 4
0
        public async Task <ResponseModel> ProcessTemplate(Guid userId, EmailTemplateId templateId, string to, Dictionary <string, string> parameters, params object[] items)
        {
            if (TryProcessTemplate(out EmailTemplateProcessor p, templateId, parameters, items))
            {
                SendEmailModel sem = new SendEmailModel(userId, to, p.Template.Subject, p.Template.Text);

                return(await this.DataManager.SendEmail(sem));
            }
            else
            {
                return(ResponseModel.Error(ResponseCode.Internal_UnhandledError, string.Join(Environment.NewLine, p.Errors)));
            }
        }
Exemplo n.º 5
0
 public Task <EmailTemplate> GetEmailTemplateAsync(EmailTemplateId id)
 {
     return(Context.EmailTemplates.FirstAsync(e => e.Id == (int)id));
 }
Exemplo n.º 6
0
 public EmailTemplateModel GetEmailTemplate(EmailTemplateId id) => _emailTemplates.TryGetValue(id, out EmailTemplateModel item) ? item : null;
Exemplo n.º 7
0
 public async Task <ResponseModel> ProcessTemplate(Guid userId, EmailTemplateId templateId, string to, params object[] items)
 => await ProcessTemplate(userId, templateId, to, null, items);
Exemplo n.º 8
0
        public bool TryProcessTemplate(out EmailTemplateProcessor processor, EmailTemplateId templateId, Dictionary <string, string> parameters, params object[] items)
        {
            var t = this.DataManager.GetEmailTemplate(templateId);

            processor = null;

            if (t == null)
            {
                processor = new EmailTemplateProcessor("No template found for: " + templateId.ToString());
            }
            else
            {
                var url = this.BaseUrl();

                if (parameters == null)
                {
                    parameters = new Dictionary <string, string>();
                }

                UserModel user = null;
                if (items != null && items.Length > 0)
                {
                    user = items.FirstOrDefault(c => c is UserModel) as UserModel;
                }

                //DisplayName is used in emails as a safety valve to identify who the user is...
                if (user != null)
                {
                    parameters.TryAdd("DisplayName", user.Name ?? string.Empty);
                }
                else
                {
                    parameters.TryAdd("DisplayName", "");
                }

                parameters.TryAdd("HomeUrl", url);
                parameters.TryAdd("LoginUrl", url + "login");
                parameters.TryAdd("SignupUrl", url + "signup");
                parameters.TryAdd("LogoUrl", url + "statics/logo.png");
                parameters.TryAdd("PhishingUrl", url + "phishing");

                //get the html containing the master layout for all emails
                //string layout = string.Copy( this.DataManager.EmailLayout.Text );
                //processor = new EmailTemplateProcessor( t, layout, parameters, items );

                processor = new EmailTemplateProcessor(t, parameters, items);

                //var matches = Regex.Matches("Test {Token1} {Token 2}", @"{([^{}]*)");
                var regex = new System.Text.RegularExpressions.Regex(@"{([^{}]*)", System.Text.RegularExpressions.RegexOptions.Multiline);

                try
                {
                    TemplateParameterDiscoverer(regex.Match(processor.Template.Subject), processor.SubjParameters);
                }
                catch (Exception ex)
                {
                    processor.AddError("Error parsing subject parameters: " + ex.ToString());
                }
                try
                {
                    TemplateParameterDiscoverer(regex.Match(processor.Template.Text), processor.BodyParameters);
                }
                catch (Exception ex)
                {
                    processor.AddError("Error parsing html parameters: " + ex.ToString());
                }

                try
                {
                    TemplateParameterPopulator(processor);
                }
                catch (Exception ex)
                {
                    processor.AddError("Error populating parameters: " + ex.ToString());
                }
            }

            return(processor.Successful);
        }
 public EmailTemplate(EmailTemplateId id, string subject, string body) : this((int)id, subject, body)
 {
 }