This commit is contained in:
2021-12-23 00:00:21 +00:00
parent 783e4611ac
commit fe36b2f9bc
3 changed files with 52 additions and 52 deletions

View File

@@ -383,9 +383,9 @@ namespace AyaNova.Biz
public async Task<string> RenderReport(DataListReportRequest reportRequest, string apiUrl) public async Task<string> RenderReport(DataListReportRequest reportRequest, string apiUrl)
{ {
var log = AyaNova.Util.ApplicationLogging.CreateLogger("ReportBiz::RenderReport"); var log = AyaNova.Util.ApplicationLogging.CreateLogger("ReportBiz::RenderReport");
#if (DEBUG) // #if (DEBUG)
log.LogInformation($"DBG: ReportBiz::RenderReport called"); // log.LogInformation($"DBG: ReportBiz::RenderReport called");
#endif // #endif
//Customer User Report? //Customer User Report?
bool RequestIsCustomerWorkOrderReport = false; bool RequestIsCustomerWorkOrderReport = false;
if (reportRequest.ReportId == -100) if (reportRequest.ReportId == -100)
@@ -400,9 +400,9 @@ namespace AyaNova.Biz
} }
//get report, vet security, see what we need before init in case of issue //get report, vet security, see what we need before init in case of issue
#if (DEBUG) // #if (DEBUG)
log.LogInformation($"DBG: ReportBiz::RenderReport get report from db"); // log.LogInformation($"DBG: ReportBiz::RenderReport get report from db");
#endif // #endif
var report = await ct.Report.FirstOrDefaultAsync(z => z.Id == reportRequest.ReportId); var report = await ct.Report.FirstOrDefaultAsync(z => z.Id == reportRequest.ReportId);
if (report == null) if (report == null)
{ {
@@ -441,18 +441,18 @@ namespace AyaNova.Biz
reportRequest.IncludeWoItemDescendants = report.IncludeWoItemDescendants; reportRequest.IncludeWoItemDescendants = report.IncludeWoItemDescendants;
//Get data //Get data
#if (DEBUG) // #if (DEBUG)
log.LogInformation($"DBG: ReportBiz::RenderReport GetReportData"); // log.LogInformation($"DBG: ReportBiz::RenderReport GetReportData");
#endif // #endif
var ReportData = await GetReportData(reportRequest, RequestIsCustomerWorkOrderReport);//###### TODO: SLOW NEEDS TIMEOUT HERE ONCE IT WORKS IS SUPPORTED var ReportData = await GetReportData(reportRequest, RequestIsCustomerWorkOrderReport);//###### TODO: SLOW NEEDS TIMEOUT HERE ONCE IT WORKS IS SUPPORTED
//if GetReportData errored then will return null so need to return that as well here //if GetReportData errored then will return null so need to return that as well here
if (ReportData == null) if (ReportData == null)
{ {
return null; return null;
} }
#if (DEBUG) // #if (DEBUG)
log.LogInformation($"DBG: ReportBiz::RenderReport got report data"); // log.LogInformation($"DBG: ReportBiz::RenderReport got report data");
#endif // #endif
//initialization //initialization
log.LogDebug("Initializing report rendering system"); log.LogDebug("Initializing report rendering system");
@@ -491,9 +491,9 @@ namespace AyaNova.Biz
} }
else else
{ {
#if (DEBUG) // #if (DEBUG)
log.LogInformation($"DBG: ReportBiz::calling browserfetcher"); // log.LogInformation($"DBG: ReportBiz::calling browserfetcher");
#endif // #endif
log.LogDebug($"Windows: Calling browserFetcher download async now:"); log.LogDebug($"Windows: Calling browserFetcher download async now:");
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultChromiumRevision); await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultChromiumRevision);
} }
@@ -514,9 +514,9 @@ namespace AyaNova.Biz
//API DOCS http://www.puppeteersharp.com/api/index.html //API DOCS http://www.puppeteersharp.com/api/index.html
log.LogDebug($"Launching headless Browser now:"); log.LogDebug($"Launching headless Browser now:");
#if (DEBUG) // #if (DEBUG)
log.LogInformation($"DBG: ReportBiz::launching browser now"); // log.LogInformation($"DBG: ReportBiz::launching browser now");
#endif // #endif
using (var browser = await Puppeteer.LaunchAsync(lo)) using (var browser = await Puppeteer.LaunchAsync(lo))
using (var page = await browser.NewPageAsync()) using (var page = await browser.NewPageAsync())
{ {
@@ -640,25 +640,25 @@ namespace AyaNova.Biz
//prePareData / preRender //prePareData / preRender
var ReportDataObject = $"{{ ayReportData:{ReportData}, ayReportMetaData:{reportMeta}, ayClientMetaData:{clientMeta}, ayServerMetaData:{serverMeta} }}"; var ReportDataObject = $"{{ ayReportData:{ReportData}, ayReportMetaData:{reportMeta}, ayClientMetaData:{clientMeta}, ayServerMetaData:{serverMeta} }}";
log.LogDebug($"Calling ayPreRender..."); log.LogDebug($"Calling ayPreRender...");
#if (DEBUG) // #if (DEBUG)
log.LogInformation($"DBG: ReportBiz::RenderReport - preRender"); // log.LogInformation($"DBG: ReportBiz::RenderReport - preRender");
#endif // #endif
//PRE_RENDER (WITH TIMEOUT???) //PRE_RENDER (WITH TIMEOUT???)
await page.WaitForExpressionAsync($"ayPreRender({ReportDataObject})"); await page.WaitForExpressionAsync($"ayPreRender({ReportDataObject})");
//compile the template //compile the template
log.LogDebug($"Calling Handlebars.compile..."); log.LogDebug($"Calling Handlebars.compile...");
#if (DEBUG) // #if (DEBUG)
log.LogInformation($"DBG: ReportBiz::RenderReport - compiling handlebars template"); // log.LogInformation($"DBG: ReportBiz::RenderReport - compiling handlebars template");
#endif // #endif
var compileScript = $"Handlebars.compile(`{report.Template}`)(PreParedReportDataObject);"; var compileScript = $"Handlebars.compile(`{report.Template}`)(PreParedReportDataObject);";
var compiledHTML = await page.EvaluateExpressionAsync<string>(compileScript); var compiledHTML = await page.EvaluateExpressionAsync<string>(compileScript);
//render report as HTML //render report as HTML
log.LogDebug($"Setting page content to compiled HTML"); log.LogDebug($"Setting page content to compiled HTML");
#if (DEBUG) // #if (DEBUG)
log.LogInformation($"DBG: ReportBiz::RenderReport - settting html on page contents"); // log.LogInformation($"DBG: ReportBiz::RenderReport - settting html on page contents");
#endif // #endif
await page.SetContentAsync(compiledHTML); await page.SetContentAsync(compiledHTML);
//add style (after page or it won't work) //add style (after page or it won't work)
@@ -675,9 +675,9 @@ namespace AyaNova.Biz
//Set PDF options //Set PDF options
//https://pptr.dev/#?product=Puppeteer&version=v5.3.0&show=api-pagepdfoptions //https://pptr.dev/#?product=Puppeteer&version=v5.3.0&show=api-pagepdfoptions
log.LogDebug($"Resolving PDF Options from report settings"); log.LogDebug($"Resolving PDF Options from report settings");
#if (DEBUG) // #if (DEBUG)
log.LogInformation($"DBG: ReportBiz::RenderReport - settting pdf options"); // log.LogInformation($"DBG: ReportBiz::RenderReport - settting pdf options");
#endif // #endif
var PdfOptions = new PdfOptions() { }; var PdfOptions = new PdfOptions() { };
PdfOptions.DisplayHeaderFooter = report.DisplayHeaderFooter; PdfOptions.DisplayHeaderFooter = report.DisplayHeaderFooter;
@@ -754,9 +754,9 @@ namespace AyaNova.Biz
//render to pdf and return //render to pdf and return
log.LogDebug($"Calling render page contents to PDF"); log.LogDebug($"Calling render page contents to PDF");
#if (DEBUG) // #if (DEBUG)
log.LogInformation($"DBG: ReportBiz::RenderReport - rendering to pdf"); // log.LogInformation($"DBG: ReportBiz::RenderReport - rendering to pdf");
#endif // #endif
await page.PdfAsync(outputFullPath, PdfOptions);//###### TODO: SLOW NEEDS TIMEOUT HERE ONCE SUPPORTED, open bug: https://github.com/hardkoded/puppeteer-sharp/issues/1710 await page.PdfAsync(outputFullPath, PdfOptions);//###### TODO: SLOW NEEDS TIMEOUT HERE ONCE SUPPORTED, open bug: https://github.com/hardkoded/puppeteer-sharp/issues/1710
log.LogDebug($"Completed, returning results"); log.LogDebug($"Completed, returning results");
@@ -778,9 +778,9 @@ namespace AyaNova.Biz
} }
finally finally
{ {
#if (DEBUG) // #if (DEBUG)
log.LogInformation($"DBG: ReportBiz::RenderReport - closing browser"); // log.LogInformation($"DBG: ReportBiz::RenderReport - closing browser");
#endif // #endif
log.LogDebug($"Closing browser"); log.LogDebug($"Closing browser");
await browser.CloseAsync(); await browser.CloseAsync();
ReportRenderManager.RemoveProcess(browser.Process.Id, log); ReportRenderManager.RemoveProcess(browser.Process.Id, log);

View File

@@ -46,9 +46,9 @@ namespace AyaNova.Util
{ {
log.LogTrace("RenderSlotAvailable check"); log.LogTrace("RenderSlotAvailable check");
//var count = _baginstances.Count; //var count = _baginstances.Count;
#if (DEBUG) // #if (DEBUG)
log.LogInformation($"DBG: RenderSlotAvailable check, there are currently {_baginstances.Count} instances in the bag"); // log.LogInformation($"DBG: RenderSlotAvailable check, there are currently {_baginstances.Count} instances in the bag");
#endif // #endif
if (_baginstances.Count >= ServerBootConfig.AYANOVA_REPORT_RENDERING_MAX_INSTANCES) if (_baginstances.Count >= ServerBootConfig.AYANOVA_REPORT_RENDERING_MAX_INSTANCES)
{ {
log.LogTrace($"RenderSlotAvailable there are no free report rendering slots available, current count is {_baginstances.Count}, checking for expired slots to force closed"); log.LogTrace($"RenderSlotAvailable there are no free report rendering slots available, current count is {_baginstances.Count}, checking for expired slots to force closed");
@@ -59,9 +59,9 @@ namespace AyaNova.Util
{ {
if (i.Expires < dtNow) if (i.Expires < dtNow)
{ {
#if (DEBUG) // #if (DEBUG)
log.LogInformation($"DBG: RenderSlotAvailable attempting kill of expired process {i.ReporterProcessId}"); // log.LogInformation($"DBG: RenderSlotAvailable attempting kill of expired process {i.ReporterProcessId}");
#endif // #endif
ForceCloseProcess(i, log); ForceCloseProcess(i, log);
} }
} }
@@ -107,21 +107,21 @@ namespace AyaNova.Util
internal static void AddProcess(int processId, ILogger log) internal static void AddProcess(int processId, ILogger log)
{ {
#if (DEBUG) // #if (DEBUG)
log.LogInformation($"DBG: RenderSlotAvailable::AddProcess {processId} in the bag"); // log.LogInformation($"DBG: RenderSlotAvailable::AddProcess {processId} in the bag");
#endif // #endif
_baginstances.Add(new ReportRenderInstanceInfo(processId)); _baginstances.Add(new ReportRenderInstanceInfo(processId));
#if (DEBUG) // #if (DEBUG)
log.LogInformation($"DBG: RenderSlotAvailable::AddProcess, there are currently {_baginstances.Count} instances in the bag"); // log.LogInformation($"DBG: RenderSlotAvailable::AddProcess, there are currently {_baginstances.Count} instances in the bag");
#endif // #endif
} }
internal static void RemoveProcess(int processId, ILogger log) internal static void RemoveProcess(int processId, ILogger log)
{ {
#if (DEBUG) // #if (DEBUG)
log.LogInformation($"DBG: RenderSlotAvailable::RemoveProcess {processId} from the bag"); // log.LogInformation($"DBG: RenderSlotAvailable::RemoveProcess {processId} from the bag");
#endif // #endif
foreach (var i in _baginstances) foreach (var i in _baginstances)
{ {
if (i.ReporterProcessId == processId) if (i.ReporterProcessId == processId)