Inheritance: System.Attribute
Example #1
0
        protected virtual void AddResponseHeaders(ActionExecutedContext context, EnableJsReportAttribute jsreportAttribute,
                                                  Report output)
        {
            foreach (var httpResponseHeader in output.Response.Headers)
            {
                if (httpResponseHeader.Key.ToLower() == "connection" || httpResponseHeader.Key.ToLower() == "transfer-encoding")
                {
                    continue;
                }


                context.HttpContext.Response.AddHeader(httpResponseHeader.Key,
                                                       string.Join(";", httpResponseHeader.Value));
            }

            foreach (var httpContentHeader in output.Response.Content.Headers)
            {
                if (jsreportAttribute.ContentDisposition != null && httpContentHeader.Key.ToLower() == "content-disposition")
                {
                    context.HttpContext.Response.AddHeader(httpContentHeader.Key, jsreportAttribute.ContentDisposition);
                }
                else
                {
                    context.HttpContext.Response.AddHeader(httpContentHeader.Key,
                                                           string.Join(";", httpContentHeader.Value));
                }
            }

            context.HttpContext.Response.ContentType = output.ContentType.MediaType;
        }
Example #2
0
 public JsReportStream(ActionExecutedContext context, EnableJsReportAttribute attr, Func<ActionExecutedContext, EnableJsReportAttribute, string, Task<Report>> renderReport)
 {
     _stream = context.HttpContext.Response.Filter;
     _context = context;
     _attr = attr;
     _renderReport = renderReport;
 }
 public JsReportStream(ActionExecutedContext context, EnableJsReportAttribute attr, Func <ActionExecutedContext, EnableJsReportAttribute, string, Task <Report> > renderReport)
 {
     _stream       = context.HttpContext.Response.Filter;
     _context      = context;
     _attr         = attr;
     _renderReport = renderReport;
 }
Example #4
0
        protected virtual object CreateRenderingRequest(ActionExecutedContext context,
                                                        EnableJsReportAttribute jsreportAttribute, string htmlContent)
        {
            if (context.Controller.ViewData["jsreportRenderRequest"] == null)
            {
                return(new RenderRequest()
                {
                    template = new Template
                    {
                        content = RemoveVisualStudioBrowserLink(htmlContent),
                        recipe = jsreportAttribute.Recipe ?? "phantom-pdf",
                        engine = jsreportAttribute.Engine ?? "none",
                        phantom = new Phantom
                        {
                            margin = jsreportAttribute.Margin,
                            headerHeight = jsreportAttribute.HeaderHeight,
                            header =
                                jsreportAttribute.HeaderPartialView != null
                                                ? RenderPartialViewToString(context, jsreportAttribute.HeaderPartialView,
                                                                            null)
                                                : null,
                            footerHeight = jsreportAttribute.FooterHeight,
                            footer =
                                jsreportAttribute.FooterPartialView != null
                                                ? RenderPartialViewToString(context, jsreportAttribute.FooterPartialView,
                                                                            null)
                                                : null,
                            orientation = jsreportAttribute.Orientation,
                            width = jsreportAttribute.Width,
                            height = jsreportAttribute.Height,
                            format = jsreportAttribute.Format,
                            waitForJS = jsreportAttribute.WaitForJS,
                            resourceTimeout = jsreportAttribute.ResourceTimeout,
                            blockJavaScript = jsreportAttribute.BlockJavaScript,
                            printDelay = jsreportAttribute.PrintDelay
                        }
                    }
                });
            }

            var originalRequest = context.Controller.ViewData["jsreportRenderRequest"];

            if (originalRequest is RenderRequest)
            {
                var castedRequest = ((RenderRequest)originalRequest);
                castedRequest.template.content = string.IsNullOrEmpty(castedRequest.template.content)
                                                     ? RemoveVisualStudioBrowserLink(htmlContent)
                                                     : castedRequest.template.content;
                return(castedRequest);
            }


            dynamic request = ConvertToDynamic(originalRequest);
            IDictionary <string, object> template = ConvertToDynamic(request.template);

            template["content"] = template.ContainsKey("content") ? template["content"] : RemoveVisualStudioBrowserLink(htmlContent);
            request.template    = template;

            return(request);
        }
Example #5
0
        private bool ShouldUseJsReport(ActionExecutedContext filterContext, out EnableJsReportAttribute attr)
        {
            var enableJsReport = false;

            attr = null;

            if (filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(EnableJsReportAttribute), true))
            {
                attr =
                    (EnableJsReportAttribute)
                    filterContext.ActionDescriptor.ControllerDescriptor.GetCustomAttributes(
                        typeof(EnableJsReportAttribute), true).First();
                enableJsReport = true;
            }

            if (filterContext.ActionDescriptor.IsDefined(typeof(EnableJsReportAttribute), true))
            {
                attr =
                    (EnableJsReportAttribute)
                    filterContext.ActionDescriptor.GetCustomAttributes(typeof(EnableJsReportAttribute), true).First();
                enableJsReport = true;
            }

            return(enableJsReport);
        }
Example #6
0
        protected virtual object CreateRenderingRequest(ActionExecutedContext context,
                                                          EnableJsReportAttribute jsreportAttribute, string htmlContent)
        {
            if (context.Controller.ViewData["jsreportRenderRequest"] == null)
            {
                return new RenderRequest()
                    {
                        template = new Template
                            {
                                content = RemoveVisualStudioBrowserLink(htmlContent),
                                recipe = jsreportAttribute.Recipe ?? "phantom-pdf",
                                engine = jsreportAttribute.Engine ?? "none",
                                phantom = new Phantom
                                    {
                                        margin = jsreportAttribute.Margin,
                                        headerHeight = jsreportAttribute.HeaderHeight,
                                        header =
                                            jsreportAttribute.HeaderPartialView != null
                                                ? RenderPartialViewToString(context, jsreportAttribute.HeaderPartialView,
                                                                            null)
                                                : null,
                                        footerHeight = jsreportAttribute.FooterHeight,
                                        footer =
                                            jsreportAttribute.FooterPartialView != null
                                                ? RenderPartialViewToString(context, jsreportAttribute.FooterPartialView,
                                                                            null)
                                                : null,
                                        orientation = jsreportAttribute.Orientation,
                                        width = jsreportAttribute.Width,
                                        height = jsreportAttribute.Height,
                                        format = jsreportAttribute.Format,
                                        waitForJS = jsreportAttribute.WaitForJS,
                                        resourceTimeout = jsreportAttribute.ResourceTimeout,
                                        blockJavaScript = jsreportAttribute.BlockJavaScript,
                                        printDelay = jsreportAttribute.PrintDelay
                                    }
                            }
                    };
            }

            var originalRequest = context.Controller.ViewData["jsreportRenderRequest"];

            if (originalRequest is RenderRequest)
            {
                var castedRequest = ((RenderRequest) originalRequest);
                castedRequest.template.content = string.IsNullOrEmpty(castedRequest.template.content)
                                                     ? RemoveVisualStudioBrowserLink(htmlContent)
                                                     : castedRequest.template.content;
                return castedRequest;
            }


            dynamic request = ConvertToDynamic(originalRequest);            
            IDictionary<string, object> template = ConvertToDynamic(request.template);
            template["content"] = template.ContainsKey("content") ? template["content"] : RemoveVisualStudioBrowserLink(htmlContent);
            request.template = template;            

            return request;
        }
Example #7
0
        protected virtual async Task <Report> RenderReport(ActionExecutedContext context,
                                                           EnableJsReportAttribute jsreportAttribute, string htmlContent)
        {
            Report output = await ReportingService.RenderAsync(CreateRenderingRequest(context, jsreportAttribute, htmlContent)).ConfigureAwait(false);

            AddResponseHeaders(context, jsreportAttribute, output);

            return(output);
        }
 protected virtual void AddResponseHeaders(ActionExecutedContext context, EnableJsReportAttribute jsreportAttribute,
                                           Report report)
 {
     context.HttpContext.Response.ContentType = report.Meta.ContentType;
     if (report.Meta.ContentDisposition != null)
     {
         context.HttpContext.Response.Headers["Content-Disposition"] = report.Meta.ContentDisposition;
     }
 }
        protected virtual async Task <Report> RenderReport(ActionExecutedContext context,
                                                           EnableJsReportAttribute jsreportAttribute, string htmlContent)
        {
            IJsReportFeature feature = context.HttpContext.JsReportFeature();
            var renderingRequest     = CreateRenderingRequest(context, jsreportAttribute, htmlContent);

            renderingRequest.Template.Content = htmlContent;
            Report output = await RenderService.RenderAsync(renderingRequest).ConfigureAwait(false);

            AddResponseHeaders(context, jsreportAttribute, output);
            feature.AfterRender?.Invoke(output);

            return(output);
        }
Example #10
0
        protected virtual async Task<Report> RenderReport(ActionExecutedContext context, EnableJsReportAttribute jsreportAttribute, string htmlContent)
        {
            var output = await ReportingService.RenderAsync(new RenderRequest()
            {
                template = new Template()
                {
                    content = RemoveVisualStudioBrowserLink(htmlContent),
                    recipe = "phantom-pdf",
                    phantom = new Phantom()
                    {
                            margin = jsreportAttribute.Margin,
                            headerHeight = jsreportAttribute.HeaderHeight,
                            header = jsreportAttribute.HeaderPartialView != null ? RenderPartialViewToString(context, jsreportAttribute.HeaderPartialView, null) : null,
                            footerHeight = jsreportAttribute.FooterHeight,
                            footer = jsreportAttribute.FooterPartialView != null ? RenderPartialViewToString(context, jsreportAttribute.FooterPartialView, null) : null
                    }
                }
            }).ConfigureAwait(false);

            context.HttpContext.Response.ContentType = output.ContentType.MediaType;

            return output;
        }
        protected virtual async Task<Report> RenderReport(ActionExecutedContext context,
                                                          EnableJsReportAttribute jsreportAttribute, string htmlContent)
        {
            Report output = await ReportingService.RenderAsync(new RenderRequest
                {
                    template = new Template
                        {
                            content = RemoveVisualStudioBrowserLink(htmlContent),
                            recipe = jsreportAttribute.Recipe ?? "phantom-pdf",
                            phantom = new Phantom
                                {
                                    margin = jsreportAttribute.Margin,
                                    headerHeight = jsreportAttribute.HeaderHeight,
                                    header =
                                        jsreportAttribute.HeaderPartialView != null
                                            ? RenderPartialViewToString(context, jsreportAttribute.HeaderPartialView,
                                                                        null)
                                            : null,
                                    footerHeight = jsreportAttribute.FooterHeight,
                                    footer =
                                        jsreportAttribute.FooterPartialView != null
                                            ? RenderPartialViewToString(context, jsreportAttribute.FooterPartialView,
                                                                        null)
                                            : null,
                                    orientation = jsreportAttribute.Orientation,
                                    width = jsreportAttribute.Width,
                                    height = jsreportAttribute.Height,
                                    format = jsreportAttribute.Format
                                }
                        }
                }).ConfigureAwait(false);
           
            AddResponseHeaders(context, jsreportAttribute, output);

            return output;
        }
Example #12
0
        protected virtual async Task <Report> RenderReport(ActionExecutedContext context,
                                                           EnableJsReportAttribute jsreportAttribute, string htmlContent)
        {
            Report output = await ReportingService.RenderAsync(new RenderRequest
            {
                template = new Template
                {
                    content = RemoveVisualStudioBrowserLink(htmlContent),
                    recipe  = jsreportAttribute.Recipe ?? "phantom-pdf",
                    phantom = new Phantom
                    {
                        margin       = jsreportAttribute.Margin,
                        headerHeight = jsreportAttribute.HeaderHeight,
                        header       =
                            jsreportAttribute.HeaderPartialView != null
                                            ? RenderPartialViewToString(context, jsreportAttribute.HeaderPartialView,
                                                                        null)
                                            : null,
                        footerHeight = jsreportAttribute.FooterHeight,
                        footer       =
                            jsreportAttribute.FooterPartialView != null
                                            ? RenderPartialViewToString(context, jsreportAttribute.FooterPartialView,
                                                                        null)
                                            : null,
                        orientation = jsreportAttribute.Orientation,
                        width       = jsreportAttribute.Width,
                        height      = jsreportAttribute.Height,
                        format      = jsreportAttribute.Format
                    }
                }
            }).ConfigureAwait(false);

            AddResponseHeaders(context, jsreportAttribute, output);

            return(output);
        }
Example #13
0
        protected virtual async Task <Report> RenderReport(ActionExecutedContext context, EnableJsReportAttribute jsreportAttribute, string htmlContent)
        {
            var output = await ReportingService.RenderAsync(new RenderRequest()
            {
                template = new Template()
                {
                    content = RemoveVisualStudioBrowserLink(htmlContent),
                    recipe  = "phantom-pdf",
                    phantom = new Phantom()
                    {
                        margin       = jsreportAttribute.Margin,
                        headerHeight = jsreportAttribute.HeaderHeight,
                        header       = jsreportAttribute.HeaderPartialView != null ? RenderPartialViewToString(context, jsreportAttribute.HeaderPartialView, null) : null,
                        footerHeight = jsreportAttribute.FooterHeight,
                        footer       = jsreportAttribute.FooterPartialView != null ? RenderPartialViewToString(context, jsreportAttribute.FooterPartialView, null) : null
                    }
                }
            }).ConfigureAwait(false);

            context.HttpContext.Response.ContentType = output.ContentType.MediaType;

            return(output);
        }
        protected virtual void AddResponseHeaders(ActionExecutedContext context, EnableJsReportAttribute jsreportAttribute,
                                               Report output)
        {
            foreach (var httpResponseHeader in output.Response.Headers)
            {
                if (httpResponseHeader.Key.ToLower() == "connection" || httpResponseHeader.Key.ToLower() == "transfer-encoding")
                    continue;


                context.HttpContext.Response.AddHeader(httpResponseHeader.Key,
                                                       string.Join(";", httpResponseHeader.Value));
            }

            foreach (var httpContentHeader in output.Response.Content.Headers)
            {
                if (jsreportAttribute.ContentDisposition != null && httpContentHeader.Key.ToLower() == "content-disposition")
                {
                    context.HttpContext.Response.AddHeader(httpContentHeader.Key, jsreportAttribute.ContentDisposition);
                }
                else
                {
                    context.HttpContext.Response.AddHeader(httpContentHeader.Key,
                                                           string.Join(";", httpContentHeader.Value));
                }
            }

            context.HttpContext.Response.ContentType = output.ContentType.MediaType;
        }
        private bool ShouldUseJsReport(ActionExecutedContext filterContext, out EnableJsReportAttribute attr)
        {
            bool enableJsReport = false;
            attr = null;

            if (filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof (EnableJsReportAttribute), true))
            {
                attr =
                    (EnableJsReportAttribute)
                    filterContext.ActionDescriptor.ControllerDescriptor.GetCustomAttributes(
                        typeof (EnableJsReportAttribute), true).First();
                enableJsReport = true;
            }

            if (filterContext.ActionDescriptor.IsDefined(typeof (EnableJsReportAttribute), true))
            {
                attr =
                    (EnableJsReportAttribute)
                    filterContext.ActionDescriptor.GetCustomAttributes(typeof (EnableJsReportAttribute), true).First();
                enableJsReport = true;
            }

            return enableJsReport;
        }
Example #16
0
        protected virtual bool ShouldUseJsReport(ActionExecutedContext filterContext, out EnableJsReportAttribute attr)
        {
            if ((filterContext.Exception != null && !filterContext.ExceptionHandled) || filterContext.Canceled)
            {
                attr = null;
                return false;
            }

            if (!filterContext.Controller.ViewData.ModelState.IsValid)
            {
                attr = null;
                return false;
            }

            bool enableJsReport = false;
            attr = null;

            if (filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof (EnableJsReportAttribute), true))
            {
                attr =
                    (EnableJsReportAttribute)
                    filterContext.ActionDescriptor.ControllerDescriptor.GetCustomAttributes(
                        typeof (EnableJsReportAttribute), true).First();
                enableJsReport = true;
            }

            if (filterContext.ActionDescriptor.IsDefined(typeof (EnableJsReportAttribute), true))
            {
                attr =
                    (EnableJsReportAttribute)
                    filterContext.ActionDescriptor.GetCustomAttributes(typeof (EnableJsReportAttribute), true).First();
                enableJsReport = true;
            }

            return enableJsReport;
        }
Example #17
0
        protected virtual async Task<Report> RenderReport(ActionExecutedContext context,
                                                          EnableJsReportAttribute jsreportAttribute, string htmlContent)
        {
            Report output = await ReportingService.RenderAsync(CreateRenderingRequest(context, jsreportAttribute, htmlContent)).ConfigureAwait(false);
           
            AddResponseHeaders(context, jsreportAttribute, output);

            return output;
        }
Example #18
0
        protected virtual bool ShouldUseJsReport(ActionExecutedContext filterContext, out EnableJsReportAttribute attr)
        {
            if ((filterContext.Exception != null && !filterContext.ExceptionHandled) || filterContext.Canceled)
            {
                attr = null;
                return(false);
            }

            if (!filterContext.Controller.ViewData.ModelState.IsValid)
            {
                attr = null;
                return(false);
            }

            bool enableJsReport = false;

            attr = null;

            if (filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(EnableJsReportAttribute), true))
            {
                attr =
                    (EnableJsReportAttribute)
                    filterContext.ActionDescriptor.ControllerDescriptor.GetCustomAttributes(
                        typeof(EnableJsReportAttribute), true).First();
                enableJsReport = true;
            }

            if (filterContext.ActionDescriptor.IsDefined(typeof(EnableJsReportAttribute), true))
            {
                attr =
                    (EnableJsReportAttribute)
                    filterContext.ActionDescriptor.GetCustomAttributes(typeof(EnableJsReportAttribute), true).First();
                enableJsReport = true;
            }

            return(enableJsReport);
        }
 protected virtual RenderRequest CreateRenderingRequest(ActionExecutedContext context,
                                                        EnableJsReportAttribute jsreportAttribute, string htmlContent)
 {
     return(context.HttpContext.JsReportFeature().RenderRequest);
 }