/// <summary>
        /// Configures a registered report
        /// </summary>
        /// <param name="reportName">The report name</param>
        /// <param name="configuration">The report configuration</param>
        public void ConfigureReport
        (
            string reportName,
            RegisteredReportConfiguration configuration
        )
        {
            var report = _reportRepository.GetReport
                         (
                reportName
                         );

            report.Configure(configuration);

            _reportRepository.UpdateReport(report);
            _unitOfWork.SaveChanges();
        }
Beispiel #2
0
        /// <summary>
        /// Asynchronously generates a report from a registered report and filter values
        /// </summary>
        /// <param name="reportName">The report name</param>
        /// <param name="filterValues">The filter values</param>
        /// <param name="userInfo">The user information</param>
        /// <returns>The generation result</returns>
        public async Task <ReportGenerationResult> GenerateAsync
        (
            string reportName,
            SubmittedReportFilterValues filterValues,
            ReportUserInfo userInfo
        )
        {
            Validate.IsNotEmpty(reportName);
            Validate.IsNotNull(filterValues);
            Validate.IsNotNull(userInfo);

            var watch = Stopwatch.StartNew();

            var hasAccess = CanUserAccessReport
                            (
                reportName,
                userInfo
                            );

            if (false == hasAccess)
            {
                watch.Stop();

                return(new ReportGenerationResult
                       (
                           null,
                           watch.ElapsedMilliseconds,
                           "The user is not authorized to generate the report."
                       ));
            }

            var registeredReport = _reportRepository.GetReport
                                   (
                reportName
                                   );

            if (registeredReport.Disabled)
            {
                watch.Stop();

                return(new ReportGenerationResult
                       (
                           null,
                           watch.ElapsedMilliseconds,
                           "The report cannot be generated because it is disabled."
                       ));
            }

            var reportDefinition = _definitionBuilder.Build
                                   (
                registeredReport,
                _queryRepository
                                   );

            var reportFilter = BuildReportFilter
                               (
                registeredReport,
                reportDefinition,
                filterValues,
                userInfo
                               );

            var options = new ReportGenerationOptions()
            {
                Culture           = userInfo.Culture,
                PreferredLanguage = userInfo.PreferredLanguage
            };

            var task = _reportGenerator.GenerateAsync
                       (
                reportDefinition,
                reportFilter,
                options
                       );

            var result = await task.ConfigureAwait
                         (
                false
                         );

            return(result);
        }