Пример #1
0
        public static byte[] CreateReport(this ISystemWordTemplate systemWordTemplate, out WordTemplateEntity template, bool avoidConversion = false)
        {
            SystemWordTemplateEntity system = GetSystemWordTemplate(systemWordTemplate.GetType());

            template = GetDefaultTemplate(system, systemWordTemplate.UntypedEntity as Entity);

            return(WordTemplateLogic.CreateReport(template.ToLite(), systemWordTemplate: systemWordTemplate, avoidConversion: avoidConversion));
        }
Пример #2
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            sb.Include <WordAttachmentEntity>()
            .WithQuery(dqm, () => s => new
            {
                Entity = s,
                s.Id,
                s.FileName,
                s.WordTemplate,
                s.OverrideModel,
            });

            EmailTemplateLogic.FillAttachmentTokens.Register((WordAttachmentEntity wa, EmailTemplateLogic.FillAttachmentTokenContext ctx) =>
            {
                if (wa.FileName != null)
                {
                    EmailTemplateParser.Parse(wa.FileName, ctx.QueryDescription, ctx.ModelType).FillQueryTokens(ctx.QueryTokens);
                }
            });

            Validator.PropertyValidator((WordAttachmentEntity e) => e.FileName).StaticPropertyValidation = WordAttachmentFileName_StaticPropertyValidation;

            EmailTemplateLogic.GenerateAttachment.Register((WordAttachmentEntity wa, EmailTemplateLogic.GenerateAttachmentContext ctx) =>
            {
                var entity = wa.OverrideModel?.Retrieve() ?? (Entity)ctx.Entity ?? ctx.SystemEmail.UntypedEntity;

                if (wa.ModelConverter != null)
                {
                    entity = wa.ModelConverter.Convert(entity);
                }

                using (CultureInfoUtils.ChangeBothCultures(ctx.Culture))
                {
                    WordTemplateEntity template = WordTemplateLogic.GetFromCache(wa.WordTemplate);

                    var fileName = GetTemplateString(wa.FileName, ref wa.FileNameNode, ctx);

                    var systemWordTemplate = template.SystemWordTemplate != null && !SystemWordTemplateLogic.RequiresExtraParameters(template.SystemWordTemplate) ?
                                             SystemWordTemplateLogic.CreateDefaultSystemWordTemplate(template.SystemWordTemplate, entity) : null;

                    var bytes = WordTemplateLogic.CreateReport(template, entity, systemWordTemplate);

                    return(new List <EmailAttachmentEmbedded>
                    {
                        new EmailAttachmentEmbedded
                        {
                            File = Files.FilePathEmbeddedLogic.SaveFile(new Entities.Files.FilePathEmbedded(EmailFileType.Attachment, fileName, bytes)),
                            Type = EmailAttachmentType.Attachment,
                        }
                    });
                }
            });
        }