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