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(" ");
+
+ // 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