Ejemplo n.º 1
0
        public IActionResult SetParameters([FromQuery] string parametersFile)
        {
            ReportsAutoDiscoveryConfigModel pathSearchConfig = GetAutoDiscoveryConfig();
            ExecutionConfig config = ExecutionConfigManager.Read(Path.Combine(pathSearchConfig.ParametersFilesDirectory, parametersFile));
            ParametersModel model  = new ParametersModel();

            model.ParametersFile = parametersFile;
            if (config.DataSource == ReportDataSource.StoredProcedure)
            {
                IDictionary <Tuple <ParameterType, string>, object> data = config.StoredProcedureParameters.Select(p =>
                                                                                                                   new KeyValuePair <Tuple <ParameterType, string>, object>(new Tuple <ParameterType, string>(ParameterType.StoredProcedure, p.ParameterName),
                                                                                                                                                                            p.ParameterValue)).ToDictionary(item => item.Key, item => item.Value);
                model.Parameters        = data;
                model.IsStoredProcedure = true;
            }
            else
            {
                IDictionary <Tuple <ParameterType, string>, object> whereParams = config.ViewParameters.WhereParameters.Select(p =>
                                                                                                                               new KeyValuePair <Tuple <ParameterType, string>, object>(new Tuple <ParameterType, string>(ParameterType.Where, p.ParameterName),
                                                                                                                                                                                        p.ParameterValue)).ToDictionary(item => item.Key, item => item.Value);
                IDictionary <Tuple <ParameterType, string>, object> orderParams = config.ViewParameters.OrderByParameters.Select(p =>
                                                                                                                                 new KeyValuePair <Tuple <ParameterType, string>, object>(new Tuple <ParameterType, string>(ParameterType.Order, p.ParameterName),
                                                                                                                                                                                          p.ParameterValue)).ToDictionary(item => item.Key, item => item.Value);
                IDictionary <Tuple <ParameterType, string>, object> groupParams = config.ViewParameters.GroupByParameters.Select(p =>
                                                                                                                                 new KeyValuePair <Tuple <ParameterType, string>, object>(new Tuple <ParameterType, string>(ParameterType.Group, p.ParameterName),
                                                                                                                                                                                          p.ParameterValue)).ToDictionary(item => item.Key, item => item.Value);
                IDictionary <Tuple <ParameterType, string>, object> result = new Dictionary <Tuple <ParameterType, string>, object>();
                result                  = result.Concat(whereParams).Concat(orderParams).Concat(groupParams).ToDictionary(item => item.Key, item => item.Value);
                model.Parameters        = result;
                model.IsStoredProcedure = false;
            }
            return(PartialView("Modals/SetParametersModal", model));
        }
        public void TestReadConfig(ReportDataSource source, string file)
        {
            ExecutionConfig expectedConfig = GetConfig(source);
            ExecutionConfig actualConfig   = ExecutionConfigManager.Read(file);

            Assert.NotNull(actualConfig);
            CheckConfigs(expectedConfig, actualConfig);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Generate([FromQuery] string dataSourceType, [FromQuery] string dataSourceConnStr,
                                                   [FromQuery] string parametersFile, [FromQuery] string templateFile,
                                                   [FromQuery] int worksheet, [FromQuery] int row, [FromQuery] int column,
                                                   [FromBody] ParameterInfoModel[] parameters)
        {
            ReportsAutoDiscoveryConfigModel pathSearchConfig   = GetAutoDiscoveryConfig();
            KeyValuePair <DbEngine, string> dataSourceDbEngine = _availableDataSources.First(item => string.Equals(item.Value.Trim().ToLower(), dataSourceType.Trim().ToLower()));
            IReportGeneratorManager         manager            = new ExcelReportGeneratorManager(_loggerFactory, dataSourceDbEngine.Key, dataSourceConnStr);
            string          reportFile = GetExcelFilePath("Report", Guid.NewGuid());
            ExecutionConfig config     = ExecutionConfigManager.Read(Path.Combine(pathSearchConfig.ParametersFilesDirectory, parametersFile));

            if (parameters != null && parameters.Length > 0)
            {
                if (config.DataSource == ReportDataSource.StoredProcedure)
                {
                    foreach (ParameterInfoModel parameter in parameters)
                    {
                        StoredProcedureParameter existingStoreProcParam = config.StoredProcedureParameters.FirstOrDefault(p => string.Equals(p.ParameterName.ToLower(), parameter.Key.ToLower()));
                        if (existingStoreProcParam != null)
                        {
                            existingStoreProcParam.ParameterValue = parameter.Value;
                        }
                    }
                }
                else
                {
                    foreach (ParameterInfoModel parameter in parameters)
                    {
                        DbQueryParameter sqlStatementPrameter = null;
                        if (parameter.Type == ParameterType.Where)
                        {
                            sqlStatementPrameter = config.ViewParameters.WhereParameters.FirstOrDefault(p => string.Equals(p.ParameterName.ToLower(), parameter.Key.ToLower()));
                        }
                        if (parameter.Type == ParameterType.Order)
                        {
                            sqlStatementPrameter = config.ViewParameters.OrderByParameters.FirstOrDefault(p => string.Equals(p.ParameterName.ToLower(), parameter.Key.ToLower()));
                        }
                        if (parameter.Type == ParameterType.Group)
                        {
                            sqlStatementPrameter = config.ViewParameters.GroupByParameters.FirstOrDefault(p => string.Equals(p.ParameterName.ToLower(), parameter.Key.ToLower()));
                        }
                        if (sqlStatementPrameter != null)
                        {
                            sqlStatementPrameter.ParameterValue = parameter.Value.ToString();
                        }
                    }
                }
            }
            bool result = await manager.GenerateAsync(Path.Combine(pathSearchConfig.TemplatesFilesDirectory, templateFile), config, reportFile,
                                                      ExcelReportGeneratorHelper.CreateParameters(worksheet, row, column));

            if (result)
            {
                byte[] bytes = System.IO.File.ReadAllBytes(reportFile);
                return(File(bytes, _expectedMimeTypes[MsExcelExtension], "Report.xlsx"));
            }
            return(null);
        }
Ejemplo n.º 4
0
        private ReportParametersInfoModel Create(FileInfo file)
        {
            ExecutionConfig config = ExecutionConfigManager.Read(file.FullName);

            string[] fileContent = System.IO.File.ReadAllLines(file.FullName);
            ReportParametersInfoModel parametersInfo = new ReportParametersInfoModel(file.Name, config.DisplayName, config.Description, fileContent);

            return(parametersInfo);
        }
        public async Task <int> GenerateAsync(string template, string executionConfigFile, string reportFile, object[] parameters)
        {
            ExecutionConfig config = ExecutionConfigManager.Read(executionConfigFile);

            return(await GenerateImplAsync(template, config, reportFile, parameters));
        }