case 4022
This commit is contained in:
@@ -434,6 +434,14 @@ namespace AyaNova.Biz
|
|||||||
log.LogDebug("Initializing report system");
|
log.LogDebug("Initializing report system");
|
||||||
var ReportJSFolderPath = Path.Combine(ServerBootConfig.AYANOVA_CONTENT_ROOT_PATH, "resource", "rpt");
|
var ReportJSFolderPath = Path.Combine(ServerBootConfig.AYANOVA_CONTENT_ROOT_PATH, "resource", "rpt");
|
||||||
|
|
||||||
|
//language - mirror client's language so that pdf footer header stuff like date prints in their desired format, otherwise those items take the server's settings automatically
|
||||||
|
var lang = reportRequest.ClientMeta["LanguageName"].Value<string>();
|
||||||
|
if (!string.IsNullOrWhiteSpace(lang))
|
||||||
|
{
|
||||||
|
lang = $"--lang={lang}";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var lo = new LaunchOptions { Headless = true };
|
var lo = new LaunchOptions { Headless = true };
|
||||||
bool isWindows = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows);
|
bool isWindows = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows);
|
||||||
if (!isWindows)
|
if (!isWindows)
|
||||||
@@ -471,7 +479,7 @@ namespace AyaNova.Biz
|
|||||||
//and so far in testing I see no reason to doubt him so removed it
|
//and so far in testing I see no reason to doubt him so removed it
|
||||||
//https://github.com/puppeteer/puppeteer/issues/1825#issuecomment-792817748
|
//https://github.com/puppeteer/puppeteer/issues/1825#issuecomment-792817748
|
||||||
//testing
|
//testing
|
||||||
lo.Args = new string[] { "--disable-dev-shm-usage --no-sandbox --disable-gpu --no-zygote " };
|
lo.Args = new string[] { $"--disable-dev-shm-usage --no-sandbox --disable-gpu --no-zygote {lang}" };
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -481,18 +489,52 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultChromiumRevision);
|
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultChromiumRevision);
|
||||||
|
|
||||||
|
lo.Args = new string[] { $"{lang}" };
|
||||||
}
|
}
|
||||||
|
|
||||||
System.Text.StringBuilder PageLog = new System.Text.StringBuilder();
|
System.Text.StringBuilder PageLog = new System.Text.StringBuilder();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//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:");
|
||||||
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())
|
||||||
|
// using (var page = (await browser.PagesAsync()).First())
|
||||||
{
|
{
|
||||||
//track this process so it can be cancelled if it times out
|
//track this process so it can be cancelled if it times out
|
||||||
ReportRenderManager.AddProcess(browser.Process.Id);
|
ReportRenderManager.AddProcess(browser.Process.Id);
|
||||||
|
|
||||||
|
|
||||||
|
// var lang = reportRequest.ClientMeta;
|
||||||
|
// // var overrideNavigatorLanguages = @"Object.defineProperty(navigator, 'languages', {
|
||||||
|
// // get: function() {
|
||||||
|
// // return ['es', 'bn', 'fr'];
|
||||||
|
// // }
|
||||||
|
// // });";
|
||||||
|
// var ov = @"Object.defineProperty(navigator, 'language', {
|
||||||
|
// get: function() {
|
||||||
|
// return 'ar-EG';
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// Object.defineProperty(navigator, 'languages', {
|
||||||
|
// get: function() {
|
||||||
|
// return ['ar-EG', 'ko-KR'];
|
||||||
|
// }
|
||||||
|
// });";
|
||||||
|
// await page.EvaluateFunctionOnNewDocumentAsync(ov);
|
||||||
|
|
||||||
|
|
||||||
|
// await page.GoToAsync("about:blank");
|
||||||
|
// var res = (JArray)await page.EvaluateExpressionAsync("navigator.languages");
|
||||||
|
|
||||||
|
// var hdrs = new Dictionary<string, string>();
|
||||||
|
// hdrs.Add("Accept-Language", "ar-EG");
|
||||||
|
// await page.SetExtraHttpHeadersAsync(hdrs);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
@@ -524,6 +566,7 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
log.LogDebug($"Preparing page: adding base reporting scripts to page");
|
log.LogDebug($"Preparing page: adding base reporting scripts to page");
|
||||||
|
|
||||||
|
|
||||||
//Add Handlebars JS for compiling and presenting
|
//Add Handlebars JS for compiling and presenting
|
||||||
//https://handlebarsjs.com/
|
//https://handlebarsjs.com/
|
||||||
await page.AddScriptTagAsync(new AddTagOptions() { Path = Path.Combine(ReportJSFolderPath, "ay-hb.js") });
|
await page.AddScriptTagAsync(new AddTagOptions() { Path = Path.Combine(ReportJSFolderPath, "ay-hb.js") });
|
||||||
|
|||||||
Reference in New Issue
Block a user