Get()
{
// oggetti base
string answ = "ND";
StringBuilder sbMain = new StringBuilder();
StringBuilder sbActions = new StringBuilder();
StringBuilder sbAllProj = new StringBuilder();
int numFix = 0;
int numProj = 0;
int numFasi = 0;
string enableChiudiRaw = _configuration["EnableChiudiFasi"]??"false";
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);
doLog("", logType.none, ref sbMain);
var currProj = await dataService.AnagProjActiv();
numProj = currProj.Count;
doLog($"Progetti Attivi: {numProj}", logType.info, ref sbMain);
doLog("
", logType.none, ref sbMain);
// leggo fasi attive
var currFasiAct = await dataService.AnagFasiActiv();
numFasi = currFasiAct.Count;
doLog("", logType.none, ref sbMain);
doLog($"Fasi Attive: {numFasi}", logType.info, ref sbMain);
doLog("
", logType.none, ref sbMain);
// ciclo elenco fasi ancestor di ognuno...
doLog("Elenco Progetti valutati
", logType.none, ref sbAllProj);
foreach (var itemProj in currProj)
{
// cerco le sue fasi PARENT...
var subsetFasi = currFasiAct
.Where(x => x.IdxProgetto == itemProj.IdxProgetto && x.IdxFaseAncest == 0)
.ToList();
string projData = $"[P.{itemProj.IdxProgetto}] {itemProj.Gruppo} | {itemProj.ClienteNav.RagSociale} | {itemProj.NomeProj} | {subsetFasi.Count} Fasi";
doLog(projData, logType.trace, ref sbAllProj);
// ciclo x ogni fase Parent
foreach (var parentFase in subsetFasi)
{
// se ne trovo valuto le ore impiegate...
var statoFase = await dataService.CalcOreFase(parentFase.IdxFase, false);
// se ore usate > (ore budget x %) --> CHIUDO!
if (statoFase != null && statoFase.totOre >= (statoFase.budgetTime * (decimal)statoFase.percOpen))
{
// 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}";
doLog(projData, logType.local, ref sbActions);
doLog(currAction, logType.warn, ref sbActions);
doLog("------------------", logType.local, ref sbActions);
// se abilitato CHIUDO fase master e sottofasi!
if (enableChiudi)
{
await dataService.FasiSetActive(parentFase.IdxFase, false);
}
}
}
}
if (numFix > 0)
{
doLog("
", logType.none, ref sbMain);
doLog("", logType.none, ref sbMain);
doLog($"Fasi critiche: {numFix}", logType.info, ref sbMain);
doLog("
", logType.none, ref sbMain);
}
else
{
doLog("
", logType.none, ref sbMain);
doLog("", logType.none, ref sbMain);
doLog($"Tutti i progetti sono OK", logType.info, ref sbMain);
doLog("
", logType.none, ref sbMain);
}
// predispongo email
string msgTopic = "GPW: effettuata verifica progetti";
string msgBody = sbMain.ToString();
// se ho errori loggo...
if (numFix > 0)
{
msgBody += sbActions.ToString();
}
msgBody += "
";
msgBody += "
";
msgBody += "
";
msgBody += sbAllProj.ToString();
//{ HtmlEncoder.Default.Encode(callbackUrl)}
// invio email
await sendEmail(msgTopic, msgBody.Replace($"{Environment.NewLine}", "
"));
// ritorno solo LOG azioni
answ = numFix == 0 ? $"ALL {numProj} Proj OK" : $"Proj: {numProj} | Fasi: {numFasi} | Fixed/Closed: {numFix}";
return answ;
}
#endregion Public Methods
}
}