예제 #1
0
        public static IEnumerable <EmailMessageEntity> CreateEmailMessage(this IEmailModel emailModel)
        {
            if (emailModel.UntypedEntity == null)
            {
                throw new InvalidOperationException("Entity property not set on EmailModel");
            }

            using (IsolationEntity.Override((emailModel.UntypedEntity as Entity)?.TryIsolation()))
            {
                var emailModelEntity = ToEmailModelEntity(emailModel.GetType());
                var template         = GetDefaultTemplate(emailModelEntity, emailModel.UntypedEntity as Entity);

                return(EmailTemplateLogic.CreateEmailMessage(template.ToLite(), model: emailModel));
            }
        }
예제 #2
0
        public static IEnumerable <EmailMessageEntity> CreateEmailMessage(this ISystemEmail systemEmail)
        {
            if (systemEmail.UntypedEntity == null)
            {
                throw new InvalidOperationException("Entity property not set on SystemEmail");
            }

            using (IsolationEntity.Override((systemEmail.UntypedEntity as Entity)?.TryIsolation()))
            {
                var systemEmailEntity = ToSystemEmailEntity(systemEmail.GetType());
                var template          = GetDefaultTemplate(systemEmailEntity, systemEmail.UntypedEntity as Entity);

                return(EmailTemplateLogic.CreateEmailMessage(template.ToLite(), systemEmail: systemEmail));
            }
        }
예제 #3
0
        public static void Start(
            SchemaBuilder sb,
            Func <EmailConfigurationEmbedded> getConfiguration,
            Func <EmailTemplateEntity?, Lite <Entity>?, SmtpConfigurationEntity> getSmtpConfiguration,
            Func <EmailMessageEntity, SmtpClient>?getSmtpClient = null,
            IFileTypeAlgorithm?attachment = null)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                if (getSmtpClient == null && getSmtpConfiguration != null)
                {
                    getSmtpClient = message => getSmtpConfiguration(message.Template?.Let(a => EmailTemplateLogic.EmailTemplatesLazy.Value.GetOrThrow(a)), message.Target).GenerateSmtpClient();
                }

                FilePathEmbeddedLogic.AssertStarted(sb);
                CultureInfoLogic.AssertStarted(sb);
                EmailLogic.getConfiguration = getConfiguration;
                EmailLogic.GetSmtpClient    = getSmtpClient ?? throw new ArgumentNullException(nameof(getSmtpClient));
                EmailTemplateLogic.Start(sb, getSmtpConfiguration);
                if (attachment != null)
                {
                    FileTypeLogic.Register(EmailFileType.Attachment, attachment);
                }

                Schema.Current.WhenIncluded <ProcessEntity>(() => EmailPackageLogic.Start(sb));

                sb.Include <EmailMessageEntity>()
                .WithQuery(() => e => new
                {
                    Entity = e,
                    e.Id,
                    e.State,
                    e.Subject,
                    e.Template,
                    e.Sent,
                    e.Target,
                    e.Package,
                    e.Exception,
                });

                PermissionAuthLogic.RegisterPermissions(AsyncEmailSenderPermission.ViewAsyncEmailSenderPanel);

                SenderManager = new EmailSenderManager();

                EmailGraph.Register();
            }
        }
예제 #4
0
        public static void Start(
            SchemaBuilder sb,
            Func <EmailConfigurationEmbedded> getConfiguration,
            Func <EmailTemplateEntity?, Lite <Entity>?, EmailMessageEntity?, EmailSenderConfigurationEntity> getEmailSenderConfiguration,
            IFileTypeAlgorithm?attachment = null)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                FilePathEmbeddedLogic.AssertStarted(sb);
                CultureInfoLogic.AssertStarted(sb);
                EmailLogic.getConfiguration = getConfiguration;
                EmailTemplateLogic.Start(sb, getEmailSenderConfiguration);
                EmailSenderConfigurationLogic.Start(sb);
                if (attachment != null)
                {
                    FileTypeLogic.Register(EmailFileType.Attachment, attachment);
                }

                Schema.Current.WhenIncluded <ProcessEntity>(() => EmailPackageLogic.Start(sb));

                sb.Include <EmailMessageEntity>()
                .WithQuery(() => e => new
                {
                    Entity = e,
                    e.Id,
                    e.State,
                    e.Subject,
                    e.Template,
                    e.Sent,
                    e.Target,
                    e.Package,
                    e.Exception,
                });

                PermissionAuthLogic.RegisterPermissions(AsyncEmailSenderPermission.ViewAsyncEmailSenderPanel);

                SenderManager = new EmailSenderManager(getEmailSenderConfiguration);

                EmailGraph.Register();

                QueryLogic.Expressions.Register((EmailPackageEntity a) => a.EmailMessages(), () => typeof(EmailMessageEntity).NicePluralName());

                ExceptionLogic.DeleteLogs += ExceptionLogic_DeleteLogs;
                ExceptionLogic.DeleteLogs += ExceptionLogic_DeletePackages;
            }
        }
예제 #5
0
        static string?ImageAttachmentFileName_StaticPropertyValidation(ImageAttachmentEntity WordAttachment, PropertyInfo pi)
        {
            var template = WordAttachment.TryGetParentEntity <EmailTemplateEntity>() !;

            if (template != null && WordAttachment.FileNameNode as TextTemplateParser.BlockNode == null)
            {
                try
                {
                    WordAttachment.FileNameNode = EmailTemplateLogic.ParseTemplate(template, WordAttachment.FileName, out string errorMessage);
                    return(errorMessage.DefaultToNull());
                }
                catch (Exception ex)
                {
                    return(ex.Message);
                }
            }

            return(null);
        }
예제 #6
0
        public EmailMessageBuilder(EmailTemplateEntity template, Entity entity, ISystemEmail systemEmail)
        {
            this.template    = template;
            this.entity      = entity;
            this.systemEmail = systemEmail;

            this.queryName  = QueryLogic.ToQueryName(template.Query.Key);
            this.qd         = DynamicQueryManager.Current.QueryDescription(queryName);
            this.smtpConfig = EmailTemplateLogic.GetSmtpConfiguration == null ? null : EmailTemplateLogic.GetSmtpConfiguration(template);
        }