public void Create(Config config, int packageId) { int logId = 0; PackageService packageService = new PackageService { Config = config, PackageId = packageId }; try { string convertedFolderPath = config.DocumentsConvertedFolder; logId = packageService.ProcessStartedLog("Package generation started", config.UserId); Model.Package package = packageService .Load() .WithSections() .WithDocumentItems() .WithReportItems() .Package; package.LogId = logId; package.LogProgress = packageService.UpdateProcessLog; new AuxDocumentManager().Process(config, package, convertedFolderPath); new ReportsManager().Process(config, package); new PackageManager().Process(config, package, convertedFolderPath); string packagedFile; if (package.IncludeToc) { package.LogProgress(package.LogId, "Started creating table of contents"); string tocFilePath = new TocManager().Create(package, config); package.LogProgress(package.LogId, "Completed creating table of contents"); packagedFile = new Files().MergeDocs(config, package, tocFilePath); } else { packagedFile = new Files().MergeDocs(config, package); } DocumentService documentService = new DocumentService(); string description = string.Format("Package output for {0} generated by {1} {2} on {3}", package.Name, config.UserFirstName, config.UserLastName, DateTime.Now.ToString("dd MMM yyyy HH:mm:ss")); FileInfo fileInfo = new FileInfo(config.DocumentsConvertedFolder + packagedFile); double fileSize = fileInfo.Length / 1000000.0; documentService.AddPackgeToDocuments(config, package.Name, description, packagedFile, fileSize.ToString("N2"), logId, package.Id); SendSuccessEmail(config); } catch (Exception e) { packageService.ProcessFailedLog(logId, "Package generation failed", e.ToString()); SendFailureMail(config, packageId, logId, e); } }
public void Process(Config config, Model.Package package, string documentsFolderPath) { ICollection <AuxDocument> convertedDocuments = new Collection <AuxDocument>(); package.LogProgress(package.LogId, "Processing documents"); foreach (Section section in package.Sections) { package.LogProgress(package.LogId, "Processing documents in section \"" + section.Name + "\""); foreach (Item item in section.Items.Where(i => i.ItemType == ItemType.AuxiliaryDocument)) { if (!item.AuxiliaryDocument.ConversionRequired) { continue; } if (!File.Exists(documentsFolderPath + item.AuxiliaryDocument.SourceFile)) { continue; } package.LogProgress(package.LogId, "Converting document for \"" + item.Name + "\""); switch (item.AuxiliaryDocument.DocumentType) { case DocumentType.Word: new WordConvert().ToPdf(item.AuxiliaryDocument, documentsFolderPath, convertedDocuments, config); break; case DocumentType.Excel: new ExcelConvert().ToPdf(item.AuxiliaryDocument, documentsFolderPath, convertedDocuments, config); break; case DocumentType.Pdf: new PdfConvert().ToPdf(item.AuxiliaryDocument, documentsFolderPath, convertedDocuments); break; default: continue; } } package.LogProgress(package.LogId, "Completed processing documents in section \"" + section.Name + "\""); } package.LogProgress(package.LogId, "Completed documents conversion"); PackageItemService packageItemService = new PackageItemService(); packageItemService.UpdateConverted(convertedDocuments, config); }
public void Process(Config config, Model.Package package) { package.LogProgress(package.LogId, "Processing reports"); foreach (Section section in package.Sections) { package.LogProgress(package.LogId, "Processing reports in section \"" + section.Name + "\""); foreach (Item item in section.Items.Where(i => i.ItemType == ItemType.Report)) { package.LogProgress(package.LogId, "Generating report \"" + item.Name + "\""); StarchefReportingEngine engine = new StarchefReportingEngine(); engine.Run(config, item.ReportFilter, package.PageSetting.Paper); } package.LogProgress(package.LogId, "Completed processing reports in section \"" + section.Name + "\""); } package.LogProgress(package.LogId, "Completed generating reports"); }