diff --git a/Src/A69WD/Data/cNota.cs b/Src/A69WD/Data/cNota.cs
index 566db36..62be4c6 100644
--- a/Src/A69WD/Data/cNota.cs
+++ b/Src/A69WD/Data/cNota.cs
@@ -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 {
///
public class cNota {
+ [XmlAttribute]
public string Key { get; set; }
+
+ [XmlAttribute]
public string Description { get; set; }
///
diff --git a/Src/A69WD/Data/cRac.cs b/Src/A69WD/Data/cRac.cs
index c4b0c9e..163539a 100644
--- a/Src/A69WD/Data/cRac.cs
+++ b/Src/A69WD/Data/cRac.cs
@@ -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].
///
+ [XmlArray("Autori")]
+ [XmlArrayItem("Autore")]
public List Autori { get; set; } = new List();
///
@@ -90,6 +93,8 @@ namespace A69WD.Data {
/// Default: null
/// Mappa la relazione tramite [Links_Rac_Tag] con la tabella [Tags].
///
+ [XmlArray("Tags")]
+ [XmlArrayItem("Tag")]
public List Tags { get; set; } = new List();
///
@@ -97,6 +102,8 @@ namespace A69WD.Data {
/// Default: null
/// Mappa la relazione tramite [Links_Rac_Ori] con la tabella [Origini].
///
+ [XmlArray("Origini")]
+ [XmlArrayItem("Origine")]
public List Origini { get; set; } = new List();
///
@@ -108,6 +115,8 @@ namespace A69WD.Data {
/// Mappa la relazione tramite [Links_Rac_Not] con la tabella [Notes].
///
//public Dictionary Note { get; set; } = new Dictionary();
+ [XmlArray("Notes")]
+ [XmlArrayItem("Nota")]
public List Notes { get; set; } = new List();
#endregion
@@ -278,7 +287,49 @@ namespace A69WD.Data {
#endregion
+ #region Serializzazione su file XML
+ ///
+ /// Serializza l'oggetto cRac in xml
+ ///
+ /// Testo xml che serializza il cRac
+ public string ToXml() {
+ XmlSerializer serializer = new XmlSerializer(typeof(cRac));
+ StringWriter sw = new StringWriter();
+ serializer.Serialize(sw, this);
+ return sw.ToString();
+ }
+
+ ///
+ /// Deserializza l'oggetto cRac dal formato xml
+ ///
+ /// Testo xml che serializza il cRac
+ /// cRac che rappresenta il racconto ricavato dal testo xml
+ public static cRac FromXml(string xml) {
+ XmlSerializer serializer = new XmlSerializer(typeof(cRac));
+ StringReader sr = new StringReader(xml);
+ return (cRac)serializer.Deserialize(sr);
+ }
+
+ ///
+ /// Salva il cRac come file xml
+ ///
+ /// Path dove salvare
+ public void SaveToXmlFile(string path) {
+ File.WriteAllText(path, ToXml());
+ }
+
+ ///
+ /// Carica il cRac dal file XML indicato
+ ///
+ /// Path da dove caricare
+ /// cRac che rappresenta il racconto ricavato dal file xml
+ public static cRac LoadFromXmlFile(string path) {
+ string xml = File.ReadAllText(path);
+ return FromXml(xml);
+ }
+
+ #endregion
///
/// Crea il file html che rappresenta il racconto.
diff --git a/Src/A69WD/Properties/AssemblyInfo.cs b/Src/A69WD/Properties/AssemblyInfo.cs
index 3a476fb..3a0e0c8 100644
--- a/Src/A69WD/Properties/AssemblyInfo.cs
+++ b/Src/A69WD/Properties/AssemblyInfo.cs
@@ -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")]
/*
diff --git a/Src/A69WD/UI/frmReader.Designer.cs b/Src/A69WD/UI/frmReader.Designer.cs
index 346d918..4d0a9ff 100644
--- a/Src/A69WD/UI/frmReader.Designer.cs
+++ b/Src/A69WD/UI/frmReader.Designer.cs
@@ -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;
}
}
\ No newline at end of file
diff --git a/Src/A69WD/UI/frmReader.cs b/Src/A69WD/UI/frmReader.cs
index 6a31982..ca584a3 100644
--- a/Src/A69WD/UI/frmReader.cs
+++ b/Src/A69WD/UI/frmReader.cs
@@ -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);
+ }
+ }
}
}