Пример #1
0
        public WorkbookGeneratorResults CompleteWorkbooksWithResults(WritersStatistics writersStatistics)
        {
            _logger.LogInformation("Starting to generate workbooks with results...");

            var availableTemplates   = WorkbookGeneratorCommon.GenerateWorkbookTemplatesList(_config.WorkbookTemplatesDirectory, _config.CustomWorkbookTemplatesDirectory, _logger);
            var applicableTemplates  = WorkbookGeneratorCommon.SelectTemplatesApplicableToThisRun(availableTemplates, writersStatistics);
            var nonEmptyExtractNames = WorkbookGeneratorCommon.GetNonEmptyExtractNames(writersStatistics);

            var completedWorkbooks = applicableTemplates
                                     .Select(template => CompleteWorkbook(template, WorkbookGeneratorCommon.HasAnyData(template, nonEmptyExtractNames)))
                                     .ToList();

            return(new WorkbookGeneratorResults(completedWorkbooks, availableTemplates));
        }
Пример #2
0
        public WorkbookGeneratorResults CompleteWorkbooksWithResults(WritersStatistics writersStatistics)
        {
            _logger.LogInformation("Starting to generate workbooks with results...");

            var availableTemplates   = WorkbookGeneratorCommon.GenerateWorkbookTemplatesList(_config.WorkbookTemplatesDirectory, _config.CustomWorkbookTemplatesDirectory, _logger);
            var applicableTemplates  = WorkbookGeneratorCommon.SelectTemplatesApplicableToThisRun(availableTemplates, writersStatistics);
            var nonEmptyExtractNames = WorkbookGeneratorCommon.GetNonEmptyExtractNames(writersStatistics);
            var results = new WorkbookGeneratorResults(new List <CompletedWorkbookInfo>(), availableTemplates);

            foreach (var template in applicableTemplates)
            {
                var templateWorkbookPath = template.Path;
                var hasAnyData           = WorkbookGeneratorCommon.HasAnyData(template, nonEmptyExtractNames);

                var baseWorkbookName        = template.Name + _config.CustomWorkbookSuffix;
                var finalWorkbookName       = hasAnyData ? baseWorkbookName : $"{baseWorkbookName} [No Data]";
                var destinationWorkbookPath = Path.Combine(_workbooksOutputDir, $"{finalWorkbookName}.twb");

                try
                {
                    CopyWorkbookToOutput(templateWorkbookPath, destinationWorkbookPath);

                    ReplaceConnectionInWorkbook(destinationWorkbookPath);

                    results.CompletedWorkbooks.Add(new CompletedWorkbookInfo(template.Name, finalWorkbookName, destinationWorkbookPath, hasAnyData));
                }
                catch (Exception ex)
                {
                    var message = $"Exception occurred while generating workbook {template.Name}. Exception: {ex.Message}";
                    _logger.LogError(message);
                    results.CompletedWorkbooks.Add(new CompletedWorkbookInfo(template.Name, finalWorkbookName, workbookPath: null, hasAnyData: false, new WorkbookGeneratingException("", ex)));
                }
            }

            return(results);
        }