示例#1
0
        public static Renderer GetRenderer(ProcessURI uri, IProcessResponse response)
        {
            RenderingSection config = RenderingSection.Current;
            if (renderer == null)
            {
                Type rendererType = Type.GetType(config.Type);
                Assembly asm = rendererType.Assembly;
                renderer = asm.CreateInstance(rendererType.FullName) as Renderer;
                renderer.Path = ParseRendererPath(config);

                //foreach (CustomHelper helper in config.CustomHelpers)
                //    renderer.Helpers.Add(CreateHelperInstance(helper));

                renderer.UrlHelper = new UrlHelper("url");
                renderer.AppHelper = new AppHelper("app");
                renderer.StateHelper = new StateHelper("state");
                renderer.AjaxHelper = new AjaxHelper("ajax");
                renderer.TypeHelper = new TypeHelper("type");
            }

            renderer.URI = uri;

            Configuration.Template template = renderer.GetTemplate(response);
            renderer.LayoutFileName = template != null
                                          ? ((string.IsNullOrEmpty(template.LayoutFileName))
                                                 ? config.LayoutFileName
                                                 : template.LayoutFileName)
                                          : config.LayoutFileName;

            return renderer;
        }
 public Template Find(IProcessResponse response)
 {
     foreach (Template tpl in this)
         if (tpl.IsResponseTemplate(response))
             return tpl;
     return null;
 }
示例#3
0
        protected Control LoadControl(string templateName, Page page, IProcessResponse response, Domain domain)
        {
            string templatePath = string.Format("~/{0}/{1}", RenderingSection.Current.Path, templateName);
            WebFormsControl control = null;

            try
            {
                control = page.LoadControl(templatePath) as WebFormsControl;
            }
            catch (Exception ex)
            {
            #if DEBUG
                throw ex;
            #endif
            }

            if (control != null)
            {
                control.URI = URI;
                control.Response = response;
                control.Domain = domain;
                control.Renderer = this;
            }
            return control;
        }
示例#4
0
 public string ProcessResponse(IProcessResponse response)
 {
     StringWriter writer = new StringWriter();
     Configuration.Template template = GetTemplate(response);
     if (template != null)
         ProcessTemplate(writer, template.FileName, response, null);
     return writer.ToString();
 }
示例#5
0
 public override void ProcessTemplate(TextWriter writer, string templateName, IProcessResponse response,
                                      Domain domain)
 {
     if (!string.IsNullOrEmpty(templateName))
     {
         Template template = Engine.GetTemplate(templateName);
         template.Merge(CreateTemplateContext(URI, response, domain), writer);
     }
 }
示例#6
0
 public void LoadDomainTemplate(IProcessResponse response, Domain domain, Control container)
 {
     string templateName = GetTemplateName(response, domain);
     if (!string.IsNullOrEmpty(templateName))
     {
         var control = LoadControl(templateName, container.Page, response, domain);
         if (control != null)
             container.Controls.Add(control);
     }
 }
示例#7
0
 public void LoadTemplate(IProcessResponse response, Domain domain, Control container)
 {
     Configuration.Template template = GetTemplate(response);
     if (template != null)
     {
         var control = LoadControl(template.FileName, container.Page, response, domain);
         if (control != null)
             container.Controls.Add(control);
     }
 }
示例#8
0
 public override void ProcessTemplate(TextWriter writer, string templateName, IProcessResponse response,
                                      Domain domain)
 {
     if (!string.IsNullOrEmpty(templateName))
     {
         Page page = new Page();
         page.Controls.Add(LoadControl(templateName, page, response, domain));
         page.RenderControl(new HtmlTextWriter(writer));
     }
 }
示例#9
0
 public override void Process(IProcessResponse response, TextWriter writer)
 {
     if (UrlHelper.CurrentExtension.Equals(UrlHelper.ExcelInteropExtension) || UrlHelper.CurrentExtension.Equals(UrlHelper.PdfExtension))
     {
         Template template = GetTemplate(response);
         if (template != null)
             ProcessTemplate(writer, template.FileName, response, null);
     }
     else
         base.Process(response, writer);
 }
示例#10
0
        private VelocityContext CreateTemplateContext(ProcessURI uri, IProcessResponse response, Domain domain)
        {
            VelocityContext context = new VelocityContext();
            context.Put("uri", uri);
            context.Put("renderer", this);

            if (response != null) context.Put("response", response);
            if (domain != null) context.Put("domain", domain);

            foreach (RendererHelper helper in Helpers)
                context.Put(helper.Name, helper);

            return context;
        }
 public static IProcessResponse Evaluate(ProcessURI uri, IProcessResponse response)
 {
     if (IsAuthorized(uri))
     {
         Expression expression = GetRuleResponseExpression(uri) ?? Expression.Empty;
         if (expression != Expression.Empty)
         {
             var expressionURI = ProcessURI.Parse(expression.ToString());
             foreach (AuthorizationKeyEvaluator evaluator in Evaluators)
                 expressionURI = evaluator.Evaluate(expression, expressionURI);
             //TODO: Apply new URI to the response subset
         }
     }
     return response;
 }
示例#12
0
 public override void ProcessTemplate(TextWriter writer, string templateName, IProcessResponse response, Domain domain)
 {
     if ((UrlHelper.CurrentExtension.Equals(UrlHelper.ExcelInteropExtension) || UrlHelper.CurrentExtension.Equals(UrlHelper.PdfExtension)) && response is QueryProcessResponse)
     {
         if (templateName.EndsWith(ExcelExtension))
         {
             SetFileName(response);
             var filePath = CreateExcelFile(templateName);
             if (UrlHelper.CurrentExtension.Equals(UrlHelper.ExcelInteropExtension))
             {
                 LoadExcelData(filePath, (QueryProcessResponse)response);
                 HttpContext.Current.Response.WriteFile(filePath);
             }
             else
             {
                 LoadPdfData(filePath, (QueryProcessResponse)response);
                 HttpContext.Current.Response.WriteFile(filePath.Replace(ExcelExtension, PdfExtension));
             }
         }
     }
     else
         base.ProcessTemplate(writer, templateName, response, domain);
 }
示例#13
0
 protected string GetTemplateName(IProcessResponse response, Domain domain)
 {
     return GetTemplate(response).TemplateDomains.Find(domain).FileName;
 }
示例#14
0
 public abstract void ProcessTemplate(TextWriter writer, string templateName, IProcessResponse response, Domain domain);
示例#15
0
 public void Process(IProcessResponse response, Domain domain, TextWriter writer)
 {
     ProcessTemplate(writer, GetTemplateName(response, domain), response, domain);
 }
示例#16
0
 public virtual void Process(IProcessResponse response, TextWriter writer)
 {
     if (!string.IsNullOrEmpty(LayoutFileName))
         ProcessTemplate(writer, LayoutFileName, response, null);
     else
     {
         Template template = GetTemplate(response);
         if (template != null)
             ProcessTemplate(writer, template.FileName, response, null);
     }
 }
示例#17
0
 public static IProcessResponse Evaluate(ProcessURI uri, IProcessResponse response)
 {
     return AuthorizationManager.Evaluate(uri, response);
 }
示例#18
0
        public Template GetTemplate(IProcessResponse response)
        {
            var config = RenderingSection.Current;

            if (!Templates.ContainsKey(response))
            {
                var template = config.Templates.Find(string.Concat(response.URI, UrlHelper.CurrentExtension), UrlHelper.CurrentExtension)
                                ?? config.Templates.Find(response.URI)
                                ?? config.Templates.Find(response);

                Templates.Add(response, template);
            }

            return Templates[response];
        }
示例#19
0
 private void SetFileName(IProcessResponse response)
 {
     FileName = response.URI.Entity;
     var timeStamp = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss.fff");
     if (FileName.Length > (FileNameLength - timeStamp.Length - 1))
         FileName = FileName.Substring(0, (FileNameLength - timeStamp.Length - 1));
     FileName = string.Concat(FileName, " ", timeStamp);
 }
示例#20
0
 public string ProcessDomain(IProcessResponse response, Domain domain)
 {
     StringWriter writer = new StringWriter();
     ProcessTemplate(writer, GetTemplateName(response, domain), response, domain);
     return writer.ToString();
 }
示例#21
0
 internal bool IsResponseTemplate(IProcessResponse response)
 {
     if (response != null)
     {
         string name = response.GetType().Name;
         const string filterKey = ResponseFilterKey + FilterKeySeparator;
         return name.Contains(Filter.Replace(filterKey, string.Empty));
     }
     return false;
 }