Example #1
0
        public TemplateContent GetTemplate(TemplateProperty templateProperty)
        {
            string file = string.Format("/{0}/{1}/{2}/{3}/{4}",
                                        templateProperty.ClientId, templateProperty.Language, templateProperty.Year,
                                        templateProperty.BizGroup, templateProperty.TemplateName);

            FileInfo fi = fileProvider.GetFile(file);

            if (!fi.Exists)
            {
                file = string.Format("/{0}/{1}/{2}/{3}",
                                     templateProperty.Language, templateProperty.Year,
                                     templateProperty.BizGroup, templateProperty.TemplateName);
                fi = fileProvider.GetFile(file);
            }
            if (!fi.Exists)
            {
                file = string.Format("/{0}/{1}/{2}",
                                     templateProperty.Language,
                                     templateProperty.BizGroup, templateProperty.TemplateName);
                fi = fileProvider.GetFile(file);
            }
            if (!fi.Exists)
            {
                file = string.Format("/{0}/{1}/{2}",
                                     templateProperty.Year,
                                     templateProperty.BizGroup, templateProperty.TemplateName);
                fi = fileProvider.GetFile(file);
            }
            if (!fi.Exists)
            {
                file = string.Format("/{0}/{1}",
                                     templateProperty.BizGroup, templateProperty.TemplateName);
                fi = fileProvider.GetFile(file);
            }
            if (!fi.Exists)
            {
                file = string.Format("/{0}", templateProperty.TemplateName);
                fi   = fileProvider.GetFile(file);
            }
            if (!fi.Exists)
            {
                throw new FileNotFoundException(DAF.Core.Resources.Locale(o => o.FileNotFound), file);
            }

            string body = File.ReadAllText(fi.FullName);

            TemplateContent content = new TemplateContent()
            {
                FilePath = file,
                Name     = templateProperty.TemplateName,
                Body     = body
            };

            return(content);
        }
Example #2
0
        public TemplateContent GetTemplate(TemplateProperty templateProperty)
        {
            string file = string.Format("/{0}/{1}/{2}/{3}/{4}",
                templateProperty.ClientId, templateProperty.Language, templateProperty.Year,
                templateProperty.BizGroup, templateProperty.TemplateName);

            FileInfo fi  = fileProvider.GetFile(file);
            if (!fi.Exists)
            {
                file = string.Format("/{0}/{1}/{2}/{3}",
                templateProperty.Language, templateProperty.Year,
                templateProperty.BizGroup, templateProperty.TemplateName);
                fi = fileProvider.GetFile(file);
            }
            if (!fi.Exists)
            {
                file = string.Format("/{0}/{1}/{2}",
                templateProperty.Language,
                templateProperty.BizGroup, templateProperty.TemplateName);
                fi = fileProvider.GetFile(file);
            }
            if (!fi.Exists)
            {
                file = string.Format("/{0}/{1}/{2}",
                templateProperty.Year,
                templateProperty.BizGroup, templateProperty.TemplateName);
                fi = fileProvider.GetFile(file);
            }
            if (!fi.Exists)
            {
                file = string.Format("/{0}/{1}",
                templateProperty.BizGroup, templateProperty.TemplateName);
                fi = fileProvider.GetFile(file);
            }
            if (!fi.Exists)
            {
                file = string.Format("/{0}", templateProperty.TemplateName);
                fi = fileProvider.GetFile(file);
            }
            if (!fi.Exists)
                throw new FileNotFoundException(DAF.Core.Resources.Locale(o => o.FileNotFound), file);

            string body = File.ReadAllText(fi.FullName);

            TemplateContent content = new TemplateContent()
            {
                FilePath = file,
                Name = templateProperty.TemplateName,
                Body = body
            };
            return content;
        }
        public TemplateResult GenerateResult(object data, TemplateContent content)
        {
            var template = RT.Template
                .WithBaseType<RT.TemplateBase>()
                .AddNamespace("DAF.Core")
                .AddNamespace("DAF.Web")
                .Compile(content.Body);

            string body = template.Render(data);
            return new TemplateResult()
            {
                Name = content.Name,
                Body = body,
                OutFilePath = null
            };
        }
Example #4
0
        public TemplateResult LoadTemplate(object data, TemplateProperty templateProperty)
        {
            TemplateContent content = fileProvider.GetTemplate(templateProperty);

            if (content == null)
            {
                return(null);
            }

            TemplateResult result = null;

            foreach (var g in generators)
            {
                result = g.GenerateResult(data, content);
                if (result != null)
                {
                    break;
                }
            }

            return(result);
        }