From 1cc452829559f81ba64e1e5ff69d524b66204ccd Mon Sep 17 00:00:00 2001 From: CSiCoAlm Date: Sun, 28 Dec 2025 13:52:05 +0100 Subject: [PATCH] Testato esportazione in html Test degli spunti ottenuti da una chat con Gemini. - [ ] Test della classe cRac.cs - [ ] Test della funzione di salvataggio sul DB - [ ] Test della funzione di lettura dal DB - [ ] Test della funzione di ricerca nel DB - [ ] Test funzione di cancellazione nel DB - [ ] Test nella ricerca di duplicati - [X] Test della funzione di esportazione in html con stile Riepilogo della chat: - connesso a gemini con chrome e utente mirko - dato in pasto il file *ATDB Database Schema.sql* con la struttura del DB - richiesto la classe cRac per rappresentare un racconto. - ottenuto *cRac.cs* - richiesto come salvare un cRac sul DB con diagnostica errori ed evitando spurie sul DB - ottenuto *Salvataggio cRac su DB.cs* - richiesto come leggere un racconto - ottenuto *GetRaccontoById.cs* - richiesto: ragruppiamo le funzioni di helper su un file Helper.cs e quelle di lettura/scrittura sul DB sul file DB.cs - ottenuto *Helper.cs* e *DB.cs* - richiesto: facciamo le ricerche avanzate per titolo, tag, autore, data di creazione, sorgente - ottenuta la nuova versione di *Aggiornamento 1 di DB.cs* - richiesto come eliminare un racconto dal DB - ottenuta la nuova versione di *Aggiornamento 2 di DB.cs* - richiesto: come ricercare racconti duplicati - ottenuto spunti di ricerca salvati in *Ricerca duplicati.cs* - richiesto come fare il merge di racconti duplicati - ottenuto *merge.cs* - richiesto delle idee per la UI - ottenuto il file *UI_idee.md* - richiesto un esempio di esportazione di un racconto in html con stile - ottenuto: *export.cs* --- Src/A69WD/Data/cRac.cs | 97 ++++++++++++++++++++++++++ Src/A69WD/Service/Service_Importer.cs | 4 +- Src/A69WD/UI/frmDownloader.Designer.cs | 13 ++++ Src/A69WD/UI/frmDownloader.cs | 18 +++++ 4 files changed, 130 insertions(+), 2 deletions(-) diff --git a/Src/A69WD/Data/cRac.cs b/Src/A69WD/Data/cRac.cs index c6bb4f1..12a708c 100644 --- a/Src/A69WD/Data/cRac.cs +++ b/Src/A69WD/Data/cRac.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace A69WD.Data { @@ -825,6 +827,101 @@ namespace A69WD.Data { } } + + + + public static string EsportaInHtml(cRac racconto, string cartellaDestinazione) { + + // Crea il nome del file pulendo il titolo da caratteri non validi + string nomeFile = string.Join("_", racconto.Title.Split(Path.GetInvalidFileNameChars())); + string pathCompleto = Path.Combine(cartellaDestinazione, $"{racconto.strIDrac}_{nomeFile}.html"); + + StringBuilder sb = new StringBuilder(); + try { + + + // Inizio Documento HTML + sb.AppendLine(""); + sb.AppendLine(""); + sb.AppendLine(""); + sb.AppendLine(" "); + sb.AppendLine($" {racconto.Title}"); + + // CSS Incorporato per uno stile elegante (Bookish Style) + sb.AppendLine(" "); + sb.AppendLine(""); + sb.AppendLine(""); + + sb.AppendLine("
"); + + // Intestazione + sb.AppendLine($"

{racconto.Title}

"); + if (!string.IsNullOrEmpty(racconto.SubTitle)) + sb.AppendLine($"

{racconto.SubTitle}

"); + + // Metadata (Autori, Voto, Origini) + sb.AppendLine(" "); + + // Corpo del racconto (Trama) + sb.AppendLine("
"); + sb.AppendLine(racconto.Trama); // Preserva i ritorni a capo grazie a white-space: pre-wrap + sb.AppendLine("
"); + + // Note (se presenti) + if (racconto.Notes.Any()) { + sb.AppendLine("
"); + sb.AppendLine("

Note

"); + foreach (var nota in racconto.Notes) + sb.AppendLine($"

{nota.Key}: {nota.Description}

"); + sb.AppendLine("
"); + } + + // Tags + if (racconto.Tags.Any()) { + sb.AppendLine("
"); + racconto.Tags.Sort(); + //foreach (var tag in racconto.Tags) + // sb.AppendLine($" #{tag}"); + racconto.Tags.ForEach(t => sb.AppendLine($" #{t}")); + sb.AppendLine("
"); + } + + // Footer + sb.AppendLine(" "); + + sb.AppendLine("
"); // Fine container + sb.AppendLine(""); + sb.AppendLine(""); + + // Scrittura su file + File.WriteAllText(pathCompleto, sb.ToString()); + } catch (Exception ex) { Logger.Error("A69 Export - " + ex.Message); } + return pathCompleto; + } + + + } // class cRac }//namespace A69WD.Data diff --git a/Src/A69WD/Service/Service_Importer.cs b/Src/A69WD/Service/Service_Importer.cs index 3ba7d0b..c14c1f1 100644 --- a/Src/A69WD/Service/Service_Importer.cs +++ b/Src/A69WD/Service/Service_Importer.cs @@ -83,8 +83,8 @@ namespace A69WD.Service { if (rac != null) { // Racconto estratto correttamente, lo salvo sul DB Logger.Warning($"Import - estrazione corretta: {name}"); - int res = App.DB.ImportRac(rac); - if (res != 1) { + int res = App.DB.ImportRac(rac); // res=id del racconto nel DB + if (res < 1) { // errore nel salvataggio Logger.Warning($"Import - errore nel salvataggio: {name}"); Interlocked.Increment(ref _errori); diff --git a/Src/A69WD/UI/frmDownloader.Designer.cs b/Src/A69WD/UI/frmDownloader.Designer.cs index 915fa03..2c1e625 100644 --- a/Src/A69WD/UI/frmDownloader.Designer.cs +++ b/Src/A69WD/UI/frmDownloader.Designer.cs @@ -31,6 +31,7 @@ this.btnShowLog = new System.Windows.Forms.Button(); this.pbST = new System.Windows.Forms.ProgressBar(); this.btnImport = new System.Windows.Forms.Button(); + this.btnTest = new System.Windows.Forms.Button(); this.SuspendLayout(); // // btnClose @@ -108,11 +109,22 @@ this.btnImport.UseVisualStyleBackColor = true; this.btnImport.Click += new System.EventHandler(this.btnImport_Click); // + // btnTest + // + this.btnTest.Location = new System.Drawing.Point(121, -1); + this.btnTest.Name = "btnTest"; + this.btnTest.Size = new System.Drawing.Size(55, 33); + this.btnTest.TabIndex = 20; + this.btnTest.Text = "Test"; + this.btnTest.UseVisualStyleBackColor = true; + this.btnTest.Click += new System.EventHandler(this.btnTest_Click); + // // frmDownloader // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(433, 95); + this.Controls.Add(this.btnTest); this.Controls.Add(this.btnImport); this.Controls.Add(this.pbST); this.Controls.Add(this.btnShowLog); @@ -136,5 +148,6 @@ private System.Windows.Forms.Button btnShowLog; private System.Windows.Forms.ProgressBar pbST; private System.Windows.Forms.Button btnImport; + private System.Windows.Forms.Button btnTest; } } \ No newline at end of file diff --git a/Src/A69WD/UI/frmDownloader.cs b/Src/A69WD/UI/frmDownloader.cs index 2e8a854..e3b966f 100644 --- a/Src/A69WD/UI/frmDownloader.cs +++ b/Src/A69WD/UI/frmDownloader.cs @@ -183,6 +183,24 @@ namespace A69WD { } private Service_Importer serviceImporter = null; + private void btnTest_Click(object sender, EventArgs e) { + int MaxRac = 60; + pbST.Maximum = MaxRac; + pbST.Minimum = 0; + pbST.Value = 0; + lblST.Text = "Inizio esportazione racconti"; + for (int i = 0; i < 61; i++) { + cRac rac = App.DB.GetRacById(i); + cRac.EsportaInHtml(rac, Cfg.Settings.PathDownloadWorking); + pbST.Value = i; + lblST.Text = $"Esportato racconto ID={rac.strIDrac}"; + } + lblST.Text = $"Fine esportazione {MaxRac.ToString("000")} racconti"; + } + + + + }//class frmDownloader