protected string FormatValue(UserAccountEvent evt, string value) { if (value == null) return null; var tokenizer = GetTokenizer(evt); return tokenizer.Tokenize(evt, this.ApplicationInformation, value); }
public virtual void Process(UserAccountEvent evt, string phone = null) { var msg = CreateMessage(evt, phone); if (msg != null) { SendSms(msg); } }
protected virtual Message CreateMessage(UserAccountEvent evt, string phone) { var msg = this.messageFormatter.Format(evt); if (msg != null) { msg.To = phone ?? evt.Account.MobilePhoneNumber; } return msg; }
private string GetMessageBody(UserAccountEvent accountEvent) { var txt = LoadTemplate(); txt = txt.Replace("{applicationName}", ApplicationInformation.ApplicationName); txt = txt.Replace("{code}", accountEvent.Account.MobileCode); return txt; }
public Message Format(UserAccountEvent accountEvent) { if (accountEvent == null) throw new ArgumentNullException("accountEvent"); var message = GetMessageBody(accountEvent); return new Message { Subject = message, Body = message }; }
protected virtual Tokenizer GetTokenizer(UserAccountEvent evt) { Type type = evt.GetType(); if (type == typeof(EmailChangeRequestedEvent)) return new EmailChangeRequestedTokenizer(); if (type == typeof(EmailChangedEvent)) return new EmailChangedTokenizer(); if (type == typeof(CertificateAddedEvent)) return new CertificateAddedTokenizer(); if (type == typeof(CertificateRemovedEvent)) return new CertificateRemovedTokenizer(); if (type == typeof(LinkedAccountAddedEvent)) return new LinkedAccountAddedTokenizer(); if (type == typeof(LinkedAccountRemovedEvent)) return new LinkedAccountRemovedTokenizer(); return new Tokenizer(); }
protected virtual string GetSubject(UserAccountEvent evt) { return FormatValue(evt, LoadSubjectTemplate(evt)); }
protected virtual string GetBody(UserAccountEvent evt) { return FormatValue(evt, LoadBodyTemplate(evt)); }
public Message Format(UserAccountEvent accountEvent) { if (accountEvent == null) throw new ArgumentNullException("accountEvent"); return CreateMessage(GetSubject(accountEvent), GetBody(accountEvent)); }
public override string Tokenize(UserAccountEvent accountEvent, ApplicationInformation appInfo, string msg) { var evt = (LinkedAccountRemovedEvent)accountEvent; msg = base.Tokenize(accountEvent, appInfo, msg); msg = msg.Replace("{provider}", evt.LinkedAccount.ProviderName); return msg; }
public virtual string Tokenize(UserAccountEvent accountEvent, ApplicationInformation appInfo, string msg) { var user = accountEvent.Account; msg = msg.Replace("{username}", user.Username); msg = msg.Replace("{email}", user.Email); msg = msg.Replace("{mobile}", user.MobilePhoneNumber); msg = msg.Replace("{applicationName}", appInfo.ApplicationName); msg = msg.Replace("{emailSignature}", appInfo.EmailSignature); msg = msg.Replace("{loginUrl}", appInfo.LoginUrl); msg = msg.Replace("{confirmAccountCreateUrl}", appInfo.VerifyAccountUrl + user.VerificationKey); msg = msg.Replace("{cancelNewAccountUrl}", appInfo.CancelNewAccountUrl + user.VerificationKey); msg = msg.Replace("{confirmPasswordResetUrl}", appInfo.ConfirmPasswordResetUrl + user.VerificationKey); msg = msg.Replace("{confirmChangeEmailUrl}", appInfo.ConfirmChangeEmailUrl + user.VerificationKey); return msg; }
public override string Tokenize(UserAccountEvent accountEvent, ApplicationInformation appInfo, string msg) { var evt = (EmailChangeRequestedEvent)accountEvent; msg = base.Tokenize(accountEvent, appInfo, msg); msg = msg.Replace("{newEmail}", evt.NewEmail); msg = msg.Replace("{oldEmail}", accountEvent.Account.Email); return msg; }
public override string Tokenize(UserAccountEvent accountEvent, ApplicationInformation appInfo, string msg) { var evt = (CertificateRemovedEvent)accountEvent; msg = base.Tokenize(accountEvent, appInfo, msg); msg = msg.Replace("{thumbprint}", evt.Certificate.Thumbprint); msg = msg.Replace("{subject}", evt.Certificate.Subject); return msg; }
protected virtual string LoadSubjectTemplate(UserAccountEvent evt) { return LoadTemplate(evt.GetType().Name + "_Subject"); }
protected virtual string LoadBodyTemplate(UserAccountEvent evt) { return LoadTemplate(evt.GetType().Name + "_Body"); }
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); } }