Merge branch 'Release/Update202506_02'

This commit is contained in:
Samuele Locatelli
2025-07-03 15:45:45 +02:00
26 changed files with 1057 additions and 541 deletions
+3 -4
View File
@@ -170,14 +170,13 @@ namespace MP.Data.Controllers
/// Elenco da tabella Macchine con dati Energy
/// </summary>
/// <returns></returns>
public List<MacchineModel> MacchineEnergy()
public List<MacchineStatModel> MacchineEnergy()
{
List<MacchineModel> dbResult = new List<MacchineModel>();
List<MacchineStatModel> dbResult = new List<MacchineStatModel>();
using (var dbCtx = new MoonPro_STATSContext(_configuration))
{
dbResult = dbCtx
.DbSetMacchine
.FromSqlRaw("EXEC stp_MaccEnergy")
.DbSetMaccStat
.ToList();
}
return dbResult;
+36
View File
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
#nullable disable
// <Auto-Generated>
// This is here so CodeMaid doesn't reorganize this document
// </Auto-Generated>
namespace MP.Data.DbModels
{
public partial class MacchineStatModel
{
#region Public Properties
[Key]
public string IdxMacchina { get; set; }
/// <summary>
/// Cod macchina
/// </summary>
public string CodMacchina { get; set; } = "";
/// <summary>
/// Nome macchina
/// </summary>
public string Nome { get; set; } = "";
/// <summary>
/// Descrizione macchina
/// </summary>
public string Descrizione { get; set; } = "";
public bool Energy { get; set; } = false;
public bool Deleted { get; set; } = false;
#endregion Public Properties
}
}
+1 -1
View File
@@ -38,7 +38,7 @@ namespace MP.Data.DbModels
/// <summary>
/// Tipo Task
/// </summary>
public Task2ExeType TType { get; set; } = Task2ExeType.ND;
public Task2ExeType TType { get; set; } = Task2ExeType.ALL;
/// <summary>
/// Comando da invocare
+36 -29
View File
@@ -50,6 +50,7 @@ namespace MP.Data
public virtual DbSet<TurniOee> DbSetTurniOee { get; set; }
public virtual DbSet<UserActionLog> DbSetUserLog { get; set; }
public virtual DbSet<VocabolarioModel> DbSetVocabolario { get; set; }
public virtual DbSet<MacchineStatModel> DbSetMaccStat { get; set; }
#endregion Public Properties
@@ -176,55 +177,61 @@ namespace MP.Data
entity.Property(e => e.Nome).HasMaxLength(50);
});
modelBuilder.Entity<MacchineStatModel>(entity =>
{
//entity.HasNoKey();
entity.ToView("v_UI_MaccEnergy");
});
modelBuilder.Entity<DdbTurni>(entity =>
{
entity.HasNoKey();
{
entity.HasNoKey();
entity.ToView("v_UI_DDB_Turni");
entity.ToView("v_UI_DDB_Turni");
entity.Property(e => e.ClasseTempo).HasMaxLength(50);
entity.Property(e => e.ClasseTempo).HasMaxLength(50);
entity.Property(e => e.CodArticolo)
.IsRequired()
.HasMaxLength(50);
entity.Property(e => e.CodArticolo)
.IsRequired()
.HasMaxLength(50);
entity.Property(e => e.CodMacchina).HasMaxLength(50);
entity.Property(e => e.CodMacchina).HasMaxLength(50);
entity.Property(e => e.DataRif).HasColumnType("datetime");
entity.Property(e => e.DataRif).HasColumnType("datetime");
entity.Property(e => e.DataTurnoFine).HasColumnType("datetime");
entity.Property(e => e.DataTurnoFine).HasColumnType("datetime");
entity.Property(e => e.DataTurnoInizio).HasColumnType("datetime");
entity.Property(e => e.DataTurnoInizio).HasColumnType("datetime");
entity.Property(e => e.Descrizione).HasMaxLength(50);
entity.Property(e => e.Descrizione).HasMaxLength(50);
entity.Property(e => e.FinePeriodo).HasColumnType("datetime");
entity.Property(e => e.FinePeriodo).HasColumnType("datetime");
entity.Property(e => e.FineStato).HasColumnType("datetime");
entity.Property(e => e.FineStato).HasColumnType("datetime");
entity.Property(e => e.IdxMacchina)
.IsRequired()
.HasMaxLength(50);
entity.Property(e => e.IdxMacchina)
.IsRequired()
.HasMaxLength(50);
entity.Property(e => e.IdxOdl).HasColumnName("IdxODL");
entity.Property(e => e.IdxOdl).HasColumnName("IdxODL");
entity.Property(e => e.InizioPeriodo).HasColumnType("datetime");
entity.Property(e => e.InizioPeriodo).HasColumnType("datetime");
entity.Property(e => e.InizioStato).HasColumnType("datetime");
entity.Property(e => e.InizioStato).HasColumnType("datetime");
entity.Property(e => e.KeyRichiesta).HasMaxLength(50);
entity.Property(e => e.KeyRichiesta).HasMaxLength(50);
entity.Property(e => e.Pallet)
.HasMaxLength(20)
.HasColumnName("pallet");
entity.Property(e => e.Pallet)
.HasMaxLength(20)
.HasColumnName("pallet");
entity.Property(e => e.TempoCicloBase).HasColumnType("decimal(18, 8)");
entity.Property(e => e.TempoCicloBase).HasColumnType("decimal(18, 8)");
entity.Property(e => e.Turno)
.IsRequired()
.HasMaxLength(5);
});
entity.Property(e => e.Turno)
.IsRequired()
.HasMaxLength(5);
});
modelBuilder.Entity<AzioniUL>(entity =>
{
-1
View File
@@ -39,7 +39,6 @@
</li>
}
</ul>
@* <i>selezione ITEM da mostrare, tra quelli POSSIBILI dato periodo...</i> *@
</div>
</div>
</div>
-1
View File
@@ -8,7 +8,6 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Security.AccessControl;
namespace MP.Stats.Components
{
+2 -2
View File
@@ -36,7 +36,7 @@ namespace MP.Stats.Controllers
public async Task<List<TaskResultModel>> ExecuteAndReturnGet()
{
List<TaskResultModel> answ = new List<TaskResultModel>();
List<TaskListModel> listTask = await DService.TaskListAll(TaskMan.Objects.Enums.Task2ExeType.ND, "");
List<TaskListModel> listTask = await DService.TaskListAll(TaskMan.Objects.Enums.Task2ExeType.ALL, "");
// verifico SE ci siano task in scadenza...
DateTime adesso = DateTime.Now;
var task2exe = listTask.Where(x => x.DtNextExec <= adesso).ToList();
@@ -56,7 +56,7 @@ namespace MP.Stats.Controllers
[HttpGet("GetList")]
public async Task<List<TaskListModel>> GetList()
{
List<TaskListModel> answ = await DService.TaskListAll(TaskMan.Objects.Enums.Task2ExeType.ND, "");
List<TaskListModel> answ = await DService.TaskListAll(TaskMan.Objects.Enums.Task2ExeType.ALL, "");
return answ;
}
+111 -113
View File
@@ -32,7 +32,7 @@ namespace MP.Stats.Data
// setup compoenti REDIS
redisConn = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("Redis"));
redisDb = redisConn.GetDatabase();
redisDb = redisConn.GetDatabase();
#endif
// conf DB
@@ -250,6 +250,113 @@ namespace MP.Stats.Data
return answ;
}
/// <summary>
/// Recupero dati FluxLog secondo filtro + richiesta raggruppamento
/// </summary>
/// <param name="CurrFilter"></param>
/// <param name="fluxType"></param>
/// <param name="searchVal"></param>
/// <returns></returns>
public async Task<List<FLModel>> FluxLogRawData(SelectData CurrFilter, string fluxType, string searchVal = "")
{
// setup parametri costanti
string source = "DB";
Stopwatch sw = new Stopwatch();
sw.Start();
List<FLModel> result = new List<FLModel>();
// cerco in redis...
DateTime adesso = DateTime.Now;
string currKey = getCacheKey($"{redisBaseKey}:FL_DATA:FT_{fluxType}", CurrFilter);
RedisValue rawData = await redisDb.StringGetAsync(currKey);
if (rawData.HasValue)
{
result = JsonConvert.DeserializeObject<List<FLModel>>($"{rawData}");
source = "REDIS";
}
else
{
result = dbController.FluxLogRawData(CurrFilter.IdxMacchina, CurrFilter.DateStart, CurrFilter.DateEnd, fluxType);
// serializzp e salvo...
rawData = JsonConvert.SerializeObject(result);
await redisDb.StringSetAsync(currKey, rawData, FastCache);
}
if (result == null)
{
result = new List<FLModel>();
}
sw.Stop();
Log.Debug($"FluxLogRawData | {source} | {sw.Elapsed.TotalMilliseconds}ms");
return result;
}
/// <summary>
/// Elenco di tipi flusso disponibili
/// </summary>
/// <returns></returns>
public async Task<List<string>> FluxTypeList()
{
// setup parametri costanti
string source = "DB";
Stopwatch sw = new Stopwatch();
sw.Start();
List<string> result = new List<string>();
// cerco in redis...
DateTime adesso = DateTime.Now;
string currKey = $"{redisBaseKey}:FTList";
RedisValue rawData = await redisDb.StringGetAsync(currKey);
if (rawData.HasValue)
{
result = JsonConvert.DeserializeObject<List<string>>($"{rawData}");
source = "REDIS";
}
else
{
result = dbController.FluxTypeList();
// serializzp e salvo...
rawData = JsonConvert.SerializeObject(result);
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
}
if (result == null)
{
result = new List<string>();
}
sw.Stop();
Log.Debug($"FluxTypeList | {source} | {sw.Elapsed.TotalMilliseconds}ms");
return result;
}
public List<MacchineStatModel> MacchineEnergy()
{
// setup parametri costanti
string source = "DB";
Stopwatch sw = new Stopwatch();
sw.Start();
List<MacchineStatModel> result = new List<MacchineStatModel>();
// cerco in redis...
DateTime adesso = DateTime.Now;
string currKey = $"{redisBaseKey}:Cache:MacchineEnergy";
RedisValue rawData = redisDb.StringGet(currKey);
if (rawData.HasValue)
{
result = JsonConvert.DeserializeObject<List<MacchineStatModel>>($"{rawData}");
source = "REDIS";
}
else
{
result = dbController.MacchineEnergy().ToList();
// serializzp e salvo...
rawData = JsonConvert.SerializeObject(result);
redisDb.StringSet(currKey, rawData, FastCache);
}
if (result == null)
{
result = new List<MacchineStatModel>();
}
sw.Stop();
Log.Debug($"MacchineEnergy | {source} | {sw.Elapsed.TotalMilliseconds}ms");
return result;
}
public List<MacchineModel> MacchineGetAll()
{
// setup parametri costanti
@@ -282,38 +389,6 @@ namespace MP.Stats.Data
return result;
}
public List<MacchineModel> MacchineEnergy()
{
// setup parametri costanti
string source = "DB";
Stopwatch sw = new Stopwatch();
sw.Start();
List<MacchineModel> result = new List<MacchineModel>();
// cerco in redis...
DateTime adesso = DateTime.Now;
string currKey = $"{redisBaseKey}:Cache:MacchineEnergy";
RedisValue rawData = redisDb.StringGet(currKey);
if (rawData.HasValue)
{
result = JsonConvert.DeserializeObject<List<MacchineModel>>($"{rawData}");
source = "REDIS";
}
else
{
result = dbController.MacchineEnergy().ToList();
// serializzp e salvo...
rawData = JsonConvert.SerializeObject(result);
redisDb.StringSet(currKey, rawData, FastCache);
}
if (result == null)
{
result = new List<MacchineModel>();
}
sw.Stop();
Log.Debug($"MacchineEnergy | {source} | {sw.Elapsed.TotalMilliseconds}ms");
return result;
}
public Task<List<AutocompleteModel>> MachineList(bool onlyEnergy = false)
{
List<AutocompleteModel> answ = new List<AutocompleteModel>();
@@ -480,83 +555,6 @@ namespace MP.Stats.Data
return numRec;
}
/// <summary>
/// Recupero dati FluxLog secondo filtro + richiesta raggruppamento
/// </summary>
/// <param name="CurrFilter"></param>
/// <param name="fluxType"></param>
/// <param name="searchVal"></param>
/// <returns></returns>
public async Task<List<FLModel>> FluxLogRawData(SelectData CurrFilter, string fluxType, string searchVal = "")
{
// setup parametri costanti
string source = "DB";
Stopwatch sw = new Stopwatch();
sw.Start();
List<FLModel> result = new List<FLModel>();
// cerco in redis...
DateTime adesso = DateTime.Now;
string currKey = getCacheKey($"{redisBaseKey}:FL_DATA:FT_{fluxType}", CurrFilter);
RedisValue rawData = await redisDb.StringGetAsync(currKey);
if (rawData.HasValue)
{
result = JsonConvert.DeserializeObject<List<FLModel>>($"{rawData}");
source = "REDIS";
}
else
{
result = dbController.FluxLogRawData(CurrFilter.IdxMacchina, CurrFilter.DateStart, CurrFilter.DateEnd, fluxType);
// serializzp e salvo...
rawData = JsonConvert.SerializeObject(result);
await redisDb.StringSetAsync(currKey, rawData, FastCache);
}
if (result == null)
{
result = new List<FLModel>();
}
sw.Stop();
Log.Debug($"FluxLogRawData | {source} | {sw.Elapsed.TotalMilliseconds}ms");
return result;
}
/// <summary>
/// Elenco di tipi flusso disponibili
/// </summary>
/// <returns></returns>
public async Task<List<string>> FluxTypeList()
{
// setup parametri costanti
string source = "DB";
Stopwatch sw = new Stopwatch();
sw.Start();
List<string> result = new List<string>();
// cerco in redis...
DateTime adesso = DateTime.Now;
string currKey = $"{redisBaseKey}:FTList";
RedisValue rawData = await redisDb.StringGetAsync(currKey);
if (rawData.HasValue)
{
result = JsonConvert.DeserializeObject<List<string>>($"{rawData}");
source = "REDIS";
}
else
{
result = dbController.FluxTypeList();
// serializzp e salvo...
rawData = JsonConvert.SerializeObject(result);
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
}
if (result == null)
{
result = new List<string>();
}
sw.Stop();
Log.Debug($"FluxTypeList | {source} | {sw.Elapsed.TotalMilliseconds}ms");
return result;
}
/// <summary>
/// Statistiche ODL
/// </summary>
@@ -787,6 +785,8 @@ namespace MP.Stats.Data
/// </summary>
protected static Dictionary<string, string> DictFluxUm = new Dictionary<string, string>();
#endregion Protected Fields
#if false
/// <summary>
/// Oggetto per connessione a REDIS
@@ -796,11 +796,9 @@ namespace MP.Stats.Data
/// <summary>
/// Oggetto DB redis da impiegare x chiamate R/W
/// </summary>
protected IDatabase redisDb = null!;
protected IDatabase redisDb = null!;
#endif
#endregion Protected Fields
#region Protected Methods
protected string getCacheKey(string TableName, SelectData CurrFilter)
+2 -2
View File
@@ -4,8 +4,8 @@
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>MP.Stats</RootNamespace>
<UserSecretsId>826e877c-ba70-4253-84cb-d0b1cafd4440</UserSecretsId>
<Version>6.16.2507.0217</Version>
<Version>6.16.2507.0217</Version>
<Version>6.16.2507.0315</Version>
<Version>6.16.2507.0315</Version>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
+1 -1
View File
@@ -29,7 +29,7 @@ namespace MP.Stats.Pages
protected override async Task OnInitializedAsync()
{
await StatService.FlushCache();
await TServ.FlushCache();
await TServ.FlushCacheAsync();
await TradServ.FlushCache();
await Task.Delay(500);
NavManager.NavigateTo("", true);
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo statistiche MAPO</i>
<h4>Versione: 6.16.2507.0217</h4>
<h4>Versione: 6.16.2507.0315</h4>
<br />
Note di rilascio:
<ul>
+1 -1
View File
@@ -1 +1 @@
6.16.2507.0217
6.16.2507.0315
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>6.16.2507.0217</version>
<version>6.16.2507.0315</version>
<url>https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/MP.Stats.zip</url>
<changelog>https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/ChangeLog.html</changelog>
<mandatory>false</mandatory>
+46 -1
View File
@@ -323,7 +323,7 @@ namespace MP.TaskMan.Controllers
{
dbResult = dbCtx
.DbSetTaskList
.Where(x => (TType == Task2ExeType.ND || x.TType == TType))
.Where(x => (TType == Task2ExeType.ALL || x.TType == TType))
.OrderBy(x => x.Ordinal)
.ToList();
}
@@ -388,6 +388,50 @@ namespace MP.TaskMan.Controllers
return done;
}
/// <summary>
/// Riordino record di un dato gruppo (da richiamare post cambio gruppo...)
/// </summary>
/// <param name="codGroup"></param>
/// <returns></returns>
public bool TaskListReorder(int codGroup)
{
bool done = false;
using (var dbCtx = new TaskContext(_configuration))
{
// in primis recupero i record del gruppo ordinati
var currList = dbCtx
.DbSetTaskList
.Where(x => x.Group == codGroup)
.OrderBy(x => x.Ordinal)
.ThenBy(x => x.TaskId)
.ToList();
int newIdx = 0;
int numRec = currList.Count;
// li verifico in base al loro id attuale...
foreach (var item in currList)
{
newIdx++;
// se va cambiato lo riassegno
if (item.Ordinal != newIdx)
{
item.Ordinal = newIdx;
dbCtx.Entry(item).State = EntityState.Modified;
}
}
// salvo!
try
{
dbCtx.SaveChanges();
done = true;
}
catch (Exception exc)
{
Log.Error($"Eccezione in TaskListReorder{Environment.NewLine}{exc}");
}
}
return done;
}
/// <summary>
/// Upsert record TaskList
/// </summary>
@@ -407,6 +451,7 @@ namespace MP.TaskMan.Controllers
if (currData != null)
{
currData.Ordinal = rec2upd.Ordinal;
currData.Group = rec2upd.Group;
currData.Enabled = rec2upd.Enabled;
currData.Name = rec2upd.Name;
currData.Descript = rec2upd.Descript;
@@ -0,0 +1,145 @@
// <auto-generated />
using System;
using MP.TaskMan;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace MP.TaskMan.Migrations
{
[DbContext(typeof(TaskContext))]
[Migration("20250703101600_AddTaskGroup")]
partial class AddTaskGroup
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.UseCollation("SQL_Latin1_General_CP1_CI_AS")
.HasAnnotation("ProductVersion", "6.0.36")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
modelBuilder.Entity("MP.TaskMan.Models.TaskExecModel", b =>
{
b.Property<int>("TaskExecId")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("TaskExecId"), 1L, 1);
b.Property<DateTime>("DtEnd")
.HasColumnType("datetime2");
b.Property<DateTime>("DtStart")
.HasColumnType("datetime2");
b.Property<bool>("IsError")
.HasColumnType("bit");
b.Property<string>("Result")
.HasColumnType("nvarchar(max)");
b.Property<int>("TaskId")
.HasColumnType("int");
b.HasKey("TaskExecId");
b.HasIndex("TaskId");
b.ToTable("TaskExec");
});
modelBuilder.Entity("MP.TaskMan.Models.TaskListModel", b =>
{
b.Property<int>("TaskId")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("TaskId"), 1L, 1);
b.Property<string>("Args")
.HasColumnType("nvarchar(max)");
b.Property<int>("Cad")
.HasColumnType("int");
b.Property<string>("Command")
.HasColumnType("nvarchar(max)");
b.Property<string>("Descript")
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("DtLastExec")
.HasColumnType("datetime2");
b.Property<DateTime>("DtNextExec")
.HasColumnType("datetime2");
b.Property<bool>("Enabled")
.HasColumnType("bit");
b.Property<int>("Freq")
.HasColumnType("int");
b.Property<int>("Group")
.HasColumnType("int");
b.Property<double>("LastDuration")
.HasColumnType("float");
b.Property<bool>("LastIsError")
.HasColumnType("bit");
b.Property<string>("LastResult")
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<int>("Ordinal")
.HasColumnType("int");
b.Property<int>("TType")
.HasColumnType("int");
b.HasKey("TaskId");
b.ToTable("TaskList");
});
modelBuilder.Entity("MP.TaskMan.Models.TaskResultModel", b =>
{
b.Property<string>("Task")
.HasColumnType("nvarchar(450)");
b.Property<int>("ExecResult")
.HasColumnType("int");
b.Property<string>("TextResult")
.HasColumnType("nvarchar(max)");
b.HasKey("Task");
b.ToTable("DbSetTaskResult");
});
modelBuilder.Entity("MP.TaskMan.Models.TaskExecModel", b =>
{
b.HasOne("MP.TaskMan.Models.TaskListModel", "TaskListNav")
.WithMany()
.HasForeignKey("TaskId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("TaskListNav");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,42 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace MP.TaskMan.Migrations
{
public partial class AddTaskGroup : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "Group",
table: "TaskList",
type: "int",
nullable: false,
defaultValue: 1);
migrationBuilder.CreateTable(
name: "DbSetTaskResult",
columns: table => new
{
Task = table.Column<string>(type: "nvarchar(450)", nullable: false),
ExecResult = table.Column<int>(type: "int", nullable: false),
TextResult = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_DbSetTaskResult", x => x.Task);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "DbSetTaskResult");
migrationBuilder.DropColumn(
name: "Group",
table: "TaskList");
}
}
}
@@ -18,7 +18,7 @@ namespace MP.TaskMan.Migrations
#pragma warning disable 612, 618
modelBuilder
.UseCollation("SQL_Latin1_General_CP1_CI_AS")
.HasAnnotation("ProductVersion", "6.0.33")
.HasAnnotation("ProductVersion", "6.0.36")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
@@ -85,6 +85,9 @@ namespace MP.TaskMan.Migrations
b.Property<int>("Freq")
.HasColumnType("int");
b.Property<int>("Group")
.HasColumnType("int");
b.Property<double>("LastDuration")
.HasColumnType("float");
@@ -108,6 +111,22 @@ namespace MP.TaskMan.Migrations
b.ToTable("TaskList");
});
modelBuilder.Entity("MP.TaskMan.Models.TaskResultModel", b =>
{
b.Property<string>("Task")
.HasColumnType("nvarchar(450)");
b.Property<int>("ExecResult")
.HasColumnType("int");
b.Property<string>("TextResult")
.HasColumnType("nvarchar(max)");
b.HasKey("Task");
b.ToTable("DbSetTaskResult");
});
modelBuilder.Entity("MP.TaskMan.Models.TaskExecModel", b =>
{
b.HasOne("MP.TaskMan.Models.TaskListModel", "TaskListNav")
+6 -1
View File
@@ -19,6 +19,11 @@ namespace MP.TaskMan.Models
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int TaskId { get; set; } = 0;
/// <summary>
/// Gruppo task (per gestione precedenze e semaforo exec)
/// </summary>
public int Group { get; set; } = 1;
/// <summary>
/// Ordinale x esecuzione
/// </summary>
@@ -42,7 +47,7 @@ namespace MP.TaskMan.Models
/// <summary>
/// Tipo Task
/// </summary>
public Task2ExeType TType { get; set; } = Task2ExeType.ND;
public Task2ExeType TType { get; set; } = Task2ExeType.ALL;
/// <summary>
/// Comando da invocare
+1 -1
View File
@@ -40,7 +40,7 @@ namespace MP.TaskMan.Objects
/// <summary>
/// Tipo indefinito / ALL
/// </summary>
ND,
ALL,
/// <summary>
/// Chiamata exe esterno
+78 -14
View File
@@ -126,6 +126,7 @@ namespace MP.TaskMan.Services
case Task2ExeType.SqlStored:
answ = MLController.ExecuteSqlTask(TaskRec.TaskId, SchedNext);
break;
case Task2ExeType.RestCallGet:
DateTime dtStart = DateTime.Now;
// in primis testo la chiamata al servizio Health
@@ -149,11 +150,12 @@ namespace MP.TaskMan.Services
answ = MLController.TaskExecSaveExecuted(TaskRec.TaskId, SchedNext, tExeMod);
}
break;
default:
break;
}
// svuoto cache!
await FlushCache();
await FlushCacheAsync();
}
return answ;
}
@@ -162,10 +164,10 @@ namespace MP.TaskMan.Services
/// Pulizia cache Redis (tutta)
/// </summary>
/// <returns></returns>
public async Task<bool> FlushCache()
public bool FlushCache()
{
RedisValue pattern = new RedisValue($"{RedisBaseKey}:*");
bool answ = await ExecFlushRedisPattern(pattern);
bool answ = ExecFlushRedisPattern(pattern);
return answ;
}
@@ -173,10 +175,32 @@ namespace MP.TaskMan.Services
/// Pulizia cache Redis per chiave specifica (da RedisBaseKey...)
/// </summary>
/// <returns></returns>
public async Task<bool> FlushCache(string KeyReq)
public bool FlushCache(string KeyReq)
{
RedisValue pattern = new RedisValue($"{RedisBaseKey}:{KeyReq}:*");
bool answ = await ExecFlushRedisPattern(pattern);
bool answ = ExecFlushRedisPattern(pattern);
return answ;
}
/// <summary>
/// Pulizia cache Redis (tutta) modalità Async
/// </summary>
/// <returns></returns>
public async Task<bool> FlushCacheAsync()
{
RedisValue pattern = new RedisValue($"{RedisBaseKey}:*");
bool answ = await ExecFlushRedisPatternAsync(pattern);
return answ;
}
/// <summary>
/// Pulizia cache Redis per chiave specifica (da RedisBaseKey...) modalità Async
/// </summary>
/// <returns></returns>
public async Task<bool> FlushCacheAsync(string KeyReq)
{
RedisValue pattern = new RedisValue($"{RedisBaseKey}:{KeyReq}:*");
bool answ = await ExecFlushRedisPatternAsync(pattern);
return answ;
}
@@ -292,7 +316,20 @@ namespace MP.TaskMan.Services
bool dbResult = MLController.TaskListMove(rec2upd, moveUp);
await Task.Delay(50);
// svuoto cache!
await FlushCache();
await FlushCacheAsync();
return dbResult;
}
/// <summary>
/// Riordino record di un dato gruppo (da richiamare post cambio gruppo...)
/// </summary>
/// <param name="codGroup"></param>
/// <returns></returns>
public bool TaskListReorder(int codGroup)
{
bool dbResult = MLController.TaskListReorder(codGroup);
// svuoto cache!
FlushCache();
return dbResult;
}
@@ -306,7 +343,7 @@ namespace MP.TaskMan.Services
bool dbResult = MLController.TaskListUpsert(rec2upd);
await Task.Delay(50);
// svuoto cache!
await FlushCache();
await FlushCacheAsync();
return dbResult;
}
@@ -336,18 +373,17 @@ namespace MP.TaskMan.Services
private Dictionary<string, string> connStrParams = new Dictionary<string, string>();
private string DataBase { get; set; } = "";
private string DataSource { get; set; } = "";
private string RedisBaseKey { get; set; } = "MP:TASK";
#endregion Private Fields
#region Private Properties
private string DataBase { get; set; } = "";
private string DataSource { get; set; } = "";
private MpTaskController MLController { get; set; } = null!;
private RestCallService RCallService { get; set; } = null!;
private string RedisBaseKey { get; set; } = "MP:TASK";
#endregion Private Properties
@@ -358,7 +394,35 @@ namespace MP.TaskMan.Services
/// </summary>
/// <param name="pattern"></param>
/// <returns></returns>
private async Task<bool> ExecFlushRedisPattern(RedisValue pattern)
private bool ExecFlushRedisPattern(RedisValue pattern)
{
bool answ = false;
var listEndpoints = redisConn.GetEndPoints();
foreach (var endPoint in listEndpoints)
{
//var server = redisConnAdmin.GetServer(listEndpoints[0]);
var server = redisConn.GetServer(endPoint);
if (server != null)
{
var keyList = server.Keys(redisDb.Database, pattern);
foreach (var item in keyList)
{
redisDb.KeyDelete(item);
}
answ = true;
}
}
// notifico update ai client in ascolto x reset cache
NotifyReloadRequest($"FlushRedisCache | {pattern}");
return answ;
}
/// <summary>
/// Esegue flush memoria redis dato pattern modalità Async
/// </summary>
/// <param name="pattern"></param>
/// <returns></returns>
private async Task<bool> ExecFlushRedisPatternAsync(RedisValue pattern)
{
bool answ = false;
var listEndpoints = redisConn.GetEndPoints();
+97 -91
View File
@@ -1,94 +1,100 @@
@if (CurrRecord != null)
@if (isProcessing)
{
<hr />
<div class="row g-1">
<div class="col-md-1">
<div class="form-floating">
<input type="number" class="form-control" @bind="@CurrRecord.Ordinal">
<label class="small">Ordine Esec.</label>
</div>
</div>
<div class="col-md-1">
<div class="form-floating">
<div class="form-control">
<div class="form-check form-switch small">
<input class="form-check-input" type="checkbox" role="switch" title="Abilitato / Disabilitato" @bind-value="@CurrRecord.Enabled" checked="@CurrRecord.Enabled">
</div>
</div>
<label class="small">Enabled</label>
</div>
</div>
<div class="col-md-2">
<div class="form-floating">
<input type="text" class="form-control" @bind="@CurrRecord.Name">
<label class="small">Nome Task</label>
</div>
</div>
<div class="col-md-4">
<div class="form-floating">
<input type="text" class="form-control" @bind="@CurrRecord.Descript">
<label class="small">Descrizione Task</label>
</div>
</div>
<div class="col-md-2">
<div class="form-floating">
<input type="datetime-local" class="form-control" @bind="@CurrRecord.DtNextExec">
<label class="small">Prossima Esecuzione</label>
</div>
</div>
<div class="col-md-1">
<div class="form-floating">
<select class="form-select" @bind="@CurrRecord.Freq">
@foreach (var option in Enum.GetValues(typeof(MP.TaskMan.Objects.Enums.TaskFreqType)))
{
<option value="@option">
@option
</option>
}
</select>
<label class="small">Frequenza</label>
</div>
</div>
<div class="col-md-1">
<div class="form-floating">
<input type="number" class="form-control" @bind="@CurrRecord.Cad">
<label class="small">Cadenza</label>
</div>
</div>
</div>
<div class="row g-1">
<div class="col-md-2">
<div class="form-floating">
<select class="form-select" @bind="@CurrRecord.TType">
@foreach (var option in Enum.GetValues(typeof(MP.TaskMan.Objects.Enums.Task2ExeType)))
{
<option value="@option">
@option
</option>
}
</select>
<label class="small">Tipo Task</label>
</div>
</div>
<div class="col-md-4">
<div class="form-floating">
<input type="text" class="form-control" @bind="@CurrRecord.Command">
<label class="small">Comando</label>
</div>
</div>
<div class="col-md-4">
<div class="form-floating">
<input type="text" class="form-control" @bind="@CurrRecord.Args">
<label class="small">Parametri</label>
</div>
</div>
<div class="col-md-1 pt-2">
<button class="btn btn-lg w-100 btn-success" @onclick="()=>doSave()" title="Save"><i class="far fa-save"></i> Save</button>
</div>
<div class="col-md-1 pt-2">
<button class="btn btn-lg w-100 btn-warning" @onclick="()=>doCancel()" title="Cancel"><i class="fas fa-ban"></i> Cancel</button>
</div>
</div>
<LoadingData DisplaySize="LoadingData.CtrlSize.Large" DisplayMode="LoadingData.SpinMode.Growl" Title="Processing"></LoadingData>
}
else
{
if (CurrRecord != null)
{
<hr />
<div class="row g-1">
<div class="col-md-1">
<div class="form-floating">
<input type="number" class="form-control bg-info bg-opacity-25" @bind="@CurrRecord.Group" min="1" max="99">
<label class="small bg-opacity-50">Gruppo</label>
</div>
</div>
<div class="col-md-1">
<div class="form-floating">
<div class="form-control">
<div class="form-check form-switch small">
<input class="form-check-input" type="checkbox" role="switch" title="Abilitato / Disabilitato" @bind-value="@CurrRecord.Enabled" checked="@CurrRecord.Enabled">
</div>
</div>
<label class="small">Enabled</label>
</div>
</div>
<div class="col-md-2">
<div class="form-floating">
<input type="text" class="form-control" @bind="@CurrRecord.Name">
<label class="small">Nome Task</label>
</div>
</div>
<div class="col-md-4">
<div class="form-floating">
<input type="text" class="form-control" @bind="@CurrRecord.Descript">
<label class="small">Descrizione Task</label>
</div>
</div>
<div class="col-md-2">
<div class="form-floating">
<input type="datetime-local" class="form-control" @bind="@CurrRecord.DtNextExec">
<label class="small">Prossima Esecuzione</label>
</div>
</div>
<div class="col-md-1">
<div class="form-floating">
<select class="form-select" @bind="@CurrRecord.Freq">
@foreach (var option in Enum.GetValues(typeof(MP.TaskMan.Objects.Enums.TaskFreqType)))
{
<option value="@option">
@option
</option>
}
</select>
<label class="small">Frequenza</label>
</div>
</div>
<div class="col-md-1">
<div class="form-floating">
<input type="number" class="form-control" @bind="@CurrRecord.Cad">
<label class="small">Cadenza</label>
</div>
</div>
</div>
<div class="row g-1">
<div class="col-md-2">
<div class="form-floating">
<select class="form-select" @bind="@CurrRecord.TType">
@foreach (var option in Enum.GetValues(typeof(MP.TaskMan.Objects.Enums.Task2ExeType)))
{
<option value="@option">
@option
</option>
}
</select>
<label class="small">Tipo Task</label>
</div>
</div>
<div class="col-md-4">
<div class="form-floating">
<input type="text" class="form-control" @bind="@CurrRecord.Command">
<label class="small">Comando</label>
</div>
</div>
<div class="col-md-4">
<div class="form-floating">
<input type="text" class="form-control" @bind="@CurrRecord.Args">
<label class="small">Parametri</label>
</div>
</div>
<div class="col-md-1 pt-2">
<button class="btn btn-lg w-100 btn-success" @onclick="() => doSave()" title="Save"><i class="far fa-save"></i> Save</button>
</div>
<div class="col-md-1 pt-2">
<button class="btn btn-lg w-100 btn-warning" @onclick="() => doCancel()" title="Cancel"><i class="fas fa-ban"></i> Cancel</button>
</div>
</div>
}
}
+18
View File
@@ -16,6 +16,13 @@ namespace MP.TaskMan
#endregion Public Properties
protected int oldGroup = 0;
protected override void OnParametersSet()
{
oldGroup = CurrRecord != null ? CurrRecord.Group : 0;
}
#region Protected Properties
[Inject]
@@ -32,15 +39,26 @@ namespace MP.TaskMan
protected async Task doSave()
{
isProcessing = true;
bool fatto = false;
await Task.Delay(1);
if (CurrRecord != null)
{
fatto = await TService.TaskListUpsert(CurrRecord);
// se cambiato gruppo chiamo reorg gruppo old/new...
if (CurrRecord.Group != oldGroup)
{
TService.TaskListReorder(oldGroup);
TService.TaskListReorder(CurrRecord.Group);
oldGroup = CurrRecord.Group;
}
}
isProcessing = false;
await EC_update.InvokeAsync(fatto);
}
#endregion Protected Methods
private bool isProcessing= false;
}
}
+10 -132
View File
@@ -8,7 +8,7 @@
</div>
<div class="px-2">
<div class="input-group">
@if (TypeSel != MP.TaskMan.Objects.Enums.Task2ExeType.ND)
@if (TypeSel != MP.TaskMan.Objects.Enums.Task2ExeType.ALL)
{
@if (currRecord == null)
{
@@ -21,7 +21,7 @@
}
else
{
<button class="btn btn-outline-secondary">Sel &rarr;</button>
<button class="btn btn-outline-secondary">Tipo Task &rarr;</button>
}
<select class="form-select" @bind="@TypeSel">
@foreach (var option in Enum.GetValues(typeof(MP.TaskMan.Objects.Enums.Task2ExeType)))
@@ -42,149 +42,27 @@
<ProgressDisplay DisplaySize="ProgressDisplay.ModalSize.Medium" ExpTimeMSec="@expTimeMsec" CurrVal="@currVal" NextVal="@nextVal" MaxVal="@MaxVal" Title="Task Processing" RefreshInterval="200"></ProgressDisplay>
<LoadingData Title="Elaborazione..." DisplayMode="LoadingData.SpinMode.BounceLine" DisplaySize="LoadingData.CtrlSize.Large"></LoadingData>
}
else if (ListRecords == null)
else if (SearchRecords == null)
{
<LoadingData></LoadingData>
}
else if (totalCount == 0)
else if (SearchRecords.Count==0)
{
<div class="alert alert-warning text-center display-4">Nessun record trovato</div>
<div class="alert alert-info fs-5">Nessun record trovato dati i criteri espressi</div>
}
else
{
<div class="row">
<div class="col-12">
<table class="table table-sm table-striped">
<thead>
<tr>
<th>
<button class="btn btn-sm btn-info" @onclick="DoReset" title="Reset"><i class="fas fa-sync"></i></button>
</th>
<th>Ord</th>
<th>Task</th>
<th>Tipo</th>
@if (detRecord == null)
{
<th>Command</th>
}
<th>Sched.</th>
@if (detRecord == null)
{
<th class="text-end">Last</th>
<th class="text-end">Next</th>
<th class="text-end">Result</th>
<th>
<button class="btn btn-sm btn-danger me-1" @onclick="ForceAll" title="Force All"><i class="fas fa-play"></i></button>
</th>
}
</tr>
</thead>
<tbody>
@foreach (var record in ListRecords)
{
<tr class="@checkSelect(@record)">
<td class="text-nowrap">
<button class="btn btn-sm btn-info" @onclick="()=>DoSelect(record)" title="Select"><i class="fas fa-search"></i></button>
@if (detRecord == null)
{
@if (currRecord == null)
{
<button class="btn btn-sm btn-primary ms-1" @onclick="()=>DoEdit(record)" title="Edit"><i class="fas fa-pencil-alt"></i></button>
<button class="btn btn-sm btn-success" @onclick="()=>DoClone(record)" title="Clona"><i class="fas fa-magic"></i></button>
}
else
{
<button class="btn btn-sm btn-secondary ms-1" @onclick="()=>DoCancel()" title="Cancel"><i class="fas fa-undo"></i></button>
}
}
</td>
<td class="text-nowrap">
@if (detRecord == null)
{
@if (record.Ordinal == minOrdinal)
{
<button class="btn btn-sm btn-outline-secondary mx-1" disabled title="Cannot Move"><i class="fas fa-caret-up"></i></button>
}
else
{
<button class="btn btn-sm btn-outline-primary mx-1" @onclick="()=>DoMove(record, true)" title="Move Up"><i class="fas fa-caret-up"></i></button>
}
}
<b>@record.Ordinal</b>
@if (detRecord == null)
{
@if (record.Ordinal == maxOrdinal)
{
<button class="btn btn-sm btn-outline-secondary mx-1" disabled title="Cannot Move"><i class="fas fa-caret-down"></i></button>
}
else
{
<button class="btn btn-sm btn-outline-primary mx-1" @onclick="()=>DoMove(record, false)" title="Move Down"><i class="fas fa-caret-down"></i></button>
}
}
</td>
<td class="text-nowrap @checkDis(@record)">
<div>@record.Name</div>
<div class="small text-truncate">@record.Descript</div>
</td>
<td class="@checkDis(@record)">
@record.TType
</td>
@if (detRecord == null)
{
<td class="small text-truncate text-break @checkDis(@record)">
<div class="font-monospace fw-bold" title="@record.Command">@TextReduce(record.Command, 32)</div>
<div class="small text-break" title="@record.Args">@TextReduce(record.Args, 40)</div>
</td>
}
<td>@record.Freq &times; @record.Cad</td>
@if (detRecord == null)
{
<td class="text-end text-nowrap @checkDis(@record)">
<div>@($"{record.DtLastExec:yyyy-MM-dd}")</div>
<div class="small">@($"{record.DtLastExec:ddd HH:mm:ss}")</div>
</td>
<td class="text-end text-nowrap @checkDis(@record)">
<div>@($"{record.DtNextExec:yyyy-MM-dd}")</div>
<div class="small">@($"{record.DtNextExec:ddd HH:mm:ss}")</div>
</td>
<td class="text-end @checkDis(@record)">
<b>@($"{record.LastDuration:N3}")</b> <sub>sec</sub> <button class="btn btn-sm @btnCss(record)" @onclick="() => ToggleDetail(record)" title="Ultima esecuzione"><i class="far @iconCss(record)"></i></button>
</td>
<td>
@if(record.Enabled)
{
<button class="btn btn-sm @btnRunCss(record.DtNextExec) me-1" @onclick="()=>DoRun(record)" title="Run Now"><i class="fas fa-play"></i></button>
}
else
{
<button class="btn btn-sm btn-secondary me-1" title="Disabled / Cannot run!" disabled><i class="fas fa-play"></i></button>
}
</td>
}
</tr>
@if (DetailTaskId != null && DetailTaskId.TaskId == record.TaskId)
{
<tr>
<td colspan="10 @checkDis(@record)">
<div class="d-flex justify-content-end">
<div class="p-1 small alert @alCss(record)">
<div class="text-trim">@record.LastResult</div>
</div>
</div>
</td>
</tr>
}
}
</tbody>
</table>
@foreach (var item in ListRecords)
{
<TaskListTable CodGroup="item.Key" AllRecords="item.Value" EC_DoReset="DoReset" EC_ForceAll="ForceAll" EC_Cancel="DoCancel" EC_Clone="DoClone" EC_Select="DoSelect" EC_Edit="DoEdit" EC_Run="DoRun" EC_Move="DoMove"></TaskListTable>
}
@* <TaskListTable AllRecords="SearchRecords" EC_DoReset="DoReset" EC_ForceAll="ForceAll" EC_Cancel="DoCancel" EC_Clone="DoClone" EC_Select="DoSelect" EC_Edit="DoEdit" EC_Run="DoRun" EC_Move="DoMove"></TaskListTable> *@
</div>
</div>
}
</div>
<div class="card-footer py-1">
<DataPager PageSize="numRecord" currPage="currPage" numRecordChanged="ForceReload" numPageChanged="ForceReloadPage" exportEnabled="false" exportRequested="ExportCsv" fileName="@fileName" totalCount="totalCount" showLoading="isLoading" />
</div>
</div>
</div>
@if (detRecord != null && !isLoading)
+13 -143
View File
@@ -8,48 +8,6 @@ namespace MP.TaskMan
{
public partial class TaskList : ComponentBase
{
#region Public Methods
protected string checkSelect(TaskListModel selRec)
{
string answ = "";
if (currRecord != null)
{
answ = (currRecord.Equals(selRec)) ? "table-info" : "";
}
else if (detRecord != null)
{
answ = detRecord.Equals(selRec) ? "table-info" : "";
}
#if false
// verifico se sia disabilitato...
if (!selRec.Enabled)
{
answ += " text-secondary text-opacity-50 textStriked";
}
#endif
return answ;
}
protected string checkDis(TaskListModel selRec)
{
string answ = "";
// verifico se sia disabilitato...
if (!selRec.Enabled)
{
answ += " text-secondary text-opacity-75 textStriked";
}
return answ;
}
#endregion Public Methods
#region Protected Fields
protected string fileName = "TaskList.csv";
#endregion Protected Fields
#region Protected Properties
[Inject]
@@ -112,18 +70,6 @@ namespace MP.TaskMan
await InvokeAsync(StateHasChanged);
}
protected string alCss(TaskListModel TaskRec)
{
return TaskRec.LastIsError ? "alert-danger" : "alert-success";
}
protected string btnCss(TaskListModel TaskRec)
{
string answ = DetailTaskId != null && DetailTaskId.TaskId == TaskRec.TaskId ? "btn-" : "btn-outline-";
answ += TaskRec.LastIsError ? "danger" : "success";
return answ;
}
protected async Task DoCancel()
{
currRecord = null;
@@ -160,19 +106,19 @@ namespace MP.TaskMan
await ReloadData();
}
protected async Task DoMove(TaskListModel currRec, bool goUp)
protected async Task DoMove(TaskListTable.ActionParam action)
{
await TService.TaskListMove(currRec, goUp);
await TService.TaskListMove(action.CurrRec, action.GoUp);
detRecord = null;
currRecord = null;
await ReloadData();
}
protected async Task DoReset()
protected async Task DoReset(bool force)
{
detRecord = null;
currRecord = null;
await TService.FlushCache();
await TService.FlushCacheAsync();
await ReloadData();
}
@@ -208,14 +154,13 @@ namespace MP.TaskMan
{
detRecord = null;
currRecord = null;
DetailTaskId = null;
isLoading = true;
detRecord = selRec;
await ReloadData();
isLoading = false;
}
protected async Task ForceAll()
protected async Task ForceAll(bool force)
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Confermi esecuzione forzata di tutti i task?"))
return;
@@ -232,36 +177,17 @@ namespace MP.TaskMan
await ReloadData();
}
protected async Task ForceReload(int newNum)
{
numRecord = newNum;
await ReloadData();
}
protected async Task ForceReloadPage(int newNum)
{
currPage = newNum;
await ReloadData();
}
protected async Task ForceUpdate(bool doForce)
{
currRecord = null;
await ReloadData();
}
protected string iconCss(TaskListModel TaskRec)
{
return TaskRec.LastIsError ? "fa-thumbs-down" : "fa-thumbs-up";
}
protected override async Task OnInitializedAsync()
{
isLoading = true;
MaxVal = 2;
CleanupDir();
await advStep(1);
numRecord = 10;
await ReloadData();
await advStep(2);
isLoading = false;
@@ -269,7 +195,6 @@ namespace MP.TaskMan
protected void ResetData()
{
CleanupDir();
TService.rollBackEdit(currRecord);
currRecord = null;
}
@@ -284,35 +209,12 @@ namespace MP.TaskMan
return answ;
}
protected string TextReduce(string textOriginal, int maxChar)
{
string answ = textOriginal;
if (answ.Length > maxChar)
{
answ = $"{textOriginal.Substring(0, maxChar / 2)} ... {textOriginal.Substring(answ.Length - maxChar / 2)}";
}
return answ;
}
protected void ToggleDetail(TaskListModel TaskRec)
{
if (DetailTaskId == null)
{
DetailTaskId = TaskRec;
}
else
{
DetailTaskId = (DetailTaskId.TaskId == TaskRec.TaskId) ? null : TaskRec;
}
}
#endregion Protected Methods
#region Private Fields
private double currVal = 0;
private TaskListModel? DetailTaskId = null;
private List<TaskListModel> ListRecords = new List<TaskListModel>();
private Dictionary<int, List<TaskListModel>> ListRecords = new Dictionary<int, List<TaskListModel>>();
private int MaxVal = 10;
private double nextVal = 0;
private List<TaskListModel> SearchRecords = new List<TaskListModel>();
@@ -321,59 +223,27 @@ namespace MP.TaskMan
#region Private Properties
private int currPage { get; set; } = 1;
private TaskListModel? currRecord { get; set; } = null;
private TaskListModel? detRecord { get; set; } = null;
private int expTimeMsec { get; set; } = 30000;
private string fullPath
{
get => $"{Directory.GetCurrentDirectory()}\\temp\\{fileName}";
}
private bool isLoading { get; set; } = false;
private int numRecord { get; set; } = 10;
private string SearchVal { get; set; } = "";
private Task2ExeType typeSel { get; set; } = Task2ExeType.ND;
private Task2ExeType typeSel { get; set; } = Task2ExeType.ALL;
#endregion Private Properties
#region Private Methods
private string btnRunCss(DateTime dtNextExe)
{
DateTime adesso = DateTime.Now;
string answ = dtNextExe < adesso ? "btn-success" : "btn-warning";
return answ;
}
private async void CleanupDir()
{
var parentDir = Directory.GetParent(fullPath).FullName;
if (!Directory.Exists(parentDir))
{
Directory.CreateDirectory(parentDir);
}
await Task.Run(() => File.Delete(fullPath));
}
private async Task ExportCsv()
{
isLoading = true;
// salvo davvero!
await Egw.Core.Utils.SaveToCsv(SearchRecords, fullPath, ';');
isLoading = false;
}
private async Task ReloadData()
{
SearchRecords = await TService.TaskListAll(TypeSel, SearchVal);
totalCount = SearchRecords.Count;
var firstRec = SearchRecords.OrderBy(x => x.Ordinal).FirstOrDefault();
minOrdinal = firstRec != null ? firstRec.Ordinal : 0;
var lastRec = SearchRecords.OrderByDescending(x => x.Ordinal).FirstOrDefault();
maxOrdinal = lastRec != null ? lastRec.Ordinal : 9999;
ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList();
// suddivido per gruppo e genero relativo display raggruppato
ListRecords = SearchRecords
.OrderBy(x => x.Group)
.ThenBy(x => x.Ordinal)
.GroupBy(x => x.Group)
.ToDictionary(g => g.Key, g => g.ToList());
}
#endregion Private Methods
+138
View File
@@ -0,0 +1,138 @@
<div class="card shadow my-2">
<div class="card-header bg-primary bg-opacity-50 bg-gradient fs-5">
Gruppo Task: @CodGroup
</div>
<div class="card-body">
<table class="table table-sm table-striped">
<thead>
<tr>
<th>
<button class="btn btn-sm btn-info" @onclick="DoReset" title="Reset"><i class="fas fa-sync"></i></button>
</th>
<th>Ord</th>
<th>Task</th>
<th>Tipo</th>
@if (detRecord == null)
{
<th>Command</th>
}
<th>Sched.</th>
@if (detRecord == null)
{
<th class="text-end">Last</th>
<th class="text-end">Next</th>
<th class="text-end">Result</th>
<th>
<button class="btn btn-sm btn-danger me-1" @onclick="ForceAll" title="Force All"><i class="fas fa-play"></i></button>
</th>
}
</tr>
</thead>
<tbody>
@foreach (var record in ListRecords)
{
<tr class="@checkSelect(@record)">
<td class="text-nowrap">
<button class="btn btn-sm btn-info" @onclick="() => DoSelect(record)" title="Select"><i class="fas fa-search"></i></button>
@if (detRecord == null)
{
@if (currRecord == null)
{
<button class="btn btn-sm btn-primary ms-1" @onclick="() => DoEdit(record)" title="Edit"><i class="fas fa-pencil-alt"></i></button>
<button class="btn btn-sm btn-success" @onclick="() => DoClone(record)" title="Clona"><i class="fas fa-magic"></i></button>
}
else
{
<button class="btn btn-sm btn-secondary ms-1" @onclick="() => DoCancel()" title="Cancel"><i class="fas fa-undo"></i></button>
}
}
</td>
<td class="text-nowrap">
@if (detRecord == null)
{
@if (record.Ordinal == minOrdinal)
{
<button class="btn btn-sm btn-outline-secondary mx-1" disabled title="Cannot Move"><i class="fas fa-caret-up"></i></button>
}
else
{
<button class="btn btn-sm btn-outline-primary mx-1" @onclick="() => DoMove(record, true)" title="Move Up"><i class="fas fa-caret-up"></i></button>
}
}
<b>@record.Ordinal</b>
@if (detRecord == null)
{
@if (record.Ordinal == maxOrdinal)
{
<button class="btn btn-sm btn-outline-secondary mx-1" disabled title="Cannot Move"><i class="fas fa-caret-down"></i></button>
}
else
{
<button class="btn btn-sm btn-outline-primary mx-1" @onclick="() => DoMove(record, false)" title="Move Down"><i class="fas fa-caret-down"></i></button>
}
}
</td>
<td class="text-nowrap @checkDis(@record)">
<div>@record.Name</div>
<div class="small text-truncate">@record.Descript</div>
</td>
<td class="@checkDis(@record)">
@record.TType
</td>
@if (detRecord == null)
{
<td class="small text-truncate text-break @checkDis(@record)">
<div class="font-monospace fw-bold" title="@record.Command">@TextReduce(record.Command, 32)</div>
<div class="small text-break" title="@record.Args">@TextReduce(record.Args, 40)</div>
</td>
}
<td>@record.Freq &times; @record.Cad</td>
@if (detRecord == null)
{
<td class="text-end text-nowrap @checkDis(@record)">
<div>@($"{record.DtLastExec:yyyy-MM-dd}")</div>
<div class="small">@($"{record.DtLastExec:ddd HH:mm:ss}")</div>
</td>
<td class="text-end text-nowrap @checkDis(@record)">
<div>@($"{record.DtNextExec:yyyy-MM-dd}")</div>
<div class="small">@($"{record.DtNextExec:ddd HH:mm:ss}")</div>
</td>
<td class="text-end @checkDis(@record)">
<b>@($"{record.LastDuration:N3}")</b> <sub>sec</sub> <button class="btn btn-sm @btnCss(record)" @onclick="() => ToggleDetail(record)" title="Ultima esecuzione"><i class="far @iconCss(record)"></i></button>
</td>
<td>
@if (record.Enabled)
{
<button class="btn btn-sm @btnRunCss(record.DtNextExec) me-1" @onclick="() => DoRun(record)" title="Run Now"><i class="fas fa-play"></i></button>
}
else
{
<button class="btn btn-sm btn-secondary me-1" title="Disabled / Cannot run!" disabled><i class="fas fa-play"></i></button>
}
</td>
}
</tr>
@if (DetailTaskId != null && DetailTaskId.TaskId == record.TaskId)
{
<tr>
<td colspan="10 @checkDis(@record)">
<div class="d-flex justify-content-end">
<div class="p-1 small alert @alCss(record)">
<div class="text-trim">@record.LastResult</div>
</div>
</div>
</td>
</tr>
}
}
</tbody>
<tfoot>
<tr>
<td colspan="10">
<DataPager PageSize="numRecord" currPage="currPage" numRecordChanged="SetNumRec" numPageChanged="SetPage" totalCount="totalCount" />
</td>
</tr>
</tfoot>
</table>
</div>
</div>
+248
View File
@@ -0,0 +1,248 @@
using Microsoft.AspNetCore.Components;
using MP.TaskMan.Models;
using MP.TaskMan.Services;
using System.Threading.Tasks;
namespace MP.TaskMan
{
public partial class TaskListTable
{
#region Public Properties
[Parameter]
public int CodGroup { get; set; } = 0;
[Parameter]
public List<TaskListModel> AllRecords { get; set; } = new List<TaskListModel>();
[Parameter]
public EventCallback<bool> EC_Cancel { get; set; }
[Parameter]
public EventCallback<TaskListModel> EC_Clone { get; set; }
[Parameter]
public EventCallback<bool> EC_DoReset { get; set; }
[Parameter]
public EventCallback<TaskListModel> EC_Edit { get; set; }
[Parameter]
public EventCallback<bool> EC_ForceAll { get; set; }
[Parameter]
public EventCallback<ActionParam> EC_Move { get; set; }
[Parameter]
public EventCallback<TaskListModel> EC_Run { get; set; }
[Parameter]
public EventCallback<TaskListModel> EC_Select { get; set; }
#endregion Public Properties
#region Public Classes
public class ActionParam
{
#region Public Properties
public TaskListModel CurrRec { get; set; } = null!;
public bool GoUp { get; set; } = true;
#endregion Public Properties
}
#endregion Public Classes
#region Protected Properties
[Inject]
protected TaskService TService { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
protected string alCss(TaskListModel TaskRec)
{
return TaskRec.LastIsError ? "alert-danger" : "alert-success";
}
protected string btnCss(TaskListModel TaskRec)
{
string answ = DetailTaskId != null && DetailTaskId.TaskId == TaskRec.TaskId ? "btn-" : "btn-outline-";
answ += TaskRec.LastIsError ? "danger" : "success";
return answ;
}
protected string checkDis(TaskListModel selRec)
{
string answ = "";
// verifico se sia disabilitato...
if (!selRec.Enabled)
{
answ += " text-secondary text-opacity-75 textStriked";
}
return answ;
}
protected string checkSelect(TaskListModel selRec)
{
string answ = "";
if (currRecord != null)
{
answ = (currRecord.Equals(selRec)) ? "table-info" : "";
}
else if (detRecord != null)
{
answ = detRecord.Equals(selRec) ? "table-info" : "";
}
#if false
// verifico se sia disabilitato...
if (!selRec.Enabled)
{
answ += " text-secondary text-opacity-50 textStriked";
}
#endif
return answ;
}
protected async Task DoCancel()
{
await EC_Cancel.InvokeAsync(true);
}
protected async Task DoClone(TaskListModel currRec)
{
await EC_Clone.InvokeAsync(currRec);
}
protected async Task DoEdit(TaskListModel currRec)
{
await EC_Edit.InvokeAsync(currRec);
}
protected async Task DoMove(TaskListModel currRec, bool goUp)
{
ActionParam retVal = new ActionParam()
{
CurrRec = currRec,
GoUp = goUp
};
await EC_Move.InvokeAsync(retVal);
}
protected async Task DoReset()
{
detRecord = null;
DetailTaskId = null;
await EC_DoReset.InvokeAsync(true);
}
protected async Task DoRun(TaskListModel currRec)
{
await EC_Run.InvokeAsync(currRec);
}
protected async Task DoSelect(TaskListModel currRec)
{
detRecord = currRec;
DetailTaskId = null;
await EC_Select.InvokeAsync(currRec);
}
protected async Task ForceAll()
{
await EC_ForceAll.InvokeAsync(true);
}
protected string iconCss(TaskListModel TaskRec)
{
return TaskRec.LastIsError ? "fa-thumbs-down" : "fa-thumbs-up";
}
protected override void OnParametersSet()
{
ReloadData();
}
protected void SetNumRec(int newNum)
{
numRecord = newNum;
ReloadData();
}
protected void SetPage(int newNum)
{
currPage = newNum;
ReloadData();
}
protected string TextReduce(string textOriginal, int maxChar)
{
string answ = textOriginal;
if (answ.Length > maxChar)
{
answ = $"{textOriginal.Substring(0, maxChar / 2)} ... {textOriginal.Substring(answ.Length - maxChar / 2)}";
}
return answ;
}
protected void ToggleDetail(TaskListModel TaskRec)
{
if (DetailTaskId == null)
{
DetailTaskId = TaskRec;
}
else
{
DetailTaskId = (DetailTaskId.TaskId == TaskRec.TaskId) ? null : TaskRec;
}
}
#endregion Protected Methods
#region Private Fields
private int currPage = 1;
private TaskListModel? DetailTaskId = null;
private bool isLoading = false;
private List<TaskListModel> ListRecords = new List<TaskListModel>();
private int maxOrdinal = 999;
private int minOrdinal = 0;
private int numRecord = 5;
private int totalCount = 0;
#endregion Private Fields
#region Private Properties
private TaskListModel? currRecord { get; set; } = null;
private TaskListModel? detRecord { get; set; } = null;
#endregion Private Properties
#region Private Methods
private string btnRunCss(DateTime dtNextExe)
{
DateTime adesso = DateTime.Now;
string answ = dtNextExe < adesso ? "btn-success" : "btn-warning";
return answ;
}
private void ReloadData()
{
totalCount = AllRecords.Count;
var firstRec = AllRecords.OrderBy(x => x.Ordinal).FirstOrDefault();
minOrdinal = firstRec != null ? firstRec.Ordinal : 0;
var lastRec = AllRecords.OrderByDescending(x => x.Ordinal).FirstOrDefault();
maxOrdinal = lastRec != null ? lastRec.Ordinal : 9999;
ListRecords = AllRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList();
}
#endregion Private Methods
}
}