Inserito serializzazione su XML dei racconti

This commit is contained in:
CSiCoAlm committed 2026-01-04 11:38:20 +01:00
1 parent 6b7d77d1a4
commit 09606b60ae
5 files changed
+90 -24

No files matched your search

+4
View File
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace A69WD.Data {
@@ -11,7 +12,10 @@ namespace A69WD.Data {
/// </summary>
public class cNota {
[XmlAttribute]
public string Key { get; set; }
[XmlAttribute]
public string Description { get; set; }
/// <summary>
+51
View File
@@ -4,6 +4,7 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace A69WD.Data {
@@ -83,6 +84,8 @@ namespace A69WD.Data {
/// Default: null
/// Mappa la relazione tramite [Links_Rac_Aut] con la tabella [Autori].
/// </summary>
[XmlArray("Autori")]
[XmlArrayItem("Autore")]
public List<string> Autori { get; set; } = new List<string>();
/// <summary>
@@ -90,6 +93,8 @@ namespace A69WD.Data {
/// Default: null
/// Mappa la relazione tramite [Links_Rac_Tag] con la tabella [Tags].
/// </summary>
[XmlArray("Tags")]
[XmlArrayItem("Tag")]
public List<string> Tags { get; set; } = new List<string>();
/// <summary>
@@ -97,6 +102,8 @@ namespace A69WD.Data {
/// Default: null
/// Mappa la relazione tramite [Links_Rac_Ori] con la tabella [Origini].
/// </summary>
[XmlArray("Origini")]
[XmlArrayItem("Origine")]
public List<string> Origini { get; set; } = new List<string>();
/// <summary>
@@ -108,6 +115,8 @@ namespace A69WD.Data {
/// Mappa la relazione tramite [Links_Rac_Not] con la tabella [Notes].
/// </summary>
//public Dictionary<string, string> Note { get; set; } = new Dictionary<string, string>();
[XmlArray("Notes")]
[XmlArrayItem("Nota")]
public List<cNota> Notes { get; set; } = new List<cNota>();
#endregion
@@ -278,7 +287,49 @@ namespace A69WD.Data {
#endregion
#region Serializzazione su file XML
/// <summary>
/// Serializza l'oggetto cRac in xml
/// </summary>
/// <returns>Testo xml che serializza il cRac</returns>
public string ToXml() {
XmlSerializer serializer = new XmlSerializer(typeof(cRac));
StringWriter sw = new StringWriter();
serializer.Serialize(sw, this);
return sw.ToString();
}
/// <summary>
/// Deserializza l'oggetto cRac dal formato xml
/// </summary>
/// <param name="xml">Testo xml che serializza il cRac</param>
/// <returns>cRac che rappresenta il racconto ricavato dal testo xml</returns>
public static cRac FromXml(string xml) {
XmlSerializer serializer = new XmlSerializer(typeof(cRac));
StringReader sr = new StringReader(xml);
return (cRac)serializer.Deserialize(sr);
}
/// <summary>
/// Salva il cRac come file xml
/// </summary>
/// <param name="path">Path dove salvare</param>
public void SaveToXmlFile(string path) {
File.WriteAllText(path, ToXml());
}
/// <summary>
/// Carica il cRac dal file XML indicato
/// </summary>
/// <param name="path">Path da dove caricare</param>
/// <returns>cRac che rappresenta il racconto ricavato dal file xml</returns>
public static cRac LoadFromXmlFile(string path) {
string xml = File.ReadAllText(path);
return FromXml(xml);
}
#endregion
/// <summary>
/// Crea il file html che rappresenta il racconto.
+2 -2
View File
@@ -32,8 +32,8 @@ using System.Runtime.InteropServices;
// È possibile specificare tutti i valori oppure impostare valori predefiniti per i numeri relativi alla revisione e alla build
// usando l'asterisco '*' come illustrato di seguito:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.5.3.0")]
[assembly: AssemblyFileVersion("0.5.3.0")]
[assembly: AssemblyVersion("0.5.3.1")]
[assembly: AssemblyFileVersion("0.5.3.1")]
/*
+16 -3
View File
@@ -30,6 +30,7 @@
this.sbStatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
this.btnTest1 = new System.Windows.Forms.Button();
this.pnlTop = new System.Windows.Forms.Panel();
this.btnTest2 = new System.Windows.Forms.Button();
this.sb.SuspendLayout();
this.pnlTop.SuspendLayout();
this.SuspendLayout();
@@ -95,16 +96,17 @@
//
// btnTest1
//
this.btnTest1.Location = new System.Drawing.Point(11, 5);
this.btnTest1.Location = new System.Drawing.Point(11, 4);
this.btnTest1.Name = "btnTest1";
this.btnTest1.Size = new System.Drawing.Size(62, 32);
this.btnTest1.Size = new System.Drawing.Size(79, 32);
this.btnTest1.TabIndex = 4;
this.btnTest1.Text = "Test";
this.btnTest1.Text = "Serializza";
this.btnTest1.UseVisualStyleBackColor = true;
this.btnTest1.Click += new System.EventHandler(this.btnTest1_Click);
//
// pnlTop
//
this.pnlTop.Controls.Add(this.btnTest2);
this.pnlTop.Controls.Add(this.btnTest1);
this.pnlTop.Dock = System.Windows.Forms.DockStyle.Top;
this.pnlTop.Location = new System.Drawing.Point(0, 0);
@@ -112,6 +114,16 @@
this.pnlTop.Size = new System.Drawing.Size(700, 42);
this.pnlTop.TabIndex = 0;
//
// btnTest2
//
this.btnTest2.Location = new System.Drawing.Point(94, 4);
this.btnTest2.Name = "btnTest2";
this.btnTest2.Size = new System.Drawing.Size(79, 32);
this.btnTest2.TabIndex = 5;
this.btnTest2.Text = "Deserializza";
this.btnTest2.UseVisualStyleBackColor = true;
this.btnTest2.Click += new System.EventHandler(this.btnTest2_Click);
//
// frmReader
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -141,5 +153,6 @@
private System.Windows.Forms.ToolStripStatusLabel sbStatusLabel;
private System.Windows.Forms.Button btnTest1;
private System.Windows.Forms.Panel pnlTop;
private System.Windows.Forms.Button btnTest2;
}
}
+17 -19
View File
@@ -61,9 +61,9 @@ namespace A69WD.UI {
mImpStart.Enabled = true;
mImpStop.Enabled = false;
// Update UI
pnlTop.Enabled = false;
pnlTop.Visible = false;
// TEST // Update UI
// TEST pnlTop.Enabled = false;
// TEST pnlTop.Visible = false;
}
@@ -741,30 +741,28 @@ namespace A69WD.UI {
}
private void btnTest1_Click(object sender, EventArgs e) {
// Test skraping eRac
// Test serializzazione su file xml
// - Verifico path per il download
if (!System.IO.Directory.Exists(Cfg.Settings.PathDownloadWorking)) System.IO.Directory.CreateDirectory(Cfg.Settings.PathDownloadWorking);
// Preparo il servizio
serviceCrawler = new Service_Crawler(sb);
// Inserisco i link iniziali nella coda
if (!cLink_eRac.InsertStartLink(serviceCrawler)) {
Logger.Warning("eRac - Insert start link Fault");
sbStatusLabel.Text = "eRac fault.";
return;
// Serializzo 5 racconti casuali
for (int i = 0; i < 5; i++) {
cRac rac = App.DB.GetRacById(App.DB.GetRandomIDrac());
string path = System.IO.Path.Combine(Cfg.Settings.PathDownloadWorking, $"ATDB_Rac_{rac.strIDrac}.xml");
rac.SaveToXmlFile(path);
}
//// Inserisco link di un racconto:
//string url = "https://www.eroticiracconti.it/racconto/105286-nicole-gis-il-culto-della-terza-notte"; // "https://www.eroticiracconti.it/racconto/112763-elara-capitolo-2-il-cambiamento";
//string name = "eRac_112763-elara-capitolo-2-il-cambiamento.html";
//serviceCrawler.EnqueueUrl(new cLink_eRac(url, name));
// avvio il servizio
serviceCrawler.StartWorker();
}
private void btnTest2_Click(object sender, EventArgs e) {
// Test deserializzazione da file xml
string[] files = System.IO.Directory.GetFiles(Cfg.Settings.PathImport, "ATDB_*.xml");
foreach (string file in files) {
cRac rac = cRac.LoadFromXmlFile(file);
var res = App.DB.ImportRac(rac);
}
}
}
}