Пример #1
0
        /// <summary>
        /// Gets the component definition as the type specified
        /// </summary>
        /// <typeparam name="T">The definition type</typeparam>
        /// <param name="definition">The definition instance</param>
        /// <returns>The converted definition</returns>
        public static T As <T>
        (
            this IReportComponentDefinition definition
        )
            where T : IReportComponentDefinition
        {
            var actualType = definition.GetType();

            if (actualType != typeof(T))
            {
                if (false == typeof(T).IsAssignableFrom(actualType))
                {
                    var message = "The component {0} cannot be converted to {1}.";

                    throw new InvalidCastException
                          (
                              String.Format
                              (
                                  message,
                                  actualType.Name,
                                  typeof(T).Name
                              )
                          );
                }
                else
                {
                    return((T)definition);
                }
            }
            else
            {
                return((T)definition);
            }
        }
Пример #2
0
        /// <summary>
        /// Constructs the report component with the details
        /// </summary>
        /// <param name="definition">The component definition</param>
        protected ReportComponentBase
        (
            IReportComponentDefinition definition
        )
        {
            Validate.IsNotNull(definition);

            this.ComponentDefinition = definition;
            this.Fields = definition.Fields;
            this.Style  = definition.Style;
        }
Пример #3
0
        /// <summary>
        /// Asynchronously generates a component from a report definition and filter
        /// </summary>
        /// <param name="definition">The component definition</param>
        /// <param name="sectionType">The report section type</param>
        /// <param name="filter">The report filter</param>
        /// <returns>The report component generated</returns>
        public override async Task <IReportComponent> GenerateAsync
        (
            IReportComponentDefinition definition,
            ReportSectionType sectionType,
            ReportFilter filter
        )
        {
            Validate.IsNotNull(definition);
            Validate.IsNotNull(filter);

            var statisticDefinition = definition.As <StatisticDefinition>();
            var function            = statisticDefinition.Function;
            var query             = statisticDefinition.Query;
            var defaultParameters = statisticDefinition.DefaultParameterValues;

            var parameters = filter.GetQueryParameters
                             (
                query,
                defaultParameters.ToArray()
                             );

            var task = function.ExecuteAsync
                       (
                query,
                parameters.ToArray()
                       );

            var value = await task.ConfigureAwait(false);

            var statistic = new Statistic
                            (
                statisticDefinition,
                value
                            );

            if (statisticDefinition.Action != null)
            {
                statistic = statistic.WithAction
                            (
                    statisticDefinition.Action
                            );
            }

            if (statisticDefinition.HasRange)
            {
                statistic = statistic.WithRange
                            (
                    statisticDefinition.LowerRange,
                    statisticDefinition.UpperRange
                            );
            }

            return(statistic);
        }
        /// <summary>
        /// Generates a component from a report definition and filter
        /// </summary>
        /// <param name="definition">The component definition</param>
        /// <param name="sectionType">The report section type</param>
        /// <param name="filter">The report filter</param>
        /// <returns>The report component generated</returns>
        public virtual IReportComponent Generate
        (
            IReportComponentDefinition definition,
            ReportSectionType sectionType,
            ReportFilter filter
        )
        {
            var task = GenerateAsync
                       (
                definition,
                sectionType,
                filter
                       );

            return(task.WaitAndUnwrapException());
        }
        /// <summary>
        /// Constructs the nested component definition with the details
        /// </summary>
        /// <param name="definition">The component definition</param>
        /// <param name="parameterBindings">The parameter bindings</param>
        public NestedReportComponentDefinition
        (
            IReportComponentDefinition definition,
            params ReportParameterBinding[] parameterBindings
        )
        {
            Validate.IsNotNull(definition);

            this.Definition        = definition;
            this.ParameterBindings = new Collection <ReportParameterBinding>();

            if (parameterBindings != null)
            {
                foreach (var binding in parameterBindings)
                {
                    this.ParameterBindings.Add(binding);
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Asynchronously generates a component from a report definition and filter
        /// </summary>
        /// <param name="definition">The component definition</param>
        /// <param name="sectionType">The report section type</param>
        /// <param name="filter">The report filter</param>
        /// <returns>The report component generated</returns>
        public override Task <IReportComponent> GenerateAsync
        (
            IReportComponentDefinition definition,
            ReportSectionType sectionType,
            ReportFilter filter
        )
        {
            Validate.IsNotNull(definition);

            var seperator = new Separator
                            (
                (SeparatorDefinition)definition
                            );

            return(Task.FromResult <IReportComponent>
                   (
                       seperator
                   ));
        }
 /// <summary>
 /// Asynchronously generates a component from a report definition and filter
 /// </summary>
 /// <param name="definition">The component definition</param>
 /// <param name="sectionType">The report section type</param>
 /// <param name="filter">The report filter</param>
 /// <returns>The report component generated</returns>
 public abstract Task <IReportComponent> GenerateAsync
 (
     IReportComponentDefinition definition,
     ReportSectionType sectionType,
     ReportFilter filter
 );
Пример #8
0
        /// <summary>
        /// Asynchronously generates a component from a report definition and filter
        /// </summary>
        /// <param name="definition">The component definition</param>
        /// <param name="sectionType">The report section type</param>
        /// <param name="filter">The report filter</param>
        /// <returns>The report component generated</returns>
        public override async Task <IReportComponent> GenerateAsync
        (
            IReportComponentDefinition definition,
            ReportSectionType sectionType,
            ReportFilter filter
        )
        {
            Validate.IsNotNull(definition);
            Validate.IsNotNull(filter);

            var repeaterDefinition = definition.As <RepeaterDefinition>();
            var query             = repeaterDefinition.Query;
            var defaultParameters = repeaterDefinition.DefaultParameterValues;

            var parameters = filter.GetQueryParameters
                             (
                query,
                defaultParameters.ToArray()
                             );

            var queryTask = query.ExecuteAsync
                            (
                parameters.ToArray()
                            );

            var results = await queryTask.ConfigureAwait
                          (
                false
                          );

            var generatedItems = new List <RepeaterItem>();
            var itemTasks      = new List <Task <RepeaterItem> >();

            foreach (var row in results.AllRows)
            {
                itemTasks.Add
                (
                    GenerateItemAsync
                    (
                        repeaterDefinition,
                        sectionType,
                        filter,
                        row
                    )
                );
            }

            await Task.WhenAll
            (
                itemTasks.ToArray()
            )
            .ConfigureAwait
            (
                false
            );

            foreach (var task in itemTasks)
            {
                generatedItems.Add
                (
                    await task.ConfigureAwait(false)
                );
            }

            if (false == repeaterDefinition.DisableSorting)
            {
                var sortDirection = filter.FindSortDirection
                                    (
                    sectionType,
                    definition.Name,
                    "Item"
                                    );

                // Apply the sorting direction, if it has been specified
                if (sortDirection != null)
                {
                    if (sortDirection.Value == SortDirection.Ascending)
                    {
                        generatedItems = generatedItems.OrderBy
                                         (
                            a => a.Value
                                         )
                                         .ToList();
                    }
                    else
                    {
                        generatedItems = generatedItems.OrderByDescending
                                         (
                            a => a.Value
                                         )
                                         .ToList();
                    }
                }
            }

            var repeater = new Repeater
                           (
                repeaterDefinition,
                generatedItems.ToArray()
                           );

            return(repeater);
        }
Пример #9
0
        /// <summary>
        /// Asynchronously generates a component from a report definition and filter
        /// </summary>
        /// <param name="definition">The component definition</param>
        /// <param name="sectionType">The report section type</param>
        /// <param name="filter">The report filter</param>
        /// <returns>The report component generated</returns>
        public override async Task <IReportComponent> GenerateAsync
        (
            IReportComponentDefinition definition,
            ReportSectionType sectionType,
            ReportFilter filter
        )
        {
            Validate.IsNotNull(definition);
            Validate.IsNotNull(filter);

            Table table;

            var tableDefinition   = definition.As <TableDefinition>();
            var query             = tableDefinition.Query;
            var defaultParameters = tableDefinition.DefaultParameterValues;

            var queryTask = query.ExecuteAsync
                            (
                filter,
                defaultParameters.ToArray()
                            );

            var results = await queryTask.ConfigureAwait
                          (
                false
                          );

            var columnsTask = GetColumnsDynamicallyAsync
                              (
                tableDefinition,
                filter
                              );

            var columnDefinitions = await columnsTask.ConfigureAwait
                                    (
                false
                                    );

            if (results.HasMultipleGroupings)
            {
                var tableGroups = new List <TableGrouping>();

                foreach (var queryGroup in results.Groupings)
                {
                    var groupRows = BuildTableRows
                                    (
                        tableDefinition,
                        sectionType,
                        filter,
                        queryGroup.Rows
                                    );

                    var tableGroup = new TableGrouping
                                     (
                        queryGroup.GroupingValues,
                        groupRows.ToArray()
                                     );

                    if (groupRows.Any() && tableDefinition.HasTotals)
                    {
                        var totals = GenerateTotals
                                     (
                            tableDefinition,
                            filter,
                            queryGroup.Rows
                                     );

                        tableGroup.SetTotals(totals);
                    }

                    tableGroups.Add(tableGroup);
                }

                table = new Table
                        (
                    tableDefinition,
                    columnDefinitions,
                    tableGroups
                        );
            }
            else
            {
                var tableRows = BuildTableRows
                                (
                    tableDefinition,
                    sectionType,
                    filter,
                    results.AllRows
                                );

                table = new Table
                        (
                    tableDefinition,
                    columnDefinitions,
                    tableRows
                        );
            }

            if (table.AllRows.Any() && tableDefinition.HasTotals)
            {
                var totals = GenerateTotals
                             (
                    tableDefinition,
                    filter,
                    results.AllRows
                             );

                table.SetTotals(totals);
            }

            _columnValueCache.Clear();

            return(table);
        }
Пример #10
0
        /// <summary>
        /// Asynchronously generates a component from a report definition and filter
        /// </summary>
        /// <param name="definition">The component definition</param>
        /// <param name="sectionType">The report section type</param>
        /// <param name="filter">The report filter</param>
        /// <returns>The report component generated</returns>
        public override async Task <IReportComponent> GenerateAsync
        (
            IReportComponentDefinition definition,
            ReportSectionType sectionType,
            ReportFilter filter
        )
        {
            Validate.IsNotNull(definition);
            Validate.IsNotNull(filter);

            var graphicDefinition = definition.As <GraphicDefinition>();

            var graphic = new Graphic
                          (
                graphicDefinition
                          );

            if (graphicDefinition.OverlayStatistics.Any())
            {
                var statisticGenerator = new StatisticGenerator();

                var statisticDefinitions = graphicDefinition.OverlayStatistics.SelectMany
                                           (
                    pair => pair.Value.Select
                    (
                        item => item
                    )
                                           );

                var statisticTasks = new List <Task <IReportComponent> >();

                foreach (var item in statisticDefinitions)
                {
                    statisticTasks.Add
                    (
                        statisticGenerator.GenerateAsync
                        (
                            item,
                            sectionType,
                            filter
                        )
                    );
                }

                await Task.WhenAll(statisticTasks).ConfigureAwait
                (
                    false
                );

                var taskIndex = 0;

                foreach (var item in graphicDefinition.OverlayStatistics)
                {
                    var statisticList = new List <Statistic>();

                    foreach (var statisticDefinition in item.Value)
                    {
                        var task = statisticTasks.ElementAt
                                   (
                            taskIndex
                                   );

                        var statistic = await task.ConfigureAwait(false) as Statistic;

                        statisticList.Add(statistic);

                        taskIndex++;
                    }

                    graphic.OverlayStatistics.Add
                    (
                        item.Key,
                        statisticList
                    );
                }
            }

            return(graphic);
        }
Пример #11
0
        /// <summary>
        /// Asynchronously generates a component from a report definition and filter
        /// </summary>
        /// <param name="definition">The component definition</param>
        /// <param name="sectionType">The report section type</param>
        /// <param name="filter">The report filter</param>
        /// <returns>The report component generated</returns>
        public override async Task <IReportComponent> GenerateAsync
        (
            IReportComponentDefinition definition,
            ReportSectionType sectionType,
            ReportFilter filter
        )
        {
            Validate.IsNotNull(definition);
            Validate.IsNotNull(filter);

            var chartDefinition = definition.As <ChartDefinition>();
            var queryTasks      = new Dictionary <ChartDataSetDefinition, Task <QueryResults> >();
            var dataSets        = new List <ChartDataSet>();

            // Build a dictionary of query tasks to execute
            foreach (var setDefinition in chartDefinition.DataSets)
            {
                var query             = setDefinition.Query;
                var defaultParameters = setDefinition.DefaultParameterValues;

                var parameterValues = filter.GetQueryParameters
                                      (
                    query,
                    defaultParameters.ToArray()
                                      );

                var task = query.ExecuteAsync
                           (
                    parameterValues.ToArray()
                           );

                queryTasks.Add(setDefinition, task);
            }

            await Task.WhenAll
            (
                queryTasks.Select(pair => pair.Value)
            )
            .ConfigureAwait
            (
                false
            );

            var labelList = new List <ChartAxisLabel>();

            // Compile and process the results of each query
            foreach (var item in queryTasks)
            {
                var dataPoints    = new List <ChartDataPoint>();
                var setDefinition = item.Key;

                var queryResults = await item.Value.ConfigureAwait
                                   (
                    false
                                   );

                if (queryResults.AllRows.Any())
                {
                    var rowNumber = 1;

                    foreach (var row in queryResults.AllRows)
                    {
                        var xLabelValue = default(object);

                        var xValue = setDefinition.XAxisBinding.Resolve <double>
                                     (
                            row
                                     );

                        if (setDefinition.XAxisLabelBinding == null)
                        {
                            xLabelValue = xValue;
                        }
                        else
                        {
                            xLabelValue = setDefinition.XAxisLabelBinding.Resolve
                                          (
                                row
                                          );
                        }

                        var xLabel = GenerateLabel
                                     (
                            xLabelValue,
                            rowNumber,
                            chartDefinition.XAxisLabelTemplate
                                     );

                        var yValue = setDefinition.YAxisBinding.Resolve <double>
                                     (
                            row
                                     );

                        var point = new ChartDataPoint
                                    (
                            xValue,
                            yValue,
                            setDefinition.Color
                                    );

                        dataPoints.Add(point);

                        if (false == labelList.Any(l => l.Text == xLabel.Text))
                        {
                            labelList.Add(xLabel);
                        }
                    }

                    var set = new ChartDataSet
                              (
                        setDefinition.Name,
                        dataPoints.ToArray()
                              );

                    dataSets.Add(set);

                    rowNumber++;
                }
            }

            var chart = new Chart
                        (
                chartDefinition,
                labelList,
                dataSets.ToArray()
                        );

            return(chart);
        }