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)
{
var log = AyaNova.Util.ApplicationLogging.CreateLogger("ReportBiz::RenderReport");
#if (DEBUG)
log.LogInformation($"DBG: ReportBiz::RenderReport called");
#endif
// #if (DEBUG)
// log.LogInformation($"DBG: ReportBiz::RenderReport called");
// #endif
//Customer User Report?
bool RequestIsCustomerWorkOrderReport = false;
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
#if (DEBUG)
log.LogInformation($"DBG: ReportBiz::RenderReport get report from db");
#endif
// #if (DEBUG)
// log.LogInformation($"DBG: ReportBiz::RenderReport get report from db");
// #endif
var report = await ct.Report.FirstOrDefaultAsync(z => z.Id == reportRequest.ReportId);
if (report == null)
{
@@ -441,18 +441,18 @@ namespace AyaNova.Biz
reportRequest.IncludeWoItemDescendants = report.IncludeWoItemDescendants;
//Get data
#if (DEBUG)
log.LogInformation($"DBG: ReportBiz::RenderReport GetReportData");
#endif
// #if (DEBUG)
// log.LogInformation($"DBG: ReportBiz::RenderReport GetReportData");
// #endif
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 (ReportData == null)
{
return null;
}
#if (DEBUG)
log.LogInformation($"DBG: ReportBiz::RenderReport got report data");
#endif
// #if (DEBUG)
// log.LogInformation($"DBG: ReportBiz::RenderReport got report data");
// #endif
//initialization
log.LogDebug("Initializing report rendering system");
@@ -491,9 +491,9 @@ namespace AyaNova.Biz
}
else
{
#if (DEBUG)
log.LogInformation($"DBG: ReportBiz::calling browserfetcher");
#endif
// #if (DEBUG)
// log.LogInformation($"DBG: ReportBiz::calling browserfetcher");
// #endif
log.LogDebug($"Windows: Calling browserFetcher download async now:");
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultChromiumRevision);
}
@@ -514,9 +514,9 @@ namespace AyaNova.Biz
//API DOCS http://www.puppeteersharp.com/api/index.html
log.LogDebug($"Launching headless Browser now:");
#if (DEBUG)
log.LogInformation($"DBG: ReportBiz::launching browser now");
#endif
// #if (DEBUG)
// log.LogInformation($"DBG: ReportBiz::launching browser now");
// #endif
using (var browser = await Puppeteer.LaunchAsync(lo))
using (var page = await browser.NewPageAsync())
{
@@ -640,25 +640,25 @@ namespace AyaNova.Biz
//prePareData / preRender
var ReportDataObject = $"{{ ayReportData:{ReportData}, ayReportMetaData:{reportMeta}, ayClientMetaData:{clientMeta}, ayServerMetaData:{serverMeta} }}";
log.LogDebug($"Calling ayPreRender...");
#if (DEBUG)
log.LogInformation($"DBG: ReportBiz::RenderReport - preRender");
#endif
// #if (DEBUG)
// log.LogInformation($"DBG: ReportBiz::RenderReport - preRender");
// #endif
//PRE_RENDER (WITH TIMEOUT???)
await page.WaitForExpressionAsync($"ayPreRender({ReportDataObject})");
//compile the template
log.LogDebug($"Calling Handlebars.compile...");
#if (DEBUG)
log.LogInformation($"DBG: ReportBiz::RenderReport - compiling handlebars template");
#endif
// #if (DEBUG)
// log.LogInformation($"DBG: ReportBiz::RenderReport - compiling handlebars template");
// #endif
var compileScript = $"Handlebars.compile(`{report.Template}`)(PreParedReportDataObject);";
var compiledHTML = await page.EvaluateExpressionAsync<string>(compileScript);
//render report as HTML
log.LogDebug($"Setting page content to compiled HTML");
#if (DEBUG)
log.LogInformation($"DBG: ReportBiz::RenderReport - settting html on page contents");
#endif
// #if (DEBUG)
// log.LogInformation($"DBG: ReportBiz::RenderReport - settting html on page contents");
// #endif
await page.SetContentAsync(compiledHTML);
//add style (after page or it won't work)
@@ -675,9 +675,9 @@ namespace AyaNova.Biz
//Set PDF options
//https://pptr.dev/#?product=Puppeteer&version=v5.3.0&show=api-pagepdfoptions
log.LogDebug($"Resolving PDF Options from report settings");
#if (DEBUG)
log.LogInformation($"DBG: ReportBiz::RenderReport - settting pdf options");
#endif
// #if (DEBUG)
// log.LogInformation($"DBG: ReportBiz::RenderReport - settting pdf options");
// #endif
var PdfOptions = new PdfOptions() { };
PdfOptions.DisplayHeaderFooter = report.DisplayHeaderFooter;
@@ -754,9 +754,9 @@ namespace AyaNova.Biz
//render to pdf and return
log.LogDebug($"Calling render page contents to PDF");
#if (DEBUG)
log.LogInformation($"DBG: ReportBiz::RenderReport - rendering to pdf");
#endif
// #if (DEBUG)
// log.LogInformation($"DBG: ReportBiz::RenderReport - rendering to pdf");
// #endif
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");
@@ -778,9 +778,9 @@ namespace AyaNova.Biz
}
finally
{
#if (DEBUG)
log.LogInformation($"DBG: ReportBiz::RenderReport - closing browser");
#endif
// #if (DEBUG)
// log.LogInformation($"DBG: ReportBiz::RenderReport - closing browser");
// #endif
log.LogDebug($"Closing browser");
await browser.CloseAsync();
ReportRenderManager.RemoveProcess(browser.Process.Id, log);

View File

@@ -2435,7 +2435,7 @@ namespace AyaNova.Biz
o.UserViz = vc.Get("user", o.UserId);
}
}
TaxCode Tax = null;
TaxCode Tax = null;
if (o.ChargeTaxCodeId != null)
{
if (!oc.Has("tax", o.ChargeTaxCodeId))

View File

@@ -46,9 +46,9 @@ namespace AyaNova.Util
{
log.LogTrace("RenderSlotAvailable check");
//var count = _baginstances.Count;
#if (DEBUG)
log.LogInformation($"DBG: RenderSlotAvailable check, there are currently {_baginstances.Count} instances in the bag");
#endif
// #if (DEBUG)
// log.LogInformation($"DBG: RenderSlotAvailable check, there are currently {_baginstances.Count} instances in the bag");
// #endif
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");
@@ -59,9 +59,9 @@ namespace AyaNova.Util
{
if (i.Expires < dtNow)
{
#if (DEBUG)
log.LogInformation($"DBG: RenderSlotAvailable attempting kill of expired process {i.ReporterProcessId}");
#endif
// #if (DEBUG)
// log.LogInformation($"DBG: RenderSlotAvailable attempting kill of expired process {i.ReporterProcessId}");
// #endif
ForceCloseProcess(i, log);
}
}
@@ -107,21 +107,21 @@ namespace AyaNova.Util
internal static void AddProcess(int processId, ILogger log)
{
#if (DEBUG)
log.LogInformation($"DBG: RenderSlotAvailable::AddProcess {processId} in the bag");
#endif
// #if (DEBUG)
// log.LogInformation($"DBG: RenderSlotAvailable::AddProcess {processId} in the bag");
// #endif
_baginstances.Add(new ReportRenderInstanceInfo(processId));
#if (DEBUG)
log.LogInformation($"DBG: RenderSlotAvailable::AddProcess, there are currently {_baginstances.Count} instances in the bag");
#endif
// #if (DEBUG)
// log.LogInformation($"DBG: RenderSlotAvailable::AddProcess, there are currently {_baginstances.Count} instances in the bag");
// #endif
}
internal static void RemoveProcess(int processId, ILogger log)
{
#if (DEBUG)
log.LogInformation($"DBG: RenderSlotAvailable::RemoveProcess {processId} from the bag");
#endif
// #if (DEBUG)
// log.LogInformation($"DBG: RenderSlotAvailable::RemoveProcess {processId} from the bag");
// #endif
foreach (var i in _baginstances)
{
if (i.ReporterProcessId == processId)