OK gestione email check progetti
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using GPW.CORE.Api.Data;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NLog;
|
||||
@@ -11,15 +10,18 @@ namespace GPW.CORE.Api.Controllers
|
||||
[ApiController]
|
||||
public class ProjCheckController : ControllerBase
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Dataservice x accesso DB
|
||||
/// </summary>
|
||||
protected ApiDataService dataService { get; set; }
|
||||
#region Private Fields
|
||||
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private readonly IEmailSender _emailSender;
|
||||
|
||||
private IConfiguration _configuration;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Avvio controller x CheckProgetti
|
||||
/// </summary>
|
||||
@@ -34,14 +36,32 @@ namespace GPW.CORE.Api.Controllers
|
||||
Log.Info("Avviata classe CheckProj");
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Protected Enums
|
||||
|
||||
protected enum logType
|
||||
{
|
||||
none,
|
||||
local,
|
||||
trace,
|
||||
info,
|
||||
warn
|
||||
}
|
||||
|
||||
#endregion Protected Enums
|
||||
|
||||
#region Protected Properties
|
||||
|
||||
/// <summary>
|
||||
/// Dataservice x accesso DB
|
||||
/// </summary>
|
||||
protected ApiDataService dataService { get; set; }
|
||||
|
||||
#endregion Protected Properties
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
/// <summary>
|
||||
/// Effettua log del tipo richiesto aggiungendo riga anche allo stringbuilder indicato
|
||||
/// </summary>
|
||||
@@ -50,24 +70,53 @@ namespace GPW.CORE.Api.Controllers
|
||||
/// <param name="currSB"></param>
|
||||
protected void doLog(string message, logType tipoLog, ref StringBuilder currSB)
|
||||
{
|
||||
bool doLine = true;
|
||||
switch (tipoLog)
|
||||
{
|
||||
case logType.info:
|
||||
Log.Info(message);
|
||||
break;
|
||||
|
||||
case logType.trace:
|
||||
Log.Trace(message);
|
||||
break;
|
||||
|
||||
case logType.warn:
|
||||
Log.Warn(message);
|
||||
break;
|
||||
|
||||
case logType.local:
|
||||
break;
|
||||
|
||||
default:
|
||||
case logType.none:
|
||||
doLine = false;
|
||||
break;
|
||||
}
|
||||
currSB.AppendLine(message);
|
||||
if (doLine)
|
||||
{
|
||||
currSB.AppendLine(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
currSB.Append(message);
|
||||
}
|
||||
}
|
||||
|
||||
protected async Task sendEmail(string subject, string message)
|
||||
{
|
||||
string emailRaw = _configuration["MailDest:ProjCheck"];
|
||||
List<string> emailDestList = emailRaw.Split(",").ToList();
|
||||
foreach (var dest in emailDestList)
|
||||
{
|
||||
await _emailSender.SendEmailAsync(dest, subject, message);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Public Methods
|
||||
|
||||
[HttpGet("ResAlloc")]
|
||||
public async Task<string> Get()
|
||||
{
|
||||
@@ -80,6 +129,12 @@ namespace GPW.CORE.Api.Controllers
|
||||
int numFix = 0;
|
||||
int numProj = 0;
|
||||
int numFasi = 0;
|
||||
string enableChiudiRaw = _configuration["EnableChiudiFasi"];
|
||||
bool enableChiudi = false;
|
||||
if (!string.IsNullOrEmpty(enableChiudiRaw))
|
||||
{
|
||||
bool.TryParse(enableChiudiRaw, out enableChiudi);
|
||||
}
|
||||
|
||||
// recupero progetti attivi...
|
||||
doLog("Esito della verifica stato ore progetto (allocate/consumate)", logType.info, ref sbMain);
|
||||
@@ -97,8 +152,7 @@ namespace GPW.CORE.Api.Controllers
|
||||
doLog("</div>", logType.none, ref sbMain);
|
||||
|
||||
// ciclo elenco fasi ancestor di ognuno...
|
||||
doLog(sepaMsg, logType.none, ref sbActions);
|
||||
doLog("<b>Elenco Progetti valutati</b>", logType.none, ref sbAllProj);
|
||||
doLog("<b>Elenco Progetti valutati</b><br/>", logType.none, ref sbAllProj);
|
||||
foreach (var itemProj in currProj)
|
||||
{
|
||||
// cerco le sue fasi PARENT...
|
||||
@@ -120,16 +174,19 @@ namespace GPW.CORE.Api.Controllers
|
||||
// segno che ho +1 fix
|
||||
numFix++;
|
||||
// x ora LOG... poi chiudo...
|
||||
string currAction = $"[F.{parentFase.IdxFase}] Budget esaurito in Fase {parentFase.NomeFase} {statoFase.totOre:N2}h consumate, budgt {statoFase.budgetTime:N0} al {statoFase.percOpen:P1}";
|
||||
string currAction = $" [F.{parentFase.IdxFase}] Budget esaurito in Fase {parentFase.NomeFase} {statoFase.totOre:N2}h consumate, budgt {statoFase.budgetTime:N0} al {statoFase.percOpen:P1}";
|
||||
|
||||
doLog(projData, logType.none, ref sbActions);
|
||||
doLog(projData, logType.local, ref sbActions);
|
||||
doLog(currAction, logType.warn, ref sbActions);
|
||||
doLog(sepaMsg, logType.none, ref sbActions);
|
||||
doLog("------------------", logType.local, ref sbActions);
|
||||
|
||||
// se abilitato CHIUDO fase master e sottofasi!
|
||||
}
|
||||
}
|
||||
}
|
||||
if (numFix > 0)
|
||||
{
|
||||
doLog("<hr/>", logType.none, ref sbMain);
|
||||
doLog("<div style=\"font-size: 1.1em;\">", logType.none, ref sbMain);
|
||||
doLog($"Fasi critiche: <b>{numFix}</b>", logType.info, ref sbMain);
|
||||
doLog("</div>", logType.none, ref sbMain);
|
||||
@@ -151,24 +208,13 @@ namespace GPW.CORE.Api.Controllers
|
||||
//{ HtmlEncoder.Default.Encode(callbackUrl)}
|
||||
|
||||
// invio email
|
||||
await sendEmail(msgTopic, msgBody.Replace($"{Environment.NewLine}","<br/>"));
|
||||
await sendEmail(msgTopic, msgBody.Replace($"{Environment.NewLine}", "<br/>"));
|
||||
|
||||
// ritorno solo LOG azioni
|
||||
answ = numFix == 0 ? $"ALL {numProj} Proj OK" : $"Proj: {numProj} | Fasi: {numFasi} | Fixed/Closed: {numFix}";
|
||||
return answ;
|
||||
}
|
||||
|
||||
|
||||
private readonly IEmailSender _emailSender;
|
||||
|
||||
protected async Task sendEmail(string subject, string message)
|
||||
{
|
||||
string emailRaw = _configuration["MailDest:ProjCheck"];
|
||||
List<string> emailDestList = emailRaw.Split(",").ToList();
|
||||
foreach (var dest in emailDestList)
|
||||
{
|
||||
await _emailSender.SendEmailAsync(dest, subject, message);
|
||||
}
|
||||
}
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,9 +24,9 @@
|
||||
},
|
||||
"MailDest": {
|
||||
"Admin": "samuele@steamware.net",
|
||||
"ProjCheck": "samuele.locatelli@egalware.com",
|
||||
"ProjCheck2": "samuele.locatelli@egalware.com,mara.baroni@egalware.com"
|
||||
"ProjCheck": "samuele.locatelli@egalware.com,mara.baroni@egalware.com"
|
||||
},
|
||||
"EnableChiudiFasi": "true",
|
||||
"Redis": {
|
||||
"Password": "",
|
||||
"AllowAdmin": false,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Version>3.0.2201.2616</Version>
|
||||
<Version>3.0.2201.2617</Version>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
Reference in New Issue
Block a user