Files
mapo-core/MP.Land/Pages/ConfSync.razor.cs
T
2024-07-19 11:04:18 +02:00

215 lines
6.1 KiB
C#

using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Configuration;
using MP.AppAuth;
using MP.AppAuth.Models;
using MP.Land.Data;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace MP.Land.Pages
{
public partial class ConfSync : IDisposable
{
#region Public Methods
public void Dispose()
{
listAnagKeyValLoc = null;
listConfigLoc = null;
listVocabolarioLoc = null;
listAnagKeyValRem = null;
listConfigRem = null;
listVocabolarioRem = null;
GC.Collect();
}
#endregion Public Methods
#region Protected Fields
protected int numDone = 0;
protected int numTot = 0;
protected double TotalMb = 0;
protected UpdateMan updateManAuth = new UpdateMan("SWDownloader", "viaD@nte16");
#endregion Protected Fields
#region Protected Properties
protected List<AnagKeyValueModel> AKVList
{
get
{
return SyncServ.AKVList;
}
set
{
SyncServ.AKVList = value;
}
}
[Inject]
protected MessageService AppMService { get; set; }
[Inject]
protected IConfiguration Configuration { get; set; }
[Inject]
protected AppAuthService DataService { get; set; }
protected bool isLoadingLoc { get; set; } = false;
protected bool isLoadingRem { get; set; } = false;
[Inject]
protected LicenseService LicServ { get; set; } = null!;
protected bool showUpdate { get; set; } = false;
[Inject]
protected SyncService SyncServ { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
protected string localPath(string localRepo)
{
return @$"{Configuration["ServerConf:downloadPath"]}\{localRepo}\{Configuration["appVers"]}"; ;
}
protected override async Task OnInitializedAsync()
{
AppMService.ShowSearch = false;
AppMService.PageName = "Config Sync";
AppMService.PageIcon = "fas fa-file-import pr-2";
await RefreshData();
}
/// <summary>
/// Cicla su tutti i record ed effettua il download
/// </summary>
protected async Task RefreshData()
{
// init progress...
showUpdate = true;
CompType = "";
numDone = 0;
numTot = 3;
await fixAKV();
numDone++;
await InvokeAsync(StateHasChanged);
await ReloadDataLoc();
numDone++;
await InvokeAsync(StateHasChanged);
await ReloadDataRem();
numDone++;
await InvokeAsync(StateHasChanged);
await Task.Delay(500);
showUpdate = false;
await InvokeAsync(StateHasChanged);
}
protected void doClose()
{
CompType = "";
}
protected bool showDetail(string valReq)
{
return !string.IsNullOrEmpty(CompType) && CompType.Equals(valReq);
}
protected async Task ReloadDataLoc()
{
isLoadingLoc = true;
await InvokeAsync(StateHasChanged);
await Task.Delay(tDelay);
listAnagKeyValLoc = await DataService.AnagKeyValList();
await Task.Delay(tDelay);
listConfigLoc = await DataService.ConfigList();
await Task.Delay(tDelay);
listVocabolarioLoc = await DataService.VocabolarioList();
isLoadingLoc = false;
}
protected async Task ReloadDataRem()
{
isLoadingRem = true;
await InvokeAsync(StateHasChanged);
await Task.Delay(tDelay);
listAnagKeyValRem = await SyncServ.OnlineListAnagKeyVal();
await Task.Delay(tDelay);
listConfigRem = await SyncServ.OnlineListConfig();
await Task.Delay(tDelay);
listVocabolarioRem = await SyncServ.OnlineListVocabolario();
isLoadingRem = false;
}
#endregion Protected Methods
#region Private Fields
private int tDelay = 250;
#endregion Private Fields
#region Private Properties
private List<AnagKeyValueModel> listAnagKeyValLoc { get; set; } = new List<AnagKeyValueModel>();
private List<AnagKeyValueModel> listAnagKeyValRem { get; set; } = new List<AnagKeyValueModel>();
private List<ConfigModel> listConfigLoc { get; set; } = new List<ConfigModel>();
private List<ConfigModel> listConfigRem { get; set; } = new List<ConfigModel>();
private List<VocabolarioModel> listVocabolarioLoc { get; set; } = new List<VocabolarioModel>();
private List<VocabolarioModel> listVocabolarioRem { get; set; } = new List<VocabolarioModel>();
#endregion Private Properties
#region Private Methods
private async Task fixAKV()
{
// check init AKV
if (AKVList == null || AKVList.Count == 0)
{
AKVList = await DataService.AnagKeyValList();
SyncServ.InitAkv();
}
}
#if false
private async Task<long> scaricaSingolo(UpdMan item)
{
long size = 0;
if (item.IsAuth)
{
size = updateManAuth.downloadLatest(item.ManifestUrl, localPath(item.LocalRepo), item.PackName);
}
else
{
size = UpdateMan.obj.downloadLatest(item.ManifestUrl, localPath(item.LocalRepo), item.PackName);
}
numDone++;
percLoading = 100 * numDone / numTot;
return await Task.FromResult(size);
}
#endif
#endregion Private Methods
protected async Task DoCompare(string compType)
{
CompType = compType;
await InvokeAsync(StateHasChanged);
}
private string CompType = "";
}
}