/// <summary>
        /// Constructs a successful result with the report
        /// </summary>
        /// <param name="section">The report section generated</param>
        /// <param name="executionTime">The execution time</param>
        /// <param name="errorMessages">The error messages</param>
        internal ReportSectionGenerationResult
        (
            ReportSection section,
            long executionTime,
            params string[] errorMessages
        )

            : base(executionTime, errorMessages)
        {
            Validate.IsNotNull(section);

            this.Section = section;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds the page footer to the report
        /// </summary>
        /// <param name="section">The report section</param>
        /// <returns>The updated report</returns>
        public Report WithPageFooter
        (
            ReportSection section
        )
        {
            Validate.IsNotNull(section);

            this.PageFooter = section;

            if (section.HasData)
            {
                this.HasData = true;
            }

            return(this);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds the body to the report
        /// </summary>
        /// <param name="section">The report section</param>
        /// <returns>The updated report</returns>
        public Report WithBody
        (
            ReportSection section
        )
        {
            Validate.IsNotNull(section);

            this.Body = section;

            if (section.HasData)
            {
                this.HasData = true;
            }

            return(this);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Asynchronously generates a report section from a report definition
        /// </summary>
        /// <param name="report">The report definition</param>
        /// <param name="filter">The report filter</param>
        /// <param name="sectionType">The section type</param>
        /// <returns>The generated section</returns>
        private async Task <ReportSectionGenerationResult> GenerateSectionAsync
        (
            ReportDefinition report,
            ReportFilter filter,
            ReportSectionType sectionType
        )
        {
            var watch = Stopwatch.StartNew();

            var sectionDefinition = report.GetSection
                                    (
                sectionType
                                    );

            if (sectionDefinition == null)
            {
                return(null);
            }
            else
            {
                var generationTasks   = new Dictionary <string, Task <IReportComponent> >();
                var componentList     = new List <IReportComponent>();
                var errorMessages     = new List <string>();
                var handledExceptions = new List <Exception>();

                // Build a dictionary of component generation tasks
                foreach (var componentDefinition in sectionDefinition.Components)
                {
                    var componentName = componentDefinition.Name;

                    var isExcluded = filter.IsExcluded
                                     (
                        componentName
                                     );

                    if (false == isExcluded)
                    {
                        var componentType      = componentDefinition.ComponentType;
                        var componentGenerator = componentType.GetGenerator();

                        var task = componentGenerator.GenerateAsync
                                   (
                            componentDefinition,
                            sectionType,
                            filter
                                   );

                        generationTasks.Add
                        (
                            componentName,
                            task
                        );
                    }
                }

                try
                {
                    await Task.WhenAll
                    (
                        generationTasks.Select(pair => pair.Value)
                    )
                    .ConfigureAwait
                    (
                        false
                    );

                    // Compile the results of each task once they have completed
                    foreach (var item in generationTasks)
                    {
                        componentList.Add
                        (
                            await item.Value.ConfigureAwait(false)
                        );
                    }
                }
                catch (Exception ex)
                {
                    errorMessages.Add(ex.Message);
                    handledExceptions.Add(ex);
                }

                watch.Stop();

                var section = new ReportSection
                              (
                    sectionDefinition.Title,
                    sectionDefinition.Description,
                    sectionType,
                    componentList.ToArray()
                              );

                var result = new ReportSectionGenerationResult
                             (
                    section,
                    watch.ElapsedMilliseconds,
                    errorMessages.ToArray()
                             );

                if (handledExceptions.Any())
                {
                    result.AddExceptions(handledExceptions);
                }

                return(result);
            }
        }