Esempio n. 1
0
        public void Vizualize([NotNull] HtmlTextWriter htmlTextWriter,
                              [NotNull] BoolReportBlock block,
                              IReadOnlyDictionary <string, object> parameterValues,
                              IReadOnlyCollection <ReportQueryResult> queryResults,
                              long userId)
        {
            if (htmlTextWriter == null)
            {
                throw new ArgumentNullException(nameof(htmlTextWriter));
            }
            if (block == null)
            {
                throw new ArgumentNullException(nameof(block));
            }

            var templateSource = $"$if({block.Variable})$1$endif$";

            var template = _templateBuilder.Build(templateSource);

            if (parameterValues != null)
            {
                foreach (var parameterValue in parameterValues)
                {
                    template.Add(parameterValue.Key, parameterValue.Value);
                }
            }

            var result = template.Render();

            if (result.Equals("1"))
            {
                if (block.Positive != null)
                {
                    _reportBlockVizualizationManager.Vizualize(
                        htmlTextWriter,
                        (dynamic)block.Positive,
                        parameterValues,
                        queryResults,
                        userId);
                }
            }
            else
            {
                if (block.Negative != null)
                {
                    _reportBlockVizualizationManager.Vizualize(
                        htmlTextWriter,
                        (dynamic)block.Negative,
                        parameterValues,
                        queryResults,
                        userId);
                }
            }
        }
        private void RenderBody(HtmlTextWriter htmlWriter, TableReportBlock block, QueryResult queryBlock, long userId)
        {
            var tableBodyStyle = new HtmlStyle();

            tableBodyStyle.Set(HtmlStyleKey.Border, $"{block.BorderPx}px solid black");

            htmlWriter.RenderBeginTag(HtmlTextWriterTag.Tbody);

            foreach (var row in queryBlock.Items)
            {
                htmlWriter.AddAttribute(HtmlTextWriterAttribute.Style, tableBodyStyle.ToString());
                htmlWriter.RenderBeginTag(HtmlTextWriterTag.Tr);

                foreach (var column in queryBlock.Columns)
                {
                    htmlWriter.AddAttribute(HtmlTextWriterAttribute.Style, tableBodyStyle.ToString());
                    htmlWriter.RenderBeginTag(HtmlTextWriterTag.Td);

                    var columnItem = row.Value.GetType()
                                     .GetProperty(column.Code)
                                     .GetValue(row.Value);

                    if (columnItem != null)
                    {
                        _blockVizualizationManager.Vizualize(
                            htmlWriter,
                            (dynamic)block.BodyLabel,
                            new ConcurrentDictionary <string, object>(
                                new[]
                        {
                            new KeyValuePair <string, object>(TableReportBlockParameters.RowColumnItem, columnItem.ToString())
                        }),
                            null,
                            userId);
                    }

                    htmlWriter.RenderEndTag();                     // Td
                }

                htmlWriter.RenderEndTag();                 // Tr
            }

            htmlWriter.RenderEndTag();             // Tbody
        }
        public void Vizualize(
            [NotNull] HtmlTextWriter htmlTextWriter,
            [NotNull] QueryScopeReportBlock block,
            IReadOnlyDictionary <string, object> parameterValues,
            IReadOnlyCollection <ReportQueryResult> queryResults,
            long userId)
        {
            if (htmlTextWriter == null)
            {
                throw new ArgumentNullException(nameof(htmlTextWriter));
            }
            if (block == null)
            {
                throw new ArgumentNullException(nameof(block));
            }

            if (block.Child == null)
            {
                throw new Exception("Empty child block");                 // TODO: normal exception
            }
            var queryParameters = GetQueryParameters(block, parameterValues);

            var scopeQueryResult = _reportQueryLinkDirector.Execute(
                userId,
                (dynamic)block.Query,
                queryParameters);

            var childQueries = new List <ReportQueryResult>();

            if (queryResults != null)
            {
                // ReSharper disable once LoopCanBeConvertedToQuery
                foreach (var queryResult in queryResults)
                {
                    childQueries.Add(queryResult);
                }
            }

            childQueries.Add(
                new ReportQueryResult
            {
                Key    = block.Query.Key,
                Result = scopeQueryResult
            });

            _reportBlockVizualizationManager.Vizualize(
                htmlTextWriter,
                (dynamic)block.Child,
                parameterValues,
                childQueries,
                userId);
        }
Esempio n. 4
0
        public void Vizualize([NotNull] HtmlTextWriter htmlTextWriter,
                              [NotNull] LinkReportBlock block,
                              IReadOnlyDictionary <string, object> parameterValues,
                              IReadOnlyCollection <ReportQueryResult> queryResults,
                              long userId)
        {
            if (htmlTextWriter == null)
            {
                throw new ArgumentNullException(nameof(htmlTextWriter));
            }
            if (block == null)
            {
                throw new ArgumentNullException(nameof(block));
            }

            if (block.Target == null)
            {
                throw new EmptyLinkReportBlockTargetException(block.Id);
            }

            if (block.Child == null)
            {
                throw new EmptyLinkReportBlockChildException(block.Id);
            }

            var template = _templateBuilder.Build(block.Target);

            if (parameterValues != null)
            {
                foreach (var parameterValue in parameterValues)
                {
                    template.Add(parameterValue.Key, parameterValue.Value);
                }
            }

            var renderedTemplate = template.Render();

            renderedTemplate = _htmlEncoder.Encode(renderedTemplate);

            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Href, renderedTemplate);
            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.A);

            _blockVizualizationManager.Vizualize(
                htmlTextWriter,
                (dynamic)block.Child,
                parameterValues,
                queryResults,
                userId);

            htmlTextWriter.RenderEndTag();
        }
        protected override void ExecuteStage(ReportBundle reportBundle)
        {
            if (reportBundle.Rule.Template.Root == null)
            {
                throw new EmptyReportRuleTemplateException(reportBundle);
            }

            using (var stringWriter = new StringWriter())
            {
                using (var htmlTextWriter = new HtmlTextWriter(stringWriter))
                {
                    _reportBlockVizualizationManager.Vizualize(
                        htmlTextWriter,
                        (dynamic)reportBundle.Rule.Template.Root,
                        reportBundle.ParameterValues,
                        reportBundle.QueryResults,
                        reportBundle.TargetUserId);
                }

                reportBundle.BodyHtml = stringWriter.ToString();
            }
        }
        public void Vizualize(
            [NotNull] HtmlTextWriter htmlTextWriter,
            [NotNull] IteratorReportBlock block,
            IReadOnlyDictionary <string, object> parameterValues,
            IReadOnlyCollection <ReportQueryResult> queryResults,
            long userId)
        {
            if (htmlTextWriter == null)
            {
                throw new ArgumentNullException(nameof(htmlTextWriter));
            }
            if (block == null)
            {
                throw new ArgumentNullException(nameof(block));
            }

            if (string.IsNullOrEmpty(block.QueryKey))
            {
                throw new IncorrectBlockQueryKeyException(block);
            }

            var query = queryResults
                        .SingleOrDefault(_ => _.Key.Equals(block.QueryKey, StringComparison.InvariantCultureIgnoreCase));

            if (query == null)
            {
                throw new QueryResultNotFoundException(block);
            }

            if (block.Child == null)
            {
                return;
            }

            var iteratorStyle = new HtmlStyle();

            iteratorStyle.Set(HtmlStyleKey.Width, "100%");
            iteratorStyle.Set(HtmlStyleKey.Float, "none");

            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Style, iteratorStyle.ToString());
            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Id, block.Id);
            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Div);

            var i = 1;

            var queryItemKey = $"{query.Key}Item";

            foreach (var resultItem in query.Result.Items)
            {
                htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Style, iteratorStyle.ToString());
                htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Id, $"{block.Id}-Item{i}");
                htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Div);

                var childParameters = parameterValues.ToDictionary(
                    paramValue => paramValue.Key,
                    paramValue => paramValue.Value);

                childParameters.Add(queryItemKey, resultItem.Value);

                _reportBlockVizualizationManager.Vizualize(
                    htmlTextWriter,
                    (dynamic)block.Child,
                    childParameters,
                    queryResults,
                    userId);

                htmlTextWriter.RenderEndTag();                 // div

                i++;
            }

            htmlTextWriter.RenderEndTag();             // div
        }
Esempio n. 7
0
        private void RenderTableContainer(HtmlTextWriter htmlTextWriter,
                                          ContainerReportBlock block,
                                          IReadOnlyDictionary <string, object> parameterValues,
                                          IReadOnlyCollection <ReportQueryResult> queryResults,
                                          long userId)
        {
            var baseDivStyle = new HtmlStyle();

            baseDivStyle
            .Set(HtmlStyleKey.Width, "100%")
            .Set(HtmlStyleKey.Float, "none");

            if (block.BreakPageBefore)
            {
                baseDivStyle.Set("page-break-before", "always");
            }

            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Style, baseDivStyle.ToString());
            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Id, block.Id);
            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Table);
            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Tbody);
            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Tr);
            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Td);

            var innerDivStyle = new HtmlStyle();

            var backgroundColor = block.BackgroundColor.ToRgb();

            innerDivStyle
            .Set(HtmlStyleKey.BackgroundColor, backgroundColor)
            .Set(HtmlStyleKey.Width, "100%")

            // unnessesary for the inner div block
            .Set(HtmlStyleKey.MarginBottom, $"{block.MarginBottomPx}px")
            .Set(HtmlStyleKey.MarginLeft, $"{block.MarginLeftPx}px")
            .Set(HtmlStyleKey.MarginRight, $"{block.MarginRightPx}px")
            .Set(HtmlStyleKey.MarginTop, $"{block.MarginTopPx}px")
            .Set(HtmlStyleKey.PaddingBottom, $"{block.PaddingBottomPx}px")
            .Set(HtmlStyleKey.PaddingLeft, $"{block.PaddingLeftPx}px")
            .Set(HtmlStyleKey.PaddingRight, $"{block.PaddingRightPx}px")
            .Set(HtmlStyleKey.PaddingTop, $"{block.PaddingTopPx}px");

            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Style, innerDivStyle.ToString());
            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Id, $"{block.Id}-Inner");
            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Table);
            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Tbody);

            if (block.Orientation == ContainerOrientation.Horizontal)
            {
                htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Tr);
            }

            if (block.Childs != null)
            {
                var i = 0;

                foreach (var child in block.Childs)
                {
                    var divWidth = 100;

                    if (block.Orientation == ContainerOrientation.Horizontal)
                    {
                        if (block.ChildProportions == null)
                        {
                            divWidth = 100 / block.Childs.Length;
                        }
                        else
                        {
                            divWidth = block.ChildProportions[i];
                        }
                    }

                    if (block.Orientation == ContainerOrientation.Vertical)
                    {
                        htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Tr);
                    }

                    var childDivStyle = new HtmlStyle();

                    childDivStyle
                    .Set(HtmlStyleKey.BackgroundColor, backgroundColor)
                    .Set(HtmlStyleKey.Width, $"{divWidth}%");

                    htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Style, childDivStyle.ToString());
                    htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Id, $"{block.Id}-Child{i + 1}");

                    htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Td);

                    _reportBlockVizualizationManager.Vizualize(
                        htmlTextWriter,
                        (dynamic)child,
                        parameterValues,
                        queryResults,
                        userId);

                    htmlTextWriter.RenderEndTag();                     // TD

                    if (block.Orientation == ContainerOrientation.Vertical)
                    {
                        htmlTextWriter.RenderEndTag();                         // TR
                    }

                    i++;
                }
            }

            if (block.Orientation == ContainerOrientation.Horizontal)
            {
                htmlTextWriter.RenderEndTag();         // TR
            }
            htmlTextWriter.RenderEndTag();             //outher table TBody
            htmlTextWriter.RenderEndTag();             //outher Table

            htmlTextWriter.RenderEndTag();             //outher table TD
            htmlTextWriter.RenderEndTag();             //outher table TR
            htmlTextWriter.RenderEndTag();             //outher table TBody
            htmlTextWriter.RenderEndTag();             //outher Table
        }
Esempio n. 8
0
        public void Vizualize(
            [NotNull] HtmlTextWriter htmlTextWriter,
            [NotNull] HtmlDocReportBlock block,
            IReadOnlyDictionary <string, object> parameterValues,
            IReadOnlyCollection <ReportQueryResult> queryResults,
            long userId)
        {
            if (htmlTextWriter == null)
            {
                throw new ArgumentNullException(nameof(htmlTextWriter));
            }
            if (block == null)
            {
                throw new ArgumentNullException(nameof(block));
            }

            var docType = new StringBuilder(block.WithHeader ? "<!DOCTYPE html>" : string.Empty);

            htmlTextWriter.Write(docType);

            if (block.WithHeader)
            {
                htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Html);
                htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Head);
                htmlTextWriter.AddAttribute("charset", "UTF-8");
                htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Meta);
                htmlTextWriter.RenderEndTag();                 // meta
            }

            RenderChartScript(htmlTextWriter);

            if (block.WithHeader)
            {
                htmlTextWriter.RenderEndTag();                 // head
                htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Body);
            }

            var containerStyle = new HtmlStyle();

            containerStyle
            .Set(HtmlStyleKey.Width, block.Width)
            .Set(HtmlStyleKey.AlignContent, "center")
            .Set(HtmlStyleKey.Margin, "0 auto");

            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Style, containerStyle.ToString());
            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Id, block.Id);
            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Div);             // div

            _reportBlockVizualizationManager.Vizualize(
                htmlTextWriter,
                (dynamic)block.Child,
                parameterValues,
                queryResults,
                userId);

            htmlTextWriter.RenderEndTag();             // div

            // ReSharper disable once InvertIf
            if (block.WithHeader)
            {
                htmlTextWriter.RenderEndTag();                 // body
                htmlTextWriter.RenderEndTag();                 // html
            }
        }