From d8c8d8dbb9e01544335d5a442e91d17910f4f6c2 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 15 Oct 2024 18:52:28 +0200 Subject: [PATCH 1/5] SPEC - fix review stats ODL con modulo - completata ottimizzazione componente display files --- MP.Data/MP.Data.csproj | 6 +- MP.SPEC/Components/ListODL.razor | 113 +---------------- MP.SPEC/Components/ListODL.razor.cs | 154 ++-------------------- MP.SPEC/Components/ODLPlot.razor.cs | 1 - MP.SPEC/Components/StatsOdl.razor | 110 ++++++++++++++++ MP.SPEC/Components/StatsOdl.razor.cs | 183 +++++++++++++++++++++++++++ MP.SPEC/MP.SPEC.csproj | 8 +- MP.SPEC/Resources/ChangeLog.html | 2 +- MP.SPEC/Resources/VersNum.txt | 2 +- MP.SPEC/Resources/manifest.xml | 2 +- 10 files changed, 314 insertions(+), 267 deletions(-) create mode 100644 MP.SPEC/Components/StatsOdl.razor create mode 100644 MP.SPEC/Components/StatsOdl.razor.cs diff --git a/MP.Data/MP.Data.csproj b/MP.Data/MP.Data.csproj index 247dff73..8115b184 100644 --- a/MP.Data/MP.Data.csproj +++ b/MP.Data/MP.Data.csproj @@ -20,7 +20,7 @@ - + @@ -33,7 +33,7 @@ - - + + \ No newline at end of file diff --git a/MP.SPEC/Components/ListODL.razor b/MP.SPEC/Components/ListODL.razor index 94945c58..1c031d67 100644 --- a/MP.SPEC/Components/ListODL.razor +++ b/MP.SPEC/Components/ListODL.razor @@ -199,123 +199,12 @@ else - @if (showUpdate) {
- -
-
+ +
+
@outMessages
-
+
@if (showProgress) {
diff --git a/MP.Land/Pages/UpdateManager.razor.cs b/MP.Land/Pages/UpdateManager.razor.cs index 535798a2..ae02e862 100644 --- a/MP.Land/Pages/UpdateManager.razor.cs +++ b/MP.Land/Pages/UpdateManager.razor.cs @@ -1,11 +1,15 @@ -using Microsoft.AspNetCore.Components; +using ICSharpCode.SharpZipLib.Zip; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using MP.AppAuth; using MP.Land.Data; using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Linq; +using System.Reflection; using System.Threading.Tasks; namespace MP.Land.Pages @@ -30,7 +34,7 @@ namespace MP.Land.Pages protected int totalCount = 0; - protected double TotalMb = 0; + protected long TotalMb = 0; protected UpdateMan updateManAuth = new UpdateMan("SWDownloader", "viaD@nte16"); @@ -59,6 +63,21 @@ namespace MP.Land.Pages #region Protected Methods + /// + /// Restituisce size calcolata + /// + /// + /// + protected string CalcSize(long origSize) + { + return MeasureUtils.SizeSuffix(origSize, 1); + } + + protected void CloseProgUpdate() + { + showUpdate = false; + } + /// /// Cicla su tutti i record ed effettua il download /// @@ -68,7 +87,7 @@ namespace MP.Land.Pages showProgress = true; showUpdate = true; outMessages = $"Iniziato download per {numTot} packages"; - StateHasChanged(); + await InvokeAsync(StateHasChanged); percLoading = 0; TotalMb = 0; numDone = 0; @@ -90,20 +109,16 @@ namespace MP.Land.Pages numTot = authList.Count; foreach (var item in authList) { - long size = 0; - size = await scaricaSingolo(item); - TotalMb += (double)size / (1024 * 1024); - outMessages = $"Scaricati {numDone}/{numTot} packages | {TotalMb:N2} Mb"; - StateHasChanged(); - await Task.Delay(1); + ScaricaSingolo(item); + await InvokeAsync(StateHasChanged); } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - outMessages = $"Effettuato download di {numDone} update | {TotalMb:N2} Mb in {ts.TotalSeconds:N2} s"; - StateHasChanged(); + outMessages = $"Effettuato download di {numDone} update | {CalcSize(TotalMb)} in {ts.TotalSeconds:N2} s"; + await InvokeAsync(StateHasChanged); await Task.Delay(1000); showProgress = false; - StateHasChanged(); + await InvokeAsync(StateHasChanged); } protected string localPath(string localRepo) @@ -130,6 +145,64 @@ namespace MP.Land.Pages await Task.Delay(1); } + /// + /// Cicla su tutti i record applicativi, crea ZIP cifrato + upload su LiMan + /// + protected async Task UploadBackupConfig() + { + // init progress... + showProgress = true; + showUpdate = true; + outMessages = $"Inizio preparazione per upload configurazioni di {numTot} packages"; + await InvokeAsync(StateHasChanged); + percLoading = 0; + TotalMb = 0; + numDone = 0; + int numIOB = 0; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + // ciclo su tutti quelli con licenza valida... + List rawList = ListRecords + .Where(x => !string.IsNullOrEmpty(x.LicenseKey)).ToList(); + List authList = new List(); + + // ciclo SOLO tra quelli davvero autorizzati... + foreach (var item in rawList) + { + if (LicServ.checkLicenseActive(item.LicenseKey)) + { + authList.Add(item); + } + } + // numero app + IOB + ZIP + numTot = authList.Count + 2; + + // recupero conf files + foreach (var item in authList) + { + // cerco i file di conf e li copio + RecuperaConf(item); + await Task.Delay(10); + await InvokeAsync(StateHasChanged); + } + // recupero i file IOB + RecuperaIobConf(); + + // ora creo il file zip + await PrepareZip(); + // effettuo upload + await UploadZip(); + + // concludo! + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + outMessages = $"Effettuato Upload backup configurazioni per {numDone} app + {numIOB} IOB | {CalcSize(TotalMb)} | {ts.TotalSeconds:N2} s"; + await InvokeAsync(StateHasChanged); + await Task.Delay(1000); + showProgress = false; + await InvokeAsync(StateHasChanged); + } + #endregion Protected Methods #region Private Fields @@ -138,9 +211,223 @@ namespace MP.Land.Pages #endregion Private Fields + #region Private Properties +#if DEBUG + private DirectoryInfo AppDir => new DirectoryInfo(Path.Combine("\\\\iis01.egalware.com", "c$\\inetpub\\wwwroot\\MP\\LAND")); +#else + private DirectoryInfo AppDir => new DirectoryInfo(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)); +#endif + + #endregion Private Properties + #region Private Methods - private async Task scaricaSingolo(AppAuth.Models.UpdMan item) + /// + /// Preparazione ZIP con password = AuthKey + /// + private async Task PrepareZip() + { + string srcPath = Path.Combine(AppDir.FullName, "temp", "orig"); + string destPath = Path.Combine(AppDir.FullName, "temp", "zip"); + if(!Directory.Exists(destPath)) + { + Directory.CreateDirectory(destPath); + } + string zFile = Path.Combine(AppDir.FullName, "temp", "zip", "MAPO.zip"); + +#if false + ZipDirectory(folderName, zFile, 9); + await Task.Delay(1); + +#endif + using (ZipFile zipFile = ZipFile.Create(zFile)) + { + zipFile.BeginUpdate(); + addFolderToZip(zipFile, srcPath, srcPath); + zipFile.CommitUpdate(); + zipFile.Close(); + } + + + } + + public void addFolderToZip(ZipFile f, string root, string folder) + { + + string relative = folder.Substring(root.Length); + if (relative.Length > 0) + { + f.AddDirectory(relative); + } + + foreach (string file in Directory.GetFiles(folder)) + { + relative = file.Substring(root.Length); + f.Add(file, relative); + } + + foreach (string subFolder in Directory.GetDirectories(folder)) + { + this.addFolderToZip(f, root, subFolder); + } + } + + /// + /// Method that compress all the files inside a folder (non-recursive) into a zip file. + /// + /// + /// + /// + private void ZipDirectory(string DirectoryPath, string OutputFilePath, int CompressionLevel = 9) + { + try + { + // Depending on the directory this could be very large and would require more attention + // in a commercial package. + string[] filenames = Directory.GetFiles(DirectoryPath); + + // 'using' statements guarantee the stream is closed properly which is a big source + // of problems otherwise. Its exception safe as well which is great. + using (ZipOutputStream OutputStream = new ZipOutputStream(File.Create(OutputFilePath))) + { + + // Define the compression level + // 0 - store only to 9 - means best compression + OutputStream.SetLevel(CompressionLevel); + + byte[] buffer = new byte[4096]; + + foreach (string file in filenames) + { + + // Using GetFileName makes the result compatible with XP + // as the resulting path is not absolute. + ZipEntry entry = new ZipEntry(Path.GetFileName(file)); + + // Setup the entry data as required. + + // Crc and size are handled by the library for seakable streams + // so no need to do them here. + + // Could also use the last write time or similar for the file. + entry.DateTime = DateTime.Now; + OutputStream.PutNextEntry(entry); + + using (FileStream fs = File.OpenRead(file)) + { + + // Using a fixed size buffer here makes no noticeable difference for output + // but keeps a lid on memory usage. + int sourceBytes; + + do + { + sourceBytes = fs.Read(buffer, 0, buffer.Length); + OutputStream.Write(buffer, 0, sourceBytes); + } while (sourceBytes > 0); + } + } + + // Finish/Close arent needed strictly as the using statement does this automatically + + // Finish is important to ensure trailing information for a Zip file is appended. Without this + // the created file would be invalid. + OutputStream.Finish(); + + // Close is important to wrap things up and unlock the file. + OutputStream.Close(); + + Console.WriteLine("Files successfully compressed"); + } + } + catch (Exception ex) + { + // No need to rethrow the exception as for our purposes its handled. + Console.WriteLine("Exception during processing {0}", ex); + } + } + + /// + /// Recupera fdile di conf da app indicata + /// + /// + private void RecuperaConf(AppAuth.Models.UpdMan item) + { + long size = 0; + if (item.IsAuth) + { + string dstDir = Path.Combine(AppDir.FullName, "temp", "orig", item.PackName); + if (!Directory.Exists(dstDir)) + { + Directory.CreateDirectory(dstDir); + } + string srcDir = Path.Combine(AppDir.Parent.FullName, item.PackName); + // recupero elenco files tipo appsettings*.json + if (Directory.Exists(srcDir)) + { + var dirInfo = new DirectoryInfo(srcDir); + // recupero files CORE + List fileList = dirInfo.GetFiles("appsettings*.json").ToList(); + // recupero files Framework + List fileListFram = dirInfo.GetFiles("web*.config").ToList(); + // merge... + foreach (var fileFrm in fileListFram) + { + fileList.Add(fileFrm); + } + // procedo! + foreach (var file in fileList) + { + string fileDestPath = Path.Combine(dstDir, file.Name); + file.CopyTo(fileDestPath, true); + size += file.Length; + } + numDone++; + percLoading = 100 * numDone / numTot; + TotalMb += size; + outMessages = $"Configurazioni preparate: {numDone}/{numTot} | {CalcSize(TotalMb)}"; + } + } + } + + /// + /// recupera tutte le conf IOB trasferite all'MP-IO dai vari IOB-WIN + /// + private void RecuperaIobConf() + { + long size = 0; + + string dstDir = Path.Combine(AppDir.FullName, "temp", "orig", "IOB"); + if (!Directory.Exists(dstDir)) + { + Directory.CreateDirectory(dstDir); + } + string srcIobDir = Path.Combine(AppDir.Parent.FullName, "IO", "fileUpload"); + // recupero elenco files tipo appsettings*.json + if (Directory.Exists(srcIobDir)) + { + var dirInfo = new DirectoryInfo(srcIobDir); + // recupero files CORE + List fileList = dirInfo.GetFiles().ToList(); + // procedo! + foreach (var file in fileList) + { + string fileDestPath = Path.Combine(dstDir, file.Name); + file.CopyTo(fileDestPath, true); + size += file.Length; + } + numDone++; + percLoading = 100 * numDone / numTot; + TotalMb += size; + outMessages = $"Configurazioni preparate: {numDone}/{numTot} | {CalcSize(TotalMb)}"; + } + } + + /// + /// Effettua download di una singola app + /// + /// + private void ScaricaSingolo(AppAuth.Models.UpdMan item) { long size = 0; if (item.IsAuth) @@ -153,9 +440,22 @@ namespace MP.Land.Pages } numDone++; percLoading = 100 * numDone / numTot; - return await Task.FromResult(size); + TotalMb += size; + outMessages = $"Scaricati {numDone}/{numTot} packages | {CalcSize(TotalMb)}"; + } + + /// + /// Invio zip al server LiMan remoto + /// + /// + /// + private async Task UploadZip() + { + await Task.Delay(200); } #endregion Private Methods + + } } \ No newline at end of file diff --git a/MP.Land/Resources/ChangeLog.html b/MP.Land/Resources/ChangeLog.html index e51289da..df8df407 100644 --- a/MP.Land/Resources/ChangeLog.html +++ b/MP.Land/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo Tablet MAPO - DotNet6 -

Versione: 6.16.2409.1212

+

Versione: 6.16.2410.1718


Note di rilascio:
    diff --git a/MP.Land/Resources/VersNum.txt b/MP.Land/Resources/VersNum.txt index aa071951..23fe602d 100644 --- a/MP.Land/Resources/VersNum.txt +++ b/MP.Land/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2409.1212 +6.16.2410.1718 diff --git a/MP.Land/Resources/manifest.xml b/MP.Land/Resources/manifest.xml index c61f05d5..069822ec 100644 --- a/MP.Land/Resources/manifest.xml +++ b/MP.Land/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2409.1212 + 6.16.2410.1718 https://nexus.steamware.net/repository/SWS/MP-LAND/stable/LAST/MP.Land.zip https://nexus.steamware.net/repository/SWS/MP-LAND/stable/LAST/ChangeLog.html false diff --git a/MP.Land/temp/.placeholder b/MP.Land/temp/.placeholder new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/MP.Land/temp/.placeholder @@ -0,0 +1 @@ + \ No newline at end of file From 7d2dd683445a7fd545a568d41d2fdcf9bd880339 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 17 Oct 2024 19:42:07 +0200 Subject: [PATCH 3/5] Reorg codice --- MP.Land/Data/SyncService.cs | 97 +++++++++++++++++++++----------- MP.Land/MP.Land.csproj | 2 +- MP.Land/Resources/ChangeLog.html | 2 +- MP.Land/Resources/VersNum.txt | 2 +- MP.Land/Resources/manifest.xml | 2 +- 5 files changed, 67 insertions(+), 38 deletions(-) diff --git a/MP.Land/Data/SyncService.cs b/MP.Land/Data/SyncService.cs index aa22bf70..93b379cd 100644 --- a/MP.Land/Data/SyncService.cs +++ b/MP.Land/Data/SyncService.cs @@ -15,6 +15,8 @@ namespace MP.Land.Data { public class SyncService { + #region Public Constructors + /// /// Init classe /// @@ -26,13 +28,26 @@ namespace MP.Land.Data _configuration = configuration; } - private static ILogger _logger { get; set; } = null!; - private static IConfiguration? _configuration; + #endregion Public Constructors + + #region Public Properties + + public List AKVList { get; set; } = new List(); + public string Applicazione { get; set; } = ""; /// - /// URL dell'API x chiamate gestione licenze + /// Codice cliente/installazione /// - private static string apiUrl = "https://liman.egalware.com/ELM.API/"; + public string Installazione { get; set; } = ""; + + /// + /// Master key licenza principale + /// + public string MasterKey { get; set; } = ""; + + #endregion Public Properties + + #region Public Methods /// /// Stato server gestione licenze @@ -55,30 +70,7 @@ namespace MP.Land.Data } return await Task.FromResult(answ); } - public List AKVList { get; set; } = new List(); - public string Applicazione { get; set; } = ""; - /// - /// Codice cliente/installazione - /// - public string Installazione { get; set; } = ""; - /// - /// Cerca di recuperare valore string da elenco AKV - /// - /// Chiave AKV richiesta - /// - protected string getAVKStr(string varReq) - { - string answ = ""; - if (AKVList != null && AKVList.Count > 0) - { - var currRec = AKVList.Where(x => x.NomeVar == varReq).FirstOrDefault(); - if (currRec != null) - { - answ = $"{currRec.ValString}"; - } - } - return answ; - } + /// /// Init della classe con variabili di base da Redis/DB /// @@ -92,11 +84,6 @@ namespace MP.Land.Data return fatto; } - /// - /// Master key licenza principale - /// - public string MasterKey { get; set; } = ""; - /// /// Lista record AnagKeyVal /// @@ -159,5 +146,47 @@ namespace MP.Land.Data } return await Task.FromResult(answ); } + + #endregion Public Methods + + #region Protected Methods + + /// + /// Cerca di recuperare valore string da elenco AKV + /// + /// Chiave AKV richiesta + /// + protected string getAVKStr(string varReq) + { + string answ = ""; + if (AKVList != null && AKVList.Count > 0) + { + var currRec = AKVList.Where(x => x.NomeVar == varReq).FirstOrDefault(); + if (currRec != null) + { + answ = $"{currRec.ValString}"; + } + } + return answ; + } + + #endregion Protected Methods + + #region Private Fields + + private static IConfiguration? _configuration; + + /// + /// URL dell'API x chiamate gestione licenze + /// + private static string apiUrl = "https://liman.egalware.com/ELM.API/"; + + #endregion Private Fields + + #region Private Properties + + private static ILogger _logger { get; set; } = null!; + + #endregion Private Properties } -} +} \ No newline at end of file diff --git a/MP.Land/MP.Land.csproj b/MP.Land/MP.Land.csproj index 52c18337..718c9b27 100644 --- a/MP.Land/MP.Land.csproj +++ b/MP.Land/MP.Land.csproj @@ -3,7 +3,7 @@ net6.0 MP.Land - 6.16.2410.1718 + 6.16.2410.1719 diff --git a/MP.Land/Resources/ChangeLog.html b/MP.Land/Resources/ChangeLog.html index df8df407..99342e44 100644 --- a/MP.Land/Resources/ChangeLog.html +++ b/MP.Land/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo Tablet MAPO - DotNet6 -

    Versione: 6.16.2410.1718

    +

    Versione: 6.16.2410.1719


    Note di rilascio:
      diff --git a/MP.Land/Resources/VersNum.txt b/MP.Land/Resources/VersNum.txt index 23fe602d..8021a159 100644 --- a/MP.Land/Resources/VersNum.txt +++ b/MP.Land/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2410.1718 +6.16.2410.1719 diff --git a/MP.Land/Resources/manifest.xml b/MP.Land/Resources/manifest.xml index 069822ec..c50f8022 100644 --- a/MP.Land/Resources/manifest.xml +++ b/MP.Land/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2410.1718 + 6.16.2410.1719 https://nexus.steamware.net/repository/SWS/MP-LAND/stable/LAST/MP.Land.zip https://nexus.steamware.net/repository/SWS/MP-LAND/stable/LAST/ChangeLog.html false From 76708b49fb0325f2b549b9d2ec0468b5d98dfcaa Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 18 Oct 2024 15:10:29 +0200 Subject: [PATCH 4/5] LAND: - ok spedizione ZIP - ok password zip - ok test in DEV --- MP.AppAuth/DTO/UploadResult.cs | 17 +++ MP.Land/Data/SyncService.cs | 80 +++++++++-- MP.Land/MP.Land.csproj | 2 +- MP.Land/Pages/About.razor | 4 - MP.Land/Pages/About.razor.cs | 10 ++ MP.Land/Pages/UpdateManager.razor.cs | 207 ++++++++++++--------------- MP.Land/Resources/ChangeLog.html | 2 +- MP.Land/Resources/VersNum.txt | 2 +- MP.Land/Resources/manifest.xml | 2 +- 9 files changed, 193 insertions(+), 133 deletions(-) create mode 100644 MP.AppAuth/DTO/UploadResult.cs diff --git a/MP.AppAuth/DTO/UploadResult.cs b/MP.AppAuth/DTO/UploadResult.cs new file mode 100644 index 00000000..b025ccb3 --- /dev/null +++ b/MP.AppAuth/DTO/UploadResult.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MP.AppAuth.DTO +{ + + public class UploadResult + { + public bool Uploaded { get; set; } + public string FileName { get; set; } = ""; + public string StoredFileName { get; set; } = ""; + public int ErrorCode { get; set; } + } +} diff --git a/MP.Land/Data/SyncService.cs b/MP.Land/Data/SyncService.cs index 93b379cd..a8417301 100644 --- a/MP.Land/Data/SyncService.cs +++ b/MP.Land/Data/SyncService.cs @@ -2,13 +2,18 @@ using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using MP.AppAuth.DTO; using MP.AppAuth.Models; using Newtonsoft.Json; +using NLog; using RestSharp; +using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading.Tasks; using System.Web; +using static Egw.Core.LiManObj; using static System.Net.Mime.MediaTypeNames; namespace MP.Land.Data @@ -21,10 +26,8 @@ namespace MP.Land.Data /// Init classe ///
    /// - /// - public SyncService(IConfiguration configuration, ILogger logger) + public SyncService(IConfiguration configuration) { - _logger = logger; _configuration = configuration; } @@ -147,6 +150,55 @@ namespace MP.Land.Data return await Task.FromResult(answ); } + /// + /// Invio file zip di backup al server centrale + /// + /// Cod Applicazione + /// CLiente / Installazione + /// Invia richiesta UnZip + /// Invia richiesta Approvazione + /// ZipFile da inviare + /// + public async Task SendZipFile(string CodApp, string CodInst, bool DoUnzip, bool ForceApprov, FileInfo ZipFile) + { + bool answ = false; + try + { + // client chiamate rest + var client = new RestClient(restOptStd); + // Chiamo il metodo! + var actReq = new RestRequest($"/api/filesave/zipbackup", Method.Post); + actReq.AddParameter("CodApp", $"{CodApp}"); + actReq.AddParameter("CodInst", $"{CodInst}"); + actReq.AddParameter("DoUnzip", $"{DoUnzip}"); + actReq.AddParameter("ForceApprov", $"{ForceApprov}"); + actReq.AddFile("ZipFile", ZipFile.FullName); + actReq.AddHeader("Content-Type", "multipart/form-data"); + // effettuo vera chiamata + var currResp = await client.ExecuteAsync(actReq); + if (currResp.StatusCode == System.Net.HttpStatusCode.OK && currResp.Content != null) + { + // mi restituisce esito upload + var currList = JsonConvert.DeserializeObject>(currResp.Content); + if (currList != null) + { + // se contiene anche la richiesta è ok... + var recUpd = currList.FirstOrDefault(x => x.FileName == ZipFile.Name); + if (recUpd != null) + { + answ = recUpd.Uploaded; + } + } + } + } + catch (Exception exc) + { + Log.Error($"Eccezione in fase gestione REST services SendZipFile{Environment.NewLine}{exc}"); + } + + return answ; + } + #endregion Public Methods #region Protected Methods @@ -179,14 +231,24 @@ namespace MP.Land.Data /// /// URL dell'API x chiamate gestione licenze /// +#if DEBUG + private static string apiUrl = "https://localhost:5003/"; +#else private static string apiUrl = "https://liman.egalware.com/ELM.API/"; +#endif + + /// + /// Classe logger + /// + private static Logger Log = LogManager.GetCurrentClassLogger(); + + /// + /// Conf client RestSharp standard: + /// - base URI al sito + /// - timeout 1 min + /// + private static RestClientOptions restOptStd = new RestClientOptions { Timeout = TimeSpan.FromSeconds(60), BaseUrl = new Uri(apiUrl) }; #endregion Private Fields - - #region Private Properties - - private static ILogger _logger { get; set; } = null!; - - #endregion Private Properties } } \ No newline at end of file diff --git a/MP.Land/MP.Land.csproj b/MP.Land/MP.Land.csproj index 718c9b27..7963d028 100644 --- a/MP.Land/MP.Land.csproj +++ b/MP.Land/MP.Land.csproj @@ -3,7 +3,7 @@ net6.0 MP.Land - 6.16.2410.1719 + 6.16.2410.1815 diff --git a/MP.Land/Pages/About.razor b/MP.Land/Pages/About.razor index ffa93c15..1dc4795c 100644 --- a/MP.Land/Pages/About.razor +++ b/MP.Land/Pages/About.razor @@ -1,8 +1,4 @@ @page "/About" -@using MP.Land.Data - -@inject MessageService AppMService -@inject LicenseService LicServ
    diff --git a/MP.Land/Pages/About.razor.cs b/MP.Land/Pages/About.razor.cs index be225631..c18f570c 100644 --- a/MP.Land/Pages/About.razor.cs +++ b/MP.Land/Pages/About.razor.cs @@ -1,11 +1,21 @@ +using Microsoft.AspNetCore.Components; +using MP.Land.Data; using NLog; using System; +using System.Net.NetworkInformation; using System.Threading.Tasks; namespace MP.Land.Pages { public partial class About { + + + + [Inject] + protected MessageService AppMService { get; set; } = null!; + [Inject] + protected LicenseService LicServ{get;set;}=null!; #region Protected Methods protected override async Task OnInitializedAsync() diff --git a/MP.Land/Pages/UpdateManager.razor.cs b/MP.Land/Pages/UpdateManager.razor.cs index ae02e862..63ab72d0 100644 --- a/MP.Land/Pages/UpdateManager.razor.cs +++ b/MP.Land/Pages/UpdateManager.razor.cs @@ -7,6 +7,7 @@ using MP.Land.Data; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Drawing; using System.IO; using System.Linq; using System.Reflection; @@ -18,6 +19,32 @@ namespace MP.Land.Pages { #region Public Methods + /// + /// Procedura di aggiunta folder a ZipFile, ricorsiva + /// + /// + /// + /// + public void AddFolderToZip(ZipFile f, string root, string folder) + { + string relative = folder.Substring(root.Length); + if (relative.Length > 0) + { + f.AddDirectory(relative); + } + + foreach (string file in Directory.GetFiles(folder)) + { + relative = file.Substring(root.Length); + f.Add(file, relative); + } + + foreach (string subFolder in Directory.GetDirectories(folder)) + { + this.AddFolderToZip(f, root, subFolder); + } + } + public void Dispose() { ListRecords = null; @@ -59,6 +86,9 @@ namespace MP.Land.Pages protected bool showProgress { get; set; } = false; protected bool showUpdate { get; set; } = false; + [Inject] + protected SyncService SyncServ { get; set; } = null!; + #endregion Protected Properties #region Protected Methods @@ -174,8 +204,8 @@ namespace MP.Land.Pages authList.Add(item); } } - // numero app + IOB + ZIP - numTot = authList.Count + 2; + // numero app + IOB + DB + ZIP + numTot = authList.Count + 3; // recupero conf files foreach (var item in authList) @@ -187,9 +217,11 @@ namespace MP.Land.Pages } // recupero i file IOB RecuperaIobConf(); + // salvo Tab Db come json + SaveDbConfAsJson(); // ora creo il file zip - await PrepareZip(); + PrepareZip(); // effettuo upload await UploadZip(); @@ -212,12 +244,18 @@ namespace MP.Land.Pages #endregion Private Fields #region Private Properties + #if DEBUG private DirectoryInfo AppDir => new DirectoryInfo(Path.Combine("\\\\iis01.egalware.com", "c$\\inetpub\\wwwroot\\MP\\LAND")); #else private DirectoryInfo AppDir => new DirectoryInfo(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)); #endif + /// + /// Nome del file ZIP da gestire + /// + private string zFileName => Path.Combine(AppDir.FullName, "temp", "zip", "MAPO.zip"); + #endregion Private Properties #region Private Methods @@ -225,126 +263,22 @@ namespace MP.Land.Pages /// /// Preparazione ZIP con password = AuthKey /// - private async Task PrepareZip() + private void PrepareZip() { string srcPath = Path.Combine(AppDir.FullName, "temp", "orig"); string destPath = Path.Combine(AppDir.FullName, "temp", "zip"); - if(!Directory.Exists(destPath)) + if (!Directory.Exists(destPath)) { Directory.CreateDirectory(destPath); } - string zFile = Path.Combine(AppDir.FullName, "temp", "zip", "MAPO.zip"); - -#if false - ZipDirectory(folderName, zFile, 9); - await Task.Delay(1); - -#endif - using (ZipFile zipFile = ZipFile.Create(zFile)) + using (ZipFile zipFile = ZipFile.Create(zFileName)) { + zipFile.Password = LicServ.MasterKey; zipFile.BeginUpdate(); - addFolderToZip(zipFile, srcPath, srcPath); + AddFolderToZip(zipFile, srcPath, srcPath); zipFile.CommitUpdate(); zipFile.Close(); } - - - } - - public void addFolderToZip(ZipFile f, string root, string folder) - { - - string relative = folder.Substring(root.Length); - if (relative.Length > 0) - { - f.AddDirectory(relative); - } - - foreach (string file in Directory.GetFiles(folder)) - { - relative = file.Substring(root.Length); - f.Add(file, relative); - } - - foreach (string subFolder in Directory.GetDirectories(folder)) - { - this.addFolderToZip(f, root, subFolder); - } - } - - /// - /// Method that compress all the files inside a folder (non-recursive) into a zip file. - /// - /// - /// - /// - private void ZipDirectory(string DirectoryPath, string OutputFilePath, int CompressionLevel = 9) - { - try - { - // Depending on the directory this could be very large and would require more attention - // in a commercial package. - string[] filenames = Directory.GetFiles(DirectoryPath); - - // 'using' statements guarantee the stream is closed properly which is a big source - // of problems otherwise. Its exception safe as well which is great. - using (ZipOutputStream OutputStream = new ZipOutputStream(File.Create(OutputFilePath))) - { - - // Define the compression level - // 0 - store only to 9 - means best compression - OutputStream.SetLevel(CompressionLevel); - - byte[] buffer = new byte[4096]; - - foreach (string file in filenames) - { - - // Using GetFileName makes the result compatible with XP - // as the resulting path is not absolute. - ZipEntry entry = new ZipEntry(Path.GetFileName(file)); - - // Setup the entry data as required. - - // Crc and size are handled by the library for seakable streams - // so no need to do them here. - - // Could also use the last write time or similar for the file. - entry.DateTime = DateTime.Now; - OutputStream.PutNextEntry(entry); - - using (FileStream fs = File.OpenRead(file)) - { - - // Using a fixed size buffer here makes no noticeable difference for output - // but keeps a lid on memory usage. - int sourceBytes; - - do - { - sourceBytes = fs.Read(buffer, 0, buffer.Length); - OutputStream.Write(buffer, 0, sourceBytes); - } while (sourceBytes > 0); - } - } - - // Finish/Close arent needed strictly as the using statement does this automatically - - // Finish is important to ensure trailing information for a Zip file is appended. Without this - // the created file would be invalid. - OutputStream.Finish(); - - // Close is important to wrap things up and unlock the file. - OutputStream.Close(); - - Console.WriteLine("Files successfully compressed"); - } - } - catch (Exception ex) - { - // No need to rethrow the exception as for our purposes its handled. - Console.WriteLine("Exception during processing {0}", ex); - } } /// @@ -423,6 +357,46 @@ namespace MP.Land.Pages } } + /// + /// Salvataggio tabelle di configurazione specifica come tracciati json + /// + /// + private void SaveDbConfAsJson() + { + long size = 0; + + string dstDir = Path.Combine(AppDir.FullName, "temp", "orig", "DB"); + if (!Directory.Exists(dstDir)) + { + Directory.CreateDirectory(dstDir); + } + // va fatta 1:1 per ogni tabella + +#if false + string srcIobDir = Path.Combine(AppDir.Parent.FullName, "IO", "fileUpload"); + // recupero elenco files tipo appsettings*.json + if (Directory.Exists(srcIobDir)) + { + var dirInfo = new DirectoryInfo(srcIobDir); + // recupero files CORE + List fileList = dirInfo.GetFiles().ToList(); + // procedo! + foreach (var file in fileList) + { + string fileDestPath = Path.Combine(dstDir, file.Name); + file.CopyTo(fileDestPath, true); + size += file.Length; + } + } +#endif + + numDone++; + percLoading = 100 * numDone / numTot; + TotalMb += size; + outMessages = $"Configurazioni preparate: {numDone}/{numTot} | {CalcSize(TotalMb)}"; + } + + /// /// Effettua download di una singola app /// @@ -449,13 +423,14 @@ namespace MP.Land.Pages /// /// /// - private async Task UploadZip() + private async Task UploadZip() { - await Task.Delay(200); + // chiamo SendZipFile di SyncService... + FileInfo zFileInfo = new FileInfo(zFileName); + var fatto = await SyncServ.SendZipFile(LicServ.Applicazione, LicServ.Installazione, true, false, zFileInfo); + return fatto; } #endregion Private Methods - - } } \ No newline at end of file diff --git a/MP.Land/Resources/ChangeLog.html b/MP.Land/Resources/ChangeLog.html index 99342e44..06b7ca50 100644 --- a/MP.Land/Resources/ChangeLog.html +++ b/MP.Land/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo Tablet MAPO - DotNet6 -

    Versione: 6.16.2410.1719

    +

    Versione: 6.16.2410.1815


    Note di rilascio:
      diff --git a/MP.Land/Resources/VersNum.txt b/MP.Land/Resources/VersNum.txt index 8021a159..aa74da27 100644 --- a/MP.Land/Resources/VersNum.txt +++ b/MP.Land/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2410.1719 +6.16.2410.1815 diff --git a/MP.Land/Resources/manifest.xml b/MP.Land/Resources/manifest.xml index c50f8022..63a924b1 100644 --- a/MP.Land/Resources/manifest.xml +++ b/MP.Land/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2410.1719 + 6.16.2410.1815 https://nexus.steamware.net/repository/SWS/MP-LAND/stable/LAST/MP.Land.zip https://nexus.steamware.net/repository/SWS/MP-LAND/stable/LAST/ChangeLog.html false From b8e5197bc7b8e435a26fb69dcc7da0ff4ea4858c Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 18 Oct 2024 15:34:25 +0200 Subject: [PATCH 5/5] LAND . fix condizione DEBUG URL x upload (verso LiMan dev locale) --- MP.Land/Pages/UpdateManager.razor.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MP.Land/Pages/UpdateManager.razor.cs b/MP.Land/Pages/UpdateManager.razor.cs index 63ab72d0..d7c17bd7 100644 --- a/MP.Land/Pages/UpdateManager.razor.cs +++ b/MP.Land/Pages/UpdateManager.razor.cs @@ -243,9 +243,10 @@ namespace MP.Land.Pages #endregion Private Fields +#if DEBUG + #region Private Properties -#if DEBUG private DirectoryInfo AppDir => new DirectoryInfo(Path.Combine("\\\\iis01.egalware.com", "c$\\inetpub\\wwwroot\\MP\\LAND")); #else private DirectoryInfo AppDir => new DirectoryInfo(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)); @@ -396,7 +397,6 @@ namespace MP.Land.Pages outMessages = $"Configurazioni preparate: {numDone}/{numTot} | {CalcSize(TotalMb)}"; } - /// /// Effettua download di una singola app ///