/* * public async Task<bool> Configure(string apiKey, string appSid, string basePath = "") * { * _pdfConfig = string.IsNullOrEmpty(basePath) ? new Configuration(apiKey, appSid) : new Configuration(apiKey, appSid, basePath); * _pdfApi = new PdfApi(_pdfConfig); * * _barcodeConfig = new Aspose.BarCode.Cloud.Sdk.Configuration(); * _barcodeConfig.DebugMode = _debug; * _barcodeConfig.AppKey = apiKey; * _barcodeConfig.AppSid = appSid; * if (!string.IsNullOrEmpty(basePath)) * _barcodeConfig.ApiBaseUrl = basePath; * _barcodeApi = new Aspose.BarCode.Cloud.Sdk.BarCodeApi(_barcodeConfig); * * await _taskMeasurer.Run(async () => * { * await CreateFolder(""); * }, "000_CreateClientFolder"); * * await _taskMeasurer.Run(async () => * { * await CreateFolder(TmpFolderName); * }, "000_CreateTemporaryFolder"); * * return true; * } */ public async Task <bool> Report(Model.Document model) { _defaultFont = model.DefaultFont; _documentOptions = model.Options; if (null == model?.Content || 0 == model?.Content?.Count) { throw new ArgumentException("No issues to export"); } if (model?.Content?.Count == 1) // single issue { PdfReportPageProcessor processor = new PdfReportPageProcessor(this, FileName, Folder); await processor.PrepareDocument(); await processor.Report(model.Content[0]); } else // multiple issues { List <PdfReportPageProcessor> pageProcessors = model.Content.Select(i => new PdfReportPageProcessor(this, $"{Guid.NewGuid()}.pdf", TmpFolderPath)).ToList(); await Task.WhenAll(pageProcessors.Select(async(p) => { await p.PrepareDocument(); await p.Report(model.Content[pageProcessors.IndexOf(p)]); })); await _taskMeasurer.Run(async() => await _pdfApi.PutMergeDocumentsAsync(mergeDocuments: new MergeDocuments(pageProcessors.Select(p => $"{TmpFolderPath}/{p.FileName}").ToList()) , name: FileName, storage: Storage, folder: Folder) , "990_MergeDocuments"); } await _taskMeasurer.Run(async() => { await RemoveFolder(TmpFolderName); }, "990_DeleteTemporaryFolder"); return(true); }
public async Task <IActionResult> PostExport([FromBody] List <Model.IssueListItem> issuesList, [FromQuery] bool generateQr = true) { User user = null; List <IssueData> issues = null; Dictionary <long, Repository> repo_dict = null; ReportModel.Document documentReportModel = null; string extension = "pdf"; string uid = Guid.NewGuid().ToString(); string reportFileName = $"{_configuration.GetValue<string>("Settings:StorageRoot", "clients_github")}/{uid}.{extension}"; Report.PdfReport pdfReport = null; try { user = await _githubCli.User.Current(); //Utils.Save2File("07_user.json", user); // fetch issues issues = (await Task.WhenAll(issuesList.Select(i => IssueData.Fetch(_githubCli, i.RepositoryId, i.IssueNo)))).ToList(); // fetch repositories repo_dict = (await Task.WhenAll(issues.GroupBy(i => i.IssueRepoId).Select(i => _githubCli.Repository.Get(i.Key)))).ToDictionary(r => r.Id, r => r); // update issues repositories issues.ForEach(i => i.IssueRepo = repo_dict[i.IssueRepoId]); ReportGithubModel model = new ReportGithubModel(System.IO.File.ReadAllText(_configuration.GetValue("Templates:ReportIssuesModel", "template/Report-Issues.Mustache"))); model.GenerateQRCode = generateQr; documentReportModel = model.CreateReportModel(model.issuesModel(issues)); if (null == documentReportModel.Options) { documentReportModel.Options = new ReportModel.DocumentOptions(); } pdfReport = new Report.PdfReport(filePath: reportFileName, storageName: _configuration.GetValue <string>("Settings:StorageName"), debug: _hostEnvironment.IsDevelopment()); await pdfReport.Configure(_client.PdfApi, _client.BarcodeApi); await pdfReport.Report(documentReportModel); return(new OkObjectResult(new { downloadlink = _basePathReplacement.ReplaceBaseUrl(Url.Link("GetDownload", new { id = uid })), id = uid })); }catch (Exception ex) { ZipFileArchive archive = new ZipFileArchive().AddFile("010_request_params.json", new { RequestId = _client.RequestId, FileId = uid, FileName = reportFileName }); foreach (var f in new Dictionary <string, object> { { "020_user.json", user }, { "030_issues.json", issues }, { "040_repo_dict.json", repo_dict }, { "050_report_model.json", documentReportModel }, }.ToArray()) { archive.AddFile(f.Key, f.Value); } throw new ControllerException($"Error generating {reportFileName}", innerException: ex, customData: await archive.Archive()); } finally { _client.Stat = pdfReport?.Stat; } }