public static void Register()
        {
            new Construct(EmailTemplateOperation.Create)
            {
                Construct = _ => new EmailTemplateEntity
                {
                    MasterTemplate = EmailMasterTemplateLogic.GetDefaultMasterTemplate(),
                }
            }.Register();

            new Execute(EmailTemplateOperation.Save)
            {
                CanBeNew      = true,
                CanBeModified = true,
                Execute       = (t, _) => { }
            }.Register();

            new Delete(EmailTemplateOperation.Delete)
            {
                Delete = (t, _) =>
                {
                    var attachments = t.Attachments.Select(a => a.ToLite()).ToList();

                    t.Delete();
                    attachments.ForEach(at => at.Delete());
                }
            }.Register();

            registered = true;
        }
    public static void Start(SchemaBuilder sb, Func <EmailTemplateEntity, Lite <Entity>?, EmailMessageEntity?, EmailSenderConfigurationEntity?>?getSmtpConfiguration)
    {
        if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
        {
            CultureInfoLogic.AssertStarted(sb);
            TemplatingLogic.Start(sb);


            GetSmtpConfiguration = getSmtpConfiguration;

            sb.Include <EmailTemplateEntity>()
            .WithQuery(() => t => new
            {
                Entity = t,
                t.Id,
                t.Name,
                t.IsBodyHtml
            });

            EmailTemplatesLazy = sb.GlobalLazy(() =>
                                               Database.Query <EmailTemplateEntity>().ToDictionary(et => et.ToLite())
                                               , new InvalidateWith(typeof(EmailTemplateEntity)));

            TemplatesByQueryName = sb.GlobalLazy(() =>
            {
                return(EmailTemplatesLazy.Value.Values.SelectCatch(et => KeyValuePair.Create(et.Query.ToQueryName(), et)).GroupToDictionary());
            }, new InvalidateWith(typeof(EmailTemplateEntity)));

            EmailModelLogic.Start(sb);
            EmailMasterTemplateLogic.Start(sb);

            sb.Schema.EntityEvents <EmailTemplateEntity>().PreSaving += new PreSavingEventHandler <EmailTemplateEntity>(EmailTemplate_PreSaving);
            sb.Schema.EntityEvents <EmailTemplateEntity>().Retrieved += EmailTemplateLogic_Retrieved;
            sb.Schema.Table <EmailModelEntity>().PreDeleteSqlSync    += e =>
                                                                        Administrator.UnsafeDeletePreCommand(Database.Query <EmailTemplateEntity>()
                                                                                                             .Where(a => a.Model.Is(e)));

            Validator.OverridePropertyValidator((EmailTemplateMessageEmbedded m) => m.Text).StaticPropertyValidation +=
                EmailTemplateMessageText_StaticPropertyValidation;

            Validator.OverridePropertyValidator((EmailTemplateMessageEmbedded m) => m.Subject).StaticPropertyValidation +=
                EmailTemplateMessageSubject_StaticPropertyValidation;

            EmailTemplateGraph.Register();

            GlobalValueProvider.RegisterGlobalVariable("UrlLeft", _ => EmailLogic.Configuration.UrlLeft);
            GlobalValueProvider.RegisterGlobalVariable("Now", _ => Clock.Now);
            GlobalValueProvider.RegisterGlobalVariable("Today", _ => Clock.Now.Date, "d");

            sb.Schema.Synchronizing += Schema_Synchronizing_Tokens;
            sb.Schema.Synchronizing += Schema_Synchronizing_DefaultTemplates;

            sb.Schema.Table <EmailModelEntity>().PreDeleteSqlSync += EmailTemplateLogic_PreDeleteSqlSync;

            Validator.PropertyValidator <EmailTemplateEntity>(et => et.Messages).StaticPropertyValidation += (et, pi) =>
            {
                var dc = EmailLogic.Configuration.DefaultCulture;

                if (!et.Messages.Any(m => m.CultureInfo != null && dc.Name.StartsWith(m.CultureInfo.Name)))
                {
                    return(EmailTemplateMessage.ThereMustBeAMessageFor0.NiceToString().FormatWith(CultureInfoLogic.EntityToCultureInfo.Value.Keys.Where(c => dc.Name.StartsWith(c.Name)).CommaOr(a => a.EnglishName)));
                }

                return(null);
            };
        }
    }