This commit is contained in:
@@ -6,6 +6,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using AyaNova.Models;
|
||||
using AyaNova.Util;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace AyaNova.Biz
|
||||
{
|
||||
@@ -338,8 +339,67 @@ namespace AyaNova.Biz
|
||||
IMailer m = AyaNova.Util.ServiceProviderProvider.Mailer;
|
||||
try
|
||||
{
|
||||
#if (DEBUG)
|
||||
//generate a workorder report here get the path and send it with the message
|
||||
using (AyContext ct = AyaNova.Util.ServiceProviderProvider.DBContext)
|
||||
{
|
||||
|
||||
ReportBiz biz = ReportBiz.GetBiz(ct);
|
||||
//example with workorder report
|
||||
//{"AType":34,"selectedRowIds":[355],"ReportId":9,"ClientMeta":{"UserName":"AyaNova SuperUser","Authorization":"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOiIxNjQ2NzgyNTc4IiwiaXNzIjoiYXlhbm92YS5jb20iLCJpZCI6IjEifQ.ad7Acq54JCRGitDWKDJFFnqKkidbdaKaFmj-RA_RG5E","DownloadToken":"NdoU8ca3LG4L39Tj2oi3UReeeM7FLevTgbgopTPhGbA","TimeZoneName":"America/Los_Angeles","LanguageName":"en-US","Hour12":true,"CurrencyName":"USD","DefaultLocale":"en","PDFDate":"3/3/22","PDFTime":"3:38 PM"}}
|
||||
|
||||
var reportRequest = new DataListReportRequest();
|
||||
reportRequest.AType = AyaType.WorkOrder;
|
||||
reportRequest.ReportId = 9;
|
||||
reportRequest.SelectedRowIds = new long[] { 1 };
|
||||
var jwt= Api.Controllers.AuthController.GenRpt();
|
||||
reportRequest.ClientMeta = JToken.Parse($"{{'UserName':'AyaNova SuperUser','Authorization':'Bearer {jwt}','TimeZoneName':'America/Los_Angeles','LanguageName':'en-US','Hour12':true,'CurrencyName':'USD','DefaultLocale':'en','PDFDate':'3/3/22','PDFTime':'3:38 PM'}}");
|
||||
//get port number
|
||||
var match = System.Text.RegularExpressions.Regex.Match(ServerBootConfig.AYANOVA_USE_URLS,"[0-9]+");
|
||||
var API_URL = $"http://127.0.0.1:{match.Value}/api/{AyaNovaVersion.CurrentApiVersion}/";
|
||||
var jobid = await biz.RequestRenderReport(reportRequest, DateTime.UtcNow.AddMinutes(ServerBootConfig.AYANOVA_REPORT_RENDERING_TIMEOUT), API_URL, "AUTOMATED NO USER");
|
||||
if (jobid == null)
|
||||
{
|
||||
return "JOB FAILED";
|
||||
}
|
||||
else
|
||||
{
|
||||
bool done = false;
|
||||
//todo: need a timeout here that sets done as failed due to timeout
|
||||
while (!done)
|
||||
{
|
||||
var status = await JobsBiz.GetJobStatusAsync((Guid)jobid);
|
||||
switch (status)
|
||||
{
|
||||
case JobStatus.Completed:
|
||||
{
|
||||
//todo: get report path and send it
|
||||
//get job logs and parse file name from it
|
||||
JobOperationsBiz jobopsbiz = new JobOperationsBiz(ct, 1, AuthorizationRoles.BizAdmin);
|
||||
List<JobOperationsLogInfoItem> log = await jobopsbiz.GetJobLogListAsync((Guid)jobid);
|
||||
var lastLog=log[log.Count-1];
|
||||
var lastLogJ=JObject.Parse(lastLog.StatusText);
|
||||
|
||||
//await m.SendEmailAsync(toAddress, "DEBUG Test from Notification system", "This is a DEBUG test to confirm notification system is working", ServerGlobalOpsSettingsCache.Notify);
|
||||
return "ok";
|
||||
}
|
||||
case JobStatus.Failed:
|
||||
return $"JOB {jobid} started but failed";
|
||||
}
|
||||
if (status == JobStatus.Failed)
|
||||
{
|
||||
return $"JOB {jobid} started but failed";
|
||||
}
|
||||
}
|
||||
return "JOB FAILED DUE TO TIMEOUT";
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
await m.SendEmailAsync(toAddress, "Test from Notification system", "This is a test to confirm notification system is working", ServerGlobalOpsSettingsCache.Notify);
|
||||
return "ok";
|
||||
#endif
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user