private CompletedWorkbookInfo CompleteWorkbook(PackagedWorkbookTemplateInfo templateInfo, bool hasAnyData) { var workbookNameToUse = hasAnyData ? $"{templateInfo.Name}{_config.CustomWorkbookSuffix}" : $"{templateInfo.Name}{_config.CustomWorkbookSuffix} [No Data]"; try { // Copy the template to where we want the workbook to live var finalWorkbookPath = Path.Combine(_workbooksOutputDir, $"{workbookNameToUse}.twbx"); // In the case of custom workbooks, we don't have a custom folder in our output. Create one if we need to Directory.CreateDirectory(Path.GetDirectoryName(finalWorkbookPath)); File.Copy(templateInfo.Path, finalWorkbookPath); // Replace necessary hyper files in the workbook ProcessPackagedWorkbook(finalWorkbookPath); _logger.LogDebug("Workbook {completedWorkbookName} complete", templateInfo.Name); return(new CompletedWorkbookInfo(templateInfo, workbookNameToUse, finalWorkbookPath, hasAnyData)); } catch (Exception ex) { var message = $"Exception occurred while generating workbook {templateInfo.Name}. Exception: {ex.Message}"; _logger.LogError(message); return(CompletedWorkbookInfo.GetFailedInfo(templateInfo, new WorkbookGeneratingException(message, ex))); } }
public CompletedWorkbookInfo(PackagedWorkbookTemplateInfo packagedWorkbookTemplateInfo, string finalWorkbookName, string workbookPath, bool hasAnyData, Exception exception = null) : this(packagedWorkbookTemplateInfo.Name, finalWorkbookName, workbookPath, hasAnyData, exception) { }
public static CompletedWorkbookInfo GetFailedInfo(PackagedWorkbookTemplateInfo packagedWorkbookTemplateInfo, Exception exception) { return(new CompletedWorkbookInfo(packagedWorkbookTemplateInfo, packagedWorkbookTemplateInfo.Name, null, false, exception)); }
/// <summary> /// This checks if we have ALL files required by workbook (whatever they are empty or not doesn't matter). /// We must have all files in order for workbook to at least open, so if at least one file is missing - there is no point in generating workbook at all. /// </summary> private static bool HaveAllDataSets(PackagedWorkbookTemplateInfo templateInfo, ICollection <string> availableExtractFiles) { return(templateInfo.RequiredExtracts.All(availableExtractFiles.Contains)); }
/// <summary> /// This checks if at least one of the data sources used by the workbook has at least one row of data /// </summary> public static bool HasAnyData(PackagedWorkbookTemplateInfo templateInfo, ICollection <string> nonEmptyExtractNames) { return(templateInfo.RequiredExtracts.Any(nonEmptyExtractNames.Contains)); }