Exemplo n.º 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));
        }
 public WordTemplateRenderer(WordprocessingDocument document, QueryDescription queryDescription, Entity entity, CultureInfo culture, ISystemWordTemplate systemWordTemplate)
 {
     this.document = document;
     this.entity = entity;
     this.culture = culture;
     this.systemWordTemplate = systemWordTemplate;
     this.queryDescription = queryDescription;
 }
Exemplo n.º 3
0
 public TemplateRenderer(OpenXmlPackage document, QueryDescription queryDescription, Entity entity, CultureInfo culture, ISystemWordTemplate systemWordTemplate, WordTemplateEntity template)
 {
     this.document           = document;
     this.entity             = entity;
     this.culture            = culture;
     this.systemWordTemplate = systemWordTemplate;
     this.queryDescription   = queryDescription;
     this.template           = template;
 }
Exemplo n.º 4
0
        public FileContentResult CreateWordReport()
        {
            var entity = Lite.Parse(Request["keys"]).Retrieve();

            var template = this.ExtractEntity <WordTemplateEntity>();

            ISystemWordTemplate systemWordReport = template.SystemWordTemplate == null ? null :
                                                   (ISystemWordTemplate)SystemWordTemplateLogic.GetEntityConstructor(template.SystemWordTemplate.ToType()).Invoke(new[] { entity });

            var bytes = template.CreateReport(entity, systemWordReport);

            return(File(bytes, MimeMapping.GetMimeMapping(template.FileName), Path.GetFileName(template.FileName)));
        }
        public static byte[] CreateReport(this WordTemplateEntity template, Entity entity, ISystemWordTemplate systemWordTemplate = null, bool avoidConversion = false)
        {

            if (systemWordTemplate != null && template.SystemWordTemplate.FullClassName != systemWordTemplate.GetType().FullName)
                throw new ArgumentException("systemWordTemplate should be a {0} instead of {1}".FormatWith(template.SystemWordTemplate.FullClassName, systemWordTemplate.GetType().FullName));

            using (template.DisableAuthorization ? ExecutionMode.Global() : null)
            {
                QueryDescription qd = DynamicQueryManager.Current.QueryDescription(template.Query.ToQueryName());

                 using (var memory = new MemoryStream())
                 {
                     memory.WriteAllBytes(template.Template.Retrieve().BinaryFile);

                     using (WordprocessingDocument document = WordprocessingDocument.Open(memory, true))
                     {
                         Dump(document, "0.Original.txt");

                         var parser = new WordTemplateParser(document, qd, template.SystemWordTemplate.ToType());
                         parser.ParseDocument(); Dump(document, "1.Match.txt");
                         parser.CreateNodes(); Dump(document, "2.BaseNode.txt");
                         parser.AssertClean();

                         var renderer = new WordTemplateRenderer(document, qd, entity, template.Culture.ToCultureInfo(), systemWordTemplate);
                         renderer.MakeQuery();
                         renderer.RenderNodes(); Dump(document, "3.Replaced.txt");
                         renderer.AssertClean();

                         FixDocument(document); Dump(document, "4.Fixed.txt");

                         if (template.WordTransformer != null)
                             Transformers.GetOrThrow(template.WordTransformer)(template, entity, document);
                     }

                     var array = memory.ToArray();

                     if (!avoidConversion && template.WordConverter != null)
                         array = Converters.GetOrThrow(template.WordConverter)(template, entity, array);

                     return array;
                 }
            }
        }
 public static byte[] CreateReport(this Lite<WordTemplateEntity> liteTemplate, Entity entity, ISystemWordTemplate systemWordTemplate = null, bool avoidConversion = false)
 {
     return liteTemplate.GetFromCache().CreateReport(entity, systemWordTemplate, avoidConversion);
 }
Exemplo n.º 7
0
        public static byte[] CreateReport(this WordTemplateEntity template, ModifiableEntity model = null, ISystemWordTemplate systemWordTemplate = null, bool avoidConversion = false)
        {
            WordTemplatePermission.GenerateReport.AssertAuthorized();

            Entity entity = null;

            if (template.SystemWordTemplate != null)
            {
                if (systemWordTemplate == null)
                {
                    systemWordTemplate = SystemWordTemplateLogic.CreateDefaultSystemWordTemplate(template.SystemWordTemplate, model);
                }
                else if (template.SystemWordTemplate.ToType() != systemWordTemplate.GetType())
                {
                    throw new ArgumentException("systemWordTemplate should be a {0} instead of {1}".FormatWith(template.SystemWordTemplate.FullClassName, systemWordTemplate.GetType().FullName));
                }
            }
            else
            {
                entity = model as Entity ?? throw new InvalidOperationException("Model should be an Entity");
            }

            using (template.DisableAuthorization ? ExecutionMode.Global() : null)
                using (CultureInfoUtils.ChangeBothCultures(template.Culture.ToCultureInfo()))
                {
                    QueryDescription qd = DynamicQueryManager.Current.QueryDescription(template.Query.ToQueryName());

                    var array = template.ProcessOpenXmlPackage(document =>
                    {
                        Dump(document, "0.Original.txt");

                        var parser = new TemplateParser(document, qd, template.SystemWordTemplate.ToType(), template);
                        parser.ParseDocument(); Dump(document, "1.Match.txt");
                        parser.CreateNodes(); Dump(document, "2.BaseNode.txt");
                        parser.AssertClean();

                        if (parser.Errors.Any())
                        {
                            throw new InvalidOperationException("Error in template {0}:\r\n".FormatWith(template) + parser.Errors.ToString(e => e.Message, "\r\n"));
                        }

                        var renderer = new TemplateRenderer(document, qd, entity, template.Culture.ToCultureInfo(), systemWordTemplate, template);
                        renderer.MakeQuery();
                        renderer.RenderNodes(); Dump(document, "3.Replaced.txt");
                        renderer.AssertClean();

                        FixDocument(document); Dump(document, "4.Fixed.txt");

                        if (template.WordTransformer != null)
                        {
                            Transformers.GetOrThrow(template.WordTransformer)(new WordContext
                            {
                                Template           = template,
                                Entity             = entity,
                                SystemWordTemplate = systemWordTemplate
                            }, document);
                        }
                    });

                    if (!avoidConversion && template.WordConverter != null)
                    {
                        array = Converters.GetOrThrow(template.WordConverter)(new WordContext
                        {
                            Template           = template,
                            Entity             = entity,
                            SystemWordTemplate = systemWordTemplate
                        }, array);
                    }

                    return(array);
                }
        }
Exemplo n.º 8
0
 public static byte[] CreateReport(this Lite <WordTemplateEntity> liteTemplate, ModifiableEntity entity = null, ISystemWordTemplate systemWordTemplate = null, bool avoidConversion = false)
 {
     return(liteTemplate.GetFromCache().CreateReport(entity, systemWordTemplate, avoidConversion));
 }
Exemplo n.º 9
0
 public static byte[] CreateReport(this ISystemWordTemplate systemWordTemplate, bool avoidConversion = false)
 {
     return(systemWordTemplate.CreateReport(out WordTemplateEntity rubish, avoidConversion));
 }