Files
gwms/GWMS.UI/Components/ParamSendEditor.razor.cs
Samuele Locatelli 4fda312aac Avanzamento telemetria:
- altri metodi tracciati
- modifica json x prod
- aggiunta Async vari
2026-03-03 18:57:46 +01:00

169 lines
4.1 KiB
C#

using GWMS.Data.DatabaseModels;
using GWMS.UI.Data;
using Microsoft.AspNetCore.Components;
using NLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace GWMS.UI.Components
{
public partial class ParamSendEditor
{
#region Private Fields
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
#endregion Private Fields
#region Protected Fields
protected string _paramUid = "";
protected int _plantId = 0;
protected ParamSendModel currRecord;
#endregion Protected Fields
#region Protected Properties
[Inject]
protected GWMSDataService DataService { get; set; }
#endregion Protected Properties
#region Public Properties
[Parameter]
public EventCallback<int> DataUpdated { get; set; }
public bool IsEnabled
{
get
{
return currRecord.enabled;
}
set
{
currRecord.enabled = value;
bool paramSent = false;
// salvo!
var pUpd = Task.Run(async () =>
{
await DataService.ParamSendUpdateAsync(currRecord);
// se viene abilitato --> verifico comunque invio
if (value)
{
// test set parametri + invio...
await DataService.ParamsSendCheckAsync();
paramSent = true;
}
await ReloadData();
if (paramSent)
{
await DataUpdated.InvokeAsync(0);
}
});
pUpd.Wait();
}
}
[Parameter]
public string ParamUidSel
{
get
{
return _paramUid;
}
set
{
_paramUid = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
[Parameter]
public int PlantIdSel
{
get
{
return _plantId;
}
set
{
_plantId = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
public int SendWindEnd
{
get
{
return currRecord.windEnd;
}
set
{
currRecord.windEnd = value;
// salvo!
var pUpd = Task.Run(async () =>
{
await DataService.ParamSendUpdateAsync(currRecord);
await ReloadData();
});
pUpd.Wait();
}
}
public int SendWindStart
{
get
{
return currRecord.windStart;
}
set
{
currRecord.windStart = value;
// salvo!
var pUpd = Task.Run(async () =>
{
await DataService.ParamSendUpdateAsync(currRecord);
await ReloadData();
});
pUpd.Wait();
}
}
#endregion Public Properties
#region Private Methods
private async Task ReloadData()
{
currRecord = null;
try
{
currRecord = await DataService.ParamSendGetAsync(PlantIdSel, ParamUidSel);
}
catch (Exception exc)
{
Log.Error($"Eccezione in ReloadData:{Environment.NewLine}{exc}");
}
}
#endregion Private Methods
#region Protected Methods
protected override async Task OnInitializedAsync()
{
await ReloadData();
}
#endregion Protected Methods
}
}