This commit is contained in:
2021-12-24 16:16:40 +00:00
parent 2385a50372
commit 95a2b0ccff
3 changed files with 64 additions and 145 deletions

View File

@@ -5048,10 +5048,10 @@ namespace AyaNova.Biz
.Where(z => z.GenerateDate < DateTime.UtcNow && (z.StopGeneratingDate == null || z.StopGeneratingDate > DateTime.UtcNow) && z.Active == true) .Where(z => z.GenerateDate < DateTime.UtcNow && (z.StopGeneratingDate == null || z.StopGeneratingDate > DateTime.UtcNow) && z.Active == true)
.Select(z => z.Id) .Select(z => z.Id)
.ToListAsync(); .ToListAsync();
#if (DEBUG) // #if (DEBUG)
if (l.Count > 0) // if (l.Count > 0)
log.LogInformation($"Found {l.Count} ready to generate PM orders"); // log.LogInformation($"Found {l.Count} ready to generate PM orders");
#endif // #endif
//process those pms //process those pms
foreach (long pmid in l) foreach (long pmid in l)
@@ -5063,9 +5063,9 @@ namespace AyaNova.Biz
#if (DEBUG) // #if (DEBUG)
log.LogInformation($"processing pm id {pmid}"); // log.LogInformation($"processing pm id {pmid}");
#endif // #endif
var p = await ct.PM.AsSplitQuery() var p = await ct.PM.AsSplitQuery()
.Include(w => w.Items.OrderBy(item => item.Sequence)) .Include(w => w.Items.OrderBy(item => item.Sequence))
.ThenInclude(wi => wi.Expenses) .ThenInclude(wi => wi.Expenses)
@@ -5184,9 +5184,9 @@ namespace AyaNova.Biz
try try
{ {
await ct.SaveChangesAsync(); await ct.SaveChangesAsync();
#if (DEBUG) // #if (DEBUG)
log.LogInformation($"updated PM after successful generation {p.Serial}"); // log.LogInformation($"updated PM after successful generation {p.Serial}");
#endif // #endif
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -5564,21 +5564,13 @@ namespace AyaNova.Biz
} }
} }
//wo.Items.Add(woi);
} }
// WorkOrderBiz biz = WorkOrderBiz.GetBiz(ct);
// var NewObject = await biz.WorkOrderCreateAsync(wo, false); // #if (DEBUG)
// if (NewObject == null) // log.LogInformation($"PMBiz::NewServiceWorkOrderFromPMAsync created new workorder {NewWoHeader.Serial}");
// { // #endif
// var err = $"PMBiz::NewServiceWorkOrderFromPMAsync error creating from PM {p.Serial}\r\n{biz.GetErrorsAsString()}";
// log.LogError(err);
// await NotifyEventHelper.AddGeneralNotifyEvent(AyaType.PM, p.Id, NotifyEventType.PMGenerationFailed, $"Error generating Work order from PM {p.Serial}\r\n{biz.GetErrorsAsString()}", "Preventive Maintenance");
// return false;
// }
#if (DEBUG)
log.LogInformation($"PMBiz::NewServiceWorkOrderFromPMAsync created new workorder {NewWoHeader.Serial}");
#endif
return true; return true;
} }
#endregion #endregion

View File

@@ -10,7 +10,6 @@ using AyaNova.Models;
using EnumsNET; using EnumsNET;
using PuppeteerSharp; using PuppeteerSharp;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System.Threading;
using System; using System;
namespace AyaNova.Biz namespace AyaNova.Biz
@@ -59,38 +58,6 @@ namespace AyaNova.Biz
} }
} }
// ////////////////////////////////////////////////////////////////////////////////////////////////
// //DUPLICATE
// //
// internal async Task<Report> DuplicateAsync(long id)
// {
// Report dbObject = await GetAsync(id, false);
// if (dbObject == null)
// {
// AddError(ApiErrorCode.NOT_FOUND, "id");
// return null;
// }
// Report newObject = new Report();
// CopyObject.Copy(dbObject, newObject);
// string newUniqueName = string.Empty;
// bool NotUnique = true;
// long l = 1;
// do
// {
// newUniqueName = Util.StringUtil.UniqueNameBuilder(dbObject.Name, l++, 255);
// NotUnique = await ct.Report.AnyAsync(z => z.Name == newUniqueName);
// } while (NotUnique);
// newObject.Name = newUniqueName;
// newObject.Id = 0;
// newObject.Concurrency = 0;
// await ct.Report.AddAsync(newObject);
// await ct.SaveChangesAsync();
// await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct);
// await SearchIndexAsync(newObject, true);
// return newObject;
// }
//////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
//IMPORT //IMPORT
@@ -115,34 +82,6 @@ namespace AyaNova.Biz
} while (NotUnique); } while (NotUnique);
newObject.Name = newUniqueName; newObject.Name = newUniqueName;
// This was stupid considering JObject can serialize directly to a report type
//but leaving in for a little while just to be sure it's all good
// newObject.Active = (bool)o["Active"];
// newObject.JsHelpers = (string)o["JsHelpers"];
// newObject.JsPrerender = (string)o["JsPrerender"];
// newObject.Notes = (string)o["Notes"];
// newObject.AType = (AyaType)(int)o["AType"];
// newObject.RenderType = (ReportRenderType)(int)o["RenderType"];
// newObject.Roles = (AuthorizationRoles)(int)o["Roles"];
// newObject.Style = (string)o["Style"];
// newObject.Template = (string)o["Template"];
// //pdf options
// newObject.HeaderTemplate = (string)o["HeaderTemplate"];
// newObject.FooterTemplate = (string)o["FooterTemplate"];
// newObject.MarginOptionsBottom = (string)o["MarginOptionsBottom"];
// newObject.MarginOptionsLeft = (string)o["MarginOptionsLeft"];
// newObject.MarginOptionsRight = (string)o["MarginOptionsRight"];
// newObject.MarginOptionsTop = (string)o["MarginOptionsTop"];
// newObject.PageRanges = (string)o["PageRanges"];
// newObject.PaperFormat = (ReportPaperFormat)(int)o["PaperFormat"];
// newObject.DisplayHeaderFooter = (bool)o["DisplayHeaderFooter"];
// newObject.Landscape = (bool)o["Landscape"];
// newObject.PreferCSSPageSize = (bool)o["PreferCSSPageSize"];
// newObject.PrintBackground = (bool)o["PrintBackground"];
// newObject.Scale = (decimal)o["Scale"];
await ValidateAsync(newObject, null); await ValidateAsync(newObject, null);
if (HasErrors) return false; if (HasErrors) return false;
@@ -384,14 +323,16 @@ namespace AyaNova.Biz
public async Task<string> RenderReport(DataListReportRequest reportRequest, DateTime renderTimeOutExpiry, string apiUrl) public async Task<string> RenderReport(DataListReportRequest reportRequest, DateTime renderTimeOutExpiry, string apiUrl)
{ {
var log = AyaNova.Util.ApplicationLogging.CreateLogger($"ReportBiz::RenderReport id {reportRequest.ReportId}, timeout @ {renderTimeOutExpiry.ToString()}"); var log = AyaNova.Util.ApplicationLogging.CreateLogger("RenderReport");
// #if (DEBUG) log.LogDebug($"ReportBiz::RenderReport id {reportRequest.ReportId}, timeout @ {renderTimeOutExpiry.ToString()}");
// log.LogInformation($"DBG: ReportBiz::RenderReport called");
// #endif
//Customer User Report? //Customer User Report?
bool RequestIsCustomerWorkOrderReport = false; bool RequestIsCustomerWorkOrderReport = false;
if (reportRequest.ReportId == -100) if (reportRequest.ReportId == -100)
{ {
log.LogTrace("customer user report requested");
//get the user and workorder data and set the actual report id or return null if not found //get the user and workorder data and set the actual report id or return null if not found
var woTags = await ct.WorkOrder.AsNoTracking().Where(x => x.Id == reportRequest.SelectedRowIds[0]).Select(x => x.Tags).FirstOrDefaultAsync(); var woTags = await ct.WorkOrder.AsNoTracking().Where(x => x.Id == reportRequest.SelectedRowIds[0]).Select(x => x.Tags).FirstOrDefaultAsync();
if (woTags == null) return null; if (woTags == null) return null;
@@ -405,9 +346,7 @@ namespace AyaNova.Biz
throw new ReportRenderTimeOutException(); throw new ReportRenderTimeOutException();
//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) log.LogTrace($"get report from db");
// log.LogInformation($"DBG: ReportBiz::RenderReport get report from db");
// #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)
{ {
@@ -427,6 +366,7 @@ namespace AyaNova.Biz
if (!RequestIsCustomerWorkOrderReport && !AyaNova.Api.ControllerHelpers.Authorized.HasReadFullRole(effectiveRoles, report.AType)) if (!RequestIsCustomerWorkOrderReport && !AyaNova.Api.ControllerHelpers.Authorized.HasReadFullRole(effectiveRoles, report.AType))
{ {
log.LogTrace($"bail: user unauthorized");
AddError(ApiErrorCode.NOT_AUTHORIZED, null, $"User not authorized for {report.AType} type object"); AddError(ApiErrorCode.NOT_AUTHORIZED, null, $"User not authorized for {report.AType} type object");
return null; return null;
} }
@@ -434,6 +374,7 @@ namespace AyaNova.Biz
//Client meta data is required //Client meta data is required
if (reportRequest.ClientMeta == null) if (reportRequest.ClientMeta == null)
{ {
log.LogTrace($"bail: ClientMeta parameter is missing");
AddError(ApiErrorCode.VALIDATION_MISSING_PROPERTY, null, "ClientMeta parameter is missing and required to render report"); AddError(ApiErrorCode.VALIDATION_MISSING_PROPERTY, null, "ClientMeta parameter is missing and required to render report");
return null; return null;
} }
@@ -447,10 +388,12 @@ namespace AyaNova.Biz
// #if (DEBUG) // #if (DEBUG)
// log.LogInformation($"DBG: ReportBiz::RenderReport GetReportData"); // log.LogInformation($"DBG: ReportBiz::RenderReport GetReportData");
// #endif // #endif
var ReportData = await GetReportData(reportRequest, renderTimeOutExpiry, RequestIsCustomerWorkOrderReport);//###### TODO: SLOW NEEDS TIMEOUT HERE ONCE IT WORKS IS SUPPORTED log.LogDebug("Getting report data now");
var ReportData = await GetReportData(reportRequest, renderTimeOutExpiry, RequestIsCustomerWorkOrderReport);
//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)
{ {
log.LogTrace($"bail: ReportData == null");
return null; return null;
} }
// #if (DEBUG) // #if (DEBUG)
@@ -463,11 +406,11 @@ namespace AyaNova.Biz
bool AutoDownloadChromium = true; bool AutoDownloadChromium = true;
if (string.IsNullOrWhiteSpace(ServerBootConfig.AYANOVA_REPORT_RENDER_BROWSER_PATH)) if (string.IsNullOrWhiteSpace(ServerBootConfig.AYANOVA_REPORT_RENDER_BROWSER_PATH))
{ {
log.LogDebug($"Using default Chromium browser (downloaded)"); log.LogTrace($"Using default Chromium browser (downloaded)");
} }
else else
{ {
log.LogDebug($"Using user specified Chromium browser at {ServerBootConfig.AYANOVA_REPORT_RENDER_BROWSER_PATH}"); log.LogTrace($"Using user specified Chromium browser at {ServerBootConfig.AYANOVA_REPORT_RENDER_BROWSER_PATH}");
AutoDownloadChromium = false; AutoDownloadChromium = false;
} }
@@ -498,7 +441,7 @@ namespace AyaNova.Biz
// #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.LogTrace($"Windows: Calling browserFetcher download async now:");
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultChromiumRevision); await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultChromiumRevision);
} }
@@ -520,20 +463,15 @@ namespace AyaNova.Biz
throw new ReportRenderTimeOutException(); throw new ReportRenderTimeOutException();
//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.LogTrace($"Launching headless Browser now:");
// #if (DEBUG)
// log.LogInformation($"DBG: ReportBiz::launching browser now");
// #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.PagesAsync())[0]) using (var page = (await browser.PagesAsync())[0])
{ {
//track this process so it can be cancelled if it times out //track this process for timeout purposes
ReportRenderManager.AddProcess(browser.Process.Id, renderTimeOutExpiry, log); ReportRenderManager.AddProcess(browser.Process.Id, renderTimeOutExpiry, log);
page.DefaultTimeout = 0;//infinite timeout as we are controlling how long the process can live for with the reportprocessmanager page.DefaultTimeout = 0;//infinite timeout as we are controlling how long the process can live for with the reportprocessmanager
try try
{ {
//info and error logging //info and error logging
page.Console += async (sender, args) => page.Console += async (sender, args) =>
{ {
@@ -558,7 +496,7 @@ namespace AyaNova.Biz
} }
}; };
log.LogDebug($"Preparing page: adding base reporting scripts to page"); log.LogTrace($"Preparing page: adding base reporting scripts to page");
if (DateTime.UtcNow > renderTimeOutExpiry) if (DateTime.UtcNow > renderTimeOutExpiry)
throw new ReportRenderTimeOutException(); throw new ReportRenderTimeOutException();
@@ -586,7 +524,7 @@ namespace AyaNova.Biz
await page.EvaluateExpressionAsync("ayRegisterHelpers();"); await page.EvaluateExpressionAsync("ayRegisterHelpers();");
if (DateTime.UtcNow > renderTimeOutExpiry) if (DateTime.UtcNow > renderTimeOutExpiry)
throw new ReportRenderTimeOutException(); throw new ReportRenderTimeOutException();
log.LogDebug($"Preparing page: adding this report's scripts, style and templates to page"); log.LogTrace($"Preparing page: adding this report's scripts, style and templates to page");
//add report pre-render, helpers and style //add report pre-render, helpers and style
if (string.IsNullOrWhiteSpace(report.JsPrerender)) if (string.IsNullOrWhiteSpace(report.JsPrerender))
@@ -601,12 +539,12 @@ namespace AyaNova.Biz
if (!string.IsNullOrWhiteSpace(report.Style)) if (!string.IsNullOrWhiteSpace(report.Style))
await page.AddStyleTagAsync(new AddTagOptions() { Content = report.Style }); await page.AddStyleTagAsync(new AddTagOptions() { Content = report.Style });
log.LogDebug($"Preparing page: adding Client meta data"); log.LogTrace($"Preparing page: adding Client meta data");
//Client meta data to JSON string //Client meta data to JSON string
var clientMeta = reportRequest.ClientMeta.ToString(); var clientMeta = reportRequest.ClientMeta.ToString();
log.LogDebug($"Preparing page: adding Server meta data"); log.LogTrace($"Preparing page: adding Server meta data");
//Server meta data //Server meta data
var logo = await ct.Logo.AsNoTracking().SingleOrDefaultAsync(); var logo = await ct.Logo.AsNoTracking().SingleOrDefaultAsync();
@@ -623,7 +561,7 @@ namespace AyaNova.Biz
var HasStreetAddress = !string.IsNullOrWhiteSpace(ServerGlobalBizSettings.Cache.Address) ? "true" : "false"; var HasStreetAddress = !string.IsNullOrWhiteSpace(ServerGlobalBizSettings.Cache.Address) ? "true" : "false";
var serverMeta = $"{{ayApiUrl:`{apiUrl}`, HasSmallLogo:{HasSmallLogo}, HasMediumLogo:{HasMediumLogo}, HasLargeLogo:{HasLargeLogo},CompanyName: `{AyaNova.Core.License.ActiveKey.RegisteredTo}`,CompanyWebAddress:`{ServerGlobalBizSettings.Cache.WebAddress}`,CompanyEmailAddress:`{ServerGlobalBizSettings.Cache.EmailAddress}`,CompanyPhone1:`{ServerGlobalBizSettings.Cache.Phone1}`,CompanyPhone2:`{ServerGlobalBizSettings.Cache.Phone2}`,HasPostalAddress:{HasPostalAddress},CompanyPostAddress:`{ServerGlobalBizSettings.Cache.PostAddress}`,CompanyPostCity:`{ServerGlobalBizSettings.Cache.PostCity}`,CompanyPostRegion:`{ServerGlobalBizSettings.Cache.PostRegion}`,CompanyPostCountry:`{ServerGlobalBizSettings.Cache.PostCountry}`,CompanyPostCode:`{ServerGlobalBizSettings.Cache.PostCode}`,HasStreetAddress:{HasStreetAddress},CompanyAddress:`{ServerGlobalBizSettings.Cache.Address}`,CompanyCity:`{ServerGlobalBizSettings.Cache.City}`,CompanyRegion:`{ServerGlobalBizSettings.Cache.Region}`,CompanyCountry:`{ServerGlobalBizSettings.Cache.Country}`,CompanyLatitude:{ServerGlobalBizSettings.Cache.Latitude},CompanyLongitude:{ServerGlobalBizSettings.Cache.Longitude}}}"; var serverMeta = $"{{ayApiUrl:`{apiUrl}`, HasSmallLogo:{HasSmallLogo}, HasMediumLogo:{HasMediumLogo}, HasLargeLogo:{HasLargeLogo},CompanyName: `{AyaNova.Core.License.ActiveKey.RegisteredTo}`,CompanyWebAddress:`{ServerGlobalBizSettings.Cache.WebAddress}`,CompanyEmailAddress:`{ServerGlobalBizSettings.Cache.EmailAddress}`,CompanyPhone1:`{ServerGlobalBizSettings.Cache.Phone1}`,CompanyPhone2:`{ServerGlobalBizSettings.Cache.Phone2}`,HasPostalAddress:{HasPostalAddress},CompanyPostAddress:`{ServerGlobalBizSettings.Cache.PostAddress}`,CompanyPostCity:`{ServerGlobalBizSettings.Cache.PostCity}`,CompanyPostRegion:`{ServerGlobalBizSettings.Cache.PostRegion}`,CompanyPostCountry:`{ServerGlobalBizSettings.Cache.PostCountry}`,CompanyPostCode:`{ServerGlobalBizSettings.Cache.PostCode}`,HasStreetAddress:{HasStreetAddress},CompanyAddress:`{ServerGlobalBizSettings.Cache.Address}`,CompanyCity:`{ServerGlobalBizSettings.Cache.City}`,CompanyRegion:`{ServerGlobalBizSettings.Cache.Region}`,CompanyCountry:`{ServerGlobalBizSettings.Cache.Country}`,CompanyLatitude:{ServerGlobalBizSettings.Cache.Latitude},CompanyLongitude:{ServerGlobalBizSettings.Cache.Longitude}}}";
log.LogDebug($"Preparing page: adding Report meta data"); log.LogTrace($"Preparing page: adding Report meta data");
//Custom fields definition for report usage //Custom fields definition for report usage
string CustomFieldsTemplate = "null"; string CustomFieldsTemplate = "null";
@@ -643,26 +581,20 @@ namespace AyaNova.Biz
if (DateTime.UtcNow > renderTimeOutExpiry) if (DateTime.UtcNow > renderTimeOutExpiry)
throw new ReportRenderTimeOutException(); throw new ReportRenderTimeOutException();
// #if (DEBUG)
// //view page contents //#### DEBUGGING TOOL: view page contents
// var pagecontent = await page.GetContentAsync(); // var pagecontent = await page.GetContentAsync();
// #endif
//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.LogTrace($"Calling ayPreRender...");
// #if (DEBUG)
// log.LogInformation($"DBG: ReportBiz::RenderReport - preRender");
// #endif
//PRE_RENDER (WITH TIMEOUT???)
await page.WaitForExpressionAsync($"ayPreRender({ReportDataObject})"); await page.WaitForExpressionAsync($"ayPreRender({ReportDataObject})");
if (DateTime.UtcNow > renderTimeOutExpiry) if (DateTime.UtcNow > renderTimeOutExpiry)
throw new ReportRenderTimeOutException(); throw new ReportRenderTimeOutException();
//compile the template //compile the template
log.LogDebug($"Calling Handlebars.compile..."); log.LogTrace($"Calling Handlebars.compile...");
// #if (DEBUG)
// log.LogInformation($"DBG: ReportBiz::RenderReport - compiling handlebars template");
// #endif
var compileScript = $"Handlebars.compile(`{report.Template}`)(PreParedReportDataObject);"; var compileScript = $"Handlebars.compile(`{report.Template}`)(PreParedReportDataObject);";
if (DateTime.UtcNow > renderTimeOutExpiry) if (DateTime.UtcNow > renderTimeOutExpiry)
throw new ReportRenderTimeOutException(); throw new ReportRenderTimeOutException();
@@ -670,16 +602,14 @@ namespace AyaNova.Biz
if (DateTime.UtcNow > renderTimeOutExpiry) if (DateTime.UtcNow > renderTimeOutExpiry)
throw new ReportRenderTimeOutException(); throw new ReportRenderTimeOutException();
//render report as HTML //render report as HTML
log.LogDebug($"Setting page content to compiled HTML"); log.LogTrace($"Setting page content to compiled HTML");
// #if (DEBUG)
// log.LogInformation($"DBG: ReportBiz::RenderReport - settting html on page contents");
// #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)
if (!string.IsNullOrWhiteSpace(report.Style)) if (!string.IsNullOrWhiteSpace(report.Style))
{ {
log.LogDebug($"Adding report template Style CSS"); log.LogTrace($"Adding report template Style CSS");
await page.AddStyleTagAsync(new AddTagOptions { Content = report.Style }); await page.AddStyleTagAsync(new AddTagOptions { Content = report.Style });
} }
@@ -689,10 +619,8 @@ 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.LogTrace($"Resolving PDF Options from report settings");
// #if (DEBUG)
// log.LogInformation($"DBG: ReportBiz::RenderReport - settting pdf options");
// #endif
var PdfOptions = new PdfOptions() { }; var PdfOptions = new PdfOptions() { };
PdfOptions.DisplayHeaderFooter = report.DisplayHeaderFooter; PdfOptions.DisplayHeaderFooter = report.DisplayHeaderFooter;
@@ -769,30 +697,29 @@ namespace AyaNova.Biz
if (DateTime.UtcNow > renderTimeOutExpiry) if (DateTime.UtcNow > renderTimeOutExpiry)
throw new ReportRenderTimeOutException(); throw new ReportRenderTimeOutException();
//render to pdf and return //render to pdf and return
log.LogDebug($"Calling render page contents to PDF"); log.LogTrace($"Calling render page contents to PDF");
// #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 await page.PdfAsync(outputFullPath, PdfOptions);//###### TODO: SLOW NEEDS TIMEOUT HERE ONCE SUPPORTED, open bug: https://github.com/hardkoded/puppeteer-sharp/issues/1710
log.LogDebug($"Closing Page and Browser"); log.LogTrace($"Closing Page and Browser");
await page.CloseAsync(); await page.CloseAsync();
await browser.CloseAsync(); await browser.CloseAsync();
log.LogDebug($"Completed, returning results"); log.LogTrace($"Completed, returning results");
return outputFileName; return outputFileName;
} }
catch (ReportRenderTimeOutException) catch (ReportRenderTimeOutException)
{ {
throw; throw;
} }
catch(PuppeteerSharp.TargetClosedException){ catch (PuppeteerSharp.TargetClosedException)
{
//we closed it because the timeout hit and the CoreJobReportRenderEngineProcessCleanup job cleaned it out //we closed it because the timeout hit and the CoreJobReportRenderEngineProcessCleanup job cleaned it out
//so return the error the client expects in this scenario //so return the error the client expects in this scenario
throw new ReportRenderTimeOutException(); throw new ReportRenderTimeOutException();
} }
catch (Exception ex) catch (Exception ex)
{ {
log.LogDebug(ex, $"Error during report rendering");
//This is the error when a helper is used on the template but doesn't exist: //This is the error when a helper is used on the template but doesn't exist:
//Evaluation failed: d //Evaluation failed: d
//(it might also mean other things wrong with template) //(it might also mean other things wrong with template)
@@ -801,7 +728,6 @@ namespace AyaNova.Biz
log.LogInformation($"Exception caught while rendering report \"{report.Name}\", report Page console log:"); log.LogInformation($"Exception caught while rendering report \"{report.Name}\", report Page console log:");
log.LogInformation(PageLog.ToString()); log.LogInformation(PageLog.ToString());
} }
log.LogInformation(ex, "Error during report render:");
// var v=await page.GetContentAsync();//for debugging purposes // var v=await page.GetContentAsync();//for debugging purposes
throw; throw;
@@ -811,11 +737,12 @@ namespace AyaNova.Biz
// #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.LogTrace($"Closing Page and Browser");
if (!page.IsClosed) if (!page.IsClosed)
await page.CloseAsync(); await page.CloseAsync();
if (!browser.IsClosed) if (!browser.IsClosed)
await browser.CloseAsync(); await browser.CloseAsync();
log.LogTrace($"Calling ReportRenderManager.RemoveProcess to stop tracking this process");
ReportRenderManager.RemoveProcess(browser.Process.Id, log); ReportRenderManager.RemoveProcess(browser.Process.Id, log);
} }
} }

View File

@@ -42,9 +42,9 @@ namespace AyaNova.Util
{ {
if (i.Expires < dtNow) if (i.Expires < dtNow)
{ {
#if (DEBUG) // #if (DEBUG)
log.LogInformation($"DBG: KillExpiredRenders attempting kill of expired process {i.ReporterProcessId}"); // log.LogInformation($"DBG: KillExpiredRenders attempting kill of expired process {i.ReporterProcessId}");
#endif // #endif
ForceCloseProcess(i, log); ForceCloseProcess(i, log);
} }
} }