This commit is contained in:
@@ -398,23 +398,13 @@ namespace AyaNova.Biz
|
||||
{
|
||||
log.LogDebug($"DeliverCustomerNotificationSMTP delivering notify event: {ne}");
|
||||
if (string.IsNullOrWhiteSpace(deliveryAddress))
|
||||
{
|
||||
{
|
||||
DeliveryLogItem.Fail = true;
|
||||
DeliveryLogItem.Error = $"No email address provided for smtp delivery; event: {ne}";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
string subject = ne.Subject;
|
||||
|
||||
|
||||
{
|
||||
IMailer m = AyaNova.Util.ServiceProviderProvider.Mailer;
|
||||
var body = ne.Message;
|
||||
|
||||
|
||||
|
||||
|
||||
if (!ServerGlobalOpsSettingsCache.Notify.SmtpDeliveryActive)
|
||||
{
|
||||
await NotifyEventHelper.AddOpsProblemEvent($"Email notifications are set to OFF at server, unable to send Customer email notification for this event:{ne}");
|
||||
@@ -423,7 +413,70 @@ namespace AyaNova.Biz
|
||||
DeliveryLogItem.Error = $"Email notifications are set to OFF at server, unable to send Customer email notification for this event: {ne}";
|
||||
}
|
||||
else
|
||||
await m.SendEmailAsync(deliveryAddress, subject, body, ServerGlobalOpsSettingsCache.Notify);
|
||||
{
|
||||
//generate report if applicable
|
||||
|
||||
if (subscription.LinkReportId != null)
|
||||
{
|
||||
long overrideLanguageId = 2;
|
||||
|
||||
ReportBiz biz = new ReportBiz(ct, 1, overrideLanguageId, AuthorizationRoles.BizAdmin);
|
||||
//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(overrideLanguageId);
|
||||
|
||||
//this could be adjusted by culture if we allow user to set a culture but that's getting a bit into the weeds, likely the server default is fine
|
||||
var pdfDate = new DateTime().ToShortDateString();
|
||||
var pdfTime = new DateTime().ToShortTimeString();
|
||||
|
||||
reportRequest.ClientMeta = JToken.Parse($"{{'UserName':'-','Authorization':'Bearer {jwt}','TimeZoneName':'America/Los_Angeles','LanguageName':'en-US','Hour12':true,'CurrencyName':'USD','DefaultLocale':'en','PDFDate':'{pdfDate}','PDFTime':'{pdfTime}'}}");
|
||||
//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)
|
||||
{
|
||||
throw new ApplicationException($"Report render job id is null failed to start");
|
||||
}
|
||||
else
|
||||
{
|
||||
bool done = false;
|
||||
bool timedOut = false;
|
||||
//todo: need a timeout here that sets done as failed due to timeout
|
||||
while (!done && !timedOut)
|
||||
{
|
||||
var status = await JobsBiz.GetJobStatusAsync((Guid)jobid);
|
||||
switch (status)
|
||||
{
|
||||
case JobStatus.Completed:
|
||||
{
|
||||
//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);
|
||||
var path = (string)lastLogJ["reportfilename"];
|
||||
var FilePath = FileUtil.GetFullPathForTemporaryFile(path);
|
||||
await m.SendEmailAsync(deliveryAddress, ne.Subject, ne.Message, ServerGlobalOpsSettingsCache.Notify, FilePath);
|
||||
break;
|
||||
}
|
||||
case JobStatus.Failed:
|
||||
throw new ApplicationException($"REPORT RENDER JOB {jobid} started but failed");
|
||||
}
|
||||
|
||||
}
|
||||
//throw new TimeoutException("JOB FAILED DUE TO REPORT RENDER TIMEOUT");
|
||||
}
|
||||
}
|
||||
else
|
||||
await m.SendEmailAsync(deliveryAddress, ne.Subject, ne.Message, ServerGlobalOpsSettingsCache.Notify);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user