internal static SqlPreCommand Regenerate(EmailTemplateEntity et, Replacements replacements, Table table)
        {
            var newTemplate = SystemEmailLogic.CreateDefaultTemplate(et.SystemEmail);

            newTemplate.SetId(et.IdOrNull);
            newTemplate.SetIsNew(false);
            newTemplate.Ticks = et.Ticks;

            using (replacements?.WithReplacedDatabaseName())
                return(table.UpdateSqlSync(newTemplate, includeCollections: true, comment: "EmailTemplate Regenerated: " + et.Name));
        }
Esempio n. 2
0
            public static void Register()
            {
                GetState = m => m.State;

                new Construct(EmailMessageOperation.CreateMail)
                {
                    ToStates  = { EmailMessageState.Created },
                    Construct = _ => new EmailMessageEntity
                    {
                        State = EmailMessageState.Created,
                    }
                }.Register();

                new ConstructFrom <EmailTemplateEntity>(EmailMessageOperation.CreateEmailFromTemplate)
                {
                    AllowsNew    = false,
                    ToStates     = { EmailMessageState.Created },
                    CanConstruct = et =>
                    {
                        if (et.SystemEmail != null && SystemEmailLogic.RequiresExtraParameters(et.SystemEmail))
                        {
                            return(EmailMessageMessage._01requiresExtraParameters.NiceToString(typeof(SystemEmailEntity).NiceName(), et.SystemEmail));
                        }

                        if (et.SendDifferentMessages)
                        {
                            return(ValidationMessage._0IsSet.NiceToString(ReflectionTools.GetPropertyInfo(() => et.SendDifferentMessages).NiceName()));
                        }

                        return(null);
                    },
                    Construct = (et, args) =>
                    {
                        var entity = args.TryGetArgC <ModifiableEntity>() ?? args.GetArg <Lite <Entity> >().Retrieve();

                        return(et.ToLite().CreateEmailMessage(entity).FirstEx());
                    }
                }.Register();

                new Execute(EmailMessageOperation.Save)
                {
                    AllowsNew  = true,
                    Lite       = false,
                    FromStates = { EmailMessageState.Created, EmailMessageState.Outdated },
                    ToStates   = { EmailMessageState.Draft },
                    Execute    = (m, _) => { m.State = EmailMessageState.Draft; }
                }.Register();

                new Execute(EmailMessageOperation.ReadyToSend)
                {
                    AllowsNew  = true,
                    Lite       = false,
                    FromStates = { EmailMessageState.Created, EmailMessageState.Draft, EmailMessageState.SentException, EmailMessageState.RecruitedForSending, EmailMessageState.Outdated },
                    ToStates   = { EmailMessageState.ReadyToSend },
                    Execute    = (m, _) =>
                    {
                        m.SendRetries = 0;
                        m.State       = EmailMessageState.ReadyToSend;
                    }
                }.Register();

                new Execute(EmailMessageOperation.Send)
                {
                    CanExecute = m => m.State == EmailMessageState.Created || m.State == EmailMessageState.Draft ||
                                 m.State == EmailMessageState.ReadyToSend || m.State == EmailMessageState.RecruitedForSending ||
                                 m.State == EmailMessageState.Outdated ? null : EmailMessageMessage.TheEmailMessageCannotBeSentFromState0.NiceToString().FormatWith(m.State.NiceToString()),
                    AllowsNew  = true,
                    Lite       = false,
                    FromStates = { EmailMessageState.Created, EmailMessageState.Draft, EmailMessageState.ReadyToSend, EmailMessageState.Outdated },
                    ToStates   = { EmailMessageState.Sent },
                    Execute    = (m, _) => EmailLogic.SenderManager.Send(m)
                }.Register();

                new ConstructFrom <EmailMessageEntity>(EmailMessageOperation.ReSend)
                {
                    AllowsNew = false,
                    ToStates  = { EmailMessageState.Created },
                    Construct = (m, _) => new EmailMessageEntity
                    {
                        From            = m.From.Clone(),
                        Recipients      = m.Recipients.Select(r => r.Clone()).ToMList(),
                        Target          = m.Target,
                        Subject         = m.Subject,
                        Body            = m.Body,
                        IsBodyHtml      = m.IsBodyHtml,
                        Template        = m.Template,
                        EditableMessage = m.EditableMessage,
                        State           = EmailMessageState.Created,
                        Attachments     = m.Attachments.ToMList(),
                    }
                }.Register();

                new Graph <EmailMessageEntity> .Delete(EmailMessageOperation.Delete)
                {
                    Delete = (m, _) => m.Delete()
                }

                .Register();
            }
Esempio n. 3
0
 public static ISystemEmail CreateSystemEmail(SystemEmailEntity systemEmail, ModifiableEntity model)
 {
     return((ISystemEmail)SystemEmailLogic.GetEntityConstructor(systemEmail.ToType()).Invoke(new[] { model }));
 }