/// <summary> /// Asynchronously generates a nested components for a query row /// </summary> /// <param name="repeaterDefinition">The repeater definition</param> /// <param name="sectionType">The section type</param> /// <param name="parentFilter">The parent report filter</param> /// <param name="row">The query row</param> /// <returns>The nested components generated</returns> private async Task <IReportComponent[]> GenerateNestedComponentsAsync ( RepeaterDefinition repeaterDefinition, ReportSectionType sectionType, ReportFilter parentFilter, QueryRow row ) { var generationTasks = new List <Task <IReportComponent> >(); var componentList = new List <IReportComponent>(); foreach (var nestedComponent in repeaterDefinition.NestedComponents) { var componentDefinition = nestedComponent.Definition; var componentName = componentDefinition.Name; var isExcluded = parentFilter.IsExcluded ( componentName ); if (false == isExcluded) { var componentType = componentDefinition.ComponentType; var componentGenerator = componentType.GetGenerator(); var nestedFilter = nestedComponent.GenerateNestedFilter ( parentFilter, row ); var task = componentGenerator.GenerateAsync ( componentDefinition, sectionType, nestedFilter ); generationTasks.Add(task); } } await Task.WhenAll ( generationTasks.ToArray() ) .ConfigureAwait ( false ); foreach (var task in generationTasks) { componentList.Add ( await task.ConfigureAwait(false) ); } return(componentList.ToArray()); }
/// <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); } }