Merge pull request 'Inserire un lettore per i racconti' (#8) from mrk/Insert Reader into master

Reviewed-on: http://mrkalm.ddns.net:34333/MrkPi/A69WD/pulls/8
This commit is contained in:
Mrk committed 2025-12-29 14:30:26 +01:00
commit ab758b77d9
18 files changed
+1431 -470

No files matched your search

+1 -1
View File
@@ -1 +1 @@
{"RootPath":"C:\\Commesse\\_zPrivate\\A69WD\\Src\\A69WD","ProjectFileName":"A69WD.csproj","Configuration":"Debug|AnyCPU","FrameworkPath":"","Sources":[{"SourceFile":"App.cs"},{"SourceFile":"Data\\cNota.cs"},{"SourceFile":"Data\\cRac.cs"},{"SourceFile":"Data\\DBTools.cs"},{"SourceFile":"Net\\eLinkState.cs"},{"SourceFile":"Net\\cLink_A69.cs"},{"SourceFile":"Service\\Service_Crawler.cs"},{"SourceFile":"Site\\cSite_A69.cs"},{"SourceFile":"UI\\frmDownloader.cs"},{"SourceFile":"UI\\frmDownloader.Designer.cs"},{"SourceFile":"General\\Cfg.cs"},{"SourceFile":"General\\cTools.cs"},{"SourceFile":"General\\Logger.cs"},{"SourceFile":"Net\\iLink.cs"},{"SourceFile":"Properties\\AssemblyInfo.cs"},{"SourceFile":"Site\\iSiteType.cs"},{"SourceFile":"Properties\\Resources.Designer.cs"},{"SourceFile":"Properties\\Settings.Designer.cs"},{"SourceFile":"obj\\Debug\\.NETFramework,Version=v4.8.AssemblyAttributes.cs"}],"References":[{"Reference":"C:\\Commesse\\_zPrivate\\A69WD\\Src\\_Lib\\HtmlAgilityPack.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\Microsoft.CSharp.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\mscorlib.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Core.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Data.DataSetExtensions.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Data.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Commesse\\_zPrivate\\A69WD\\Src\\_Lib\\System.Data.SQLite.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Deployment.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Drawing.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Net.Http.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Windows.Forms.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Xml.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Xml.Linq.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""}],"Analyzers":[],"Outputs":[{"OutputItemFullPath":"C:\\Commesse\\_zPrivate\\A69WD\\Src\\A69WD\\bin\\Debug\\A69WD.exe","OutputItemRelativePath":"A69WD.exe"},{"OutputItemFullPath":"","OutputItemRelativePath":""}],"CopyToOutputEntries":[]} {"RootPath":"C:\\Commesse\\_zPrivate\\A69WD\\Src\\A69WD","ProjectFileName":"A69WD.csproj","Configuration":"Debug|AnyCPU","FrameworkPath":"","Sources":[{"SourceFile":"App.cs"},{"SourceFile":"Data\\cNota.cs"},{"SourceFile":"Data\\cRac.cs"},{"SourceFile":"Data\\DBTools.cs"},{"SourceFile":"Data\\Helper.cs"},{"SourceFile":"General\\Navigator.cs"},{"SourceFile":"Net\\eLinkState.cs"},{"SourceFile":"Net\\cLink_A69.cs"},{"SourceFile":"Service\\Service_Crawler.cs"},{"SourceFile":"Service\\Service_Importer.cs"},{"SourceFile":"Site\\cSite_A69.cs"},{"SourceFile":"UI\\frmDownloader.cs"},{"SourceFile":"UI\\frmDownloader.Designer.cs"},{"SourceFile":"General\\Cfg.cs"},{"SourceFile":"General\\cTools.cs"},{"SourceFile":"General\\Logger.cs"},{"SourceFile":"Net\\iLink.cs"},{"SourceFile":"Properties\\AssemblyInfo.cs"},{"SourceFile":"Site\\iSiteType.cs"},{"SourceFile":"UI\\frmReader.cs"},{"SourceFile":"UI\\frmReader.Designer.cs"},{"SourceFile":"Properties\\Resources.Designer.cs"},{"SourceFile":"Properties\\Settings.Designer.cs"},{"SourceFile":"obj\\Debug\\.NETFramework,Version=v4.8.AssemblyAttributes.cs"}],"References":[{"Reference":"C:\\Commesse\\_zPrivate\\A69WD\\Src\\_Lib\\HtmlAgilityPack.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\Microsoft.CSharp.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\mscorlib.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Core.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Data.DataSetExtensions.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Data.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Commesse\\_zPrivate\\A69WD\\Src\\_Lib\\System.Data.SQLite.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Deployment.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Drawing.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Net.Http.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Windows.Forms.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Xml.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Xml.Linq.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""}],"Analyzers":[],"Outputs":[{"OutputItemFullPath":"C:\\Commesse\\_zPrivate\\A69WD\\Src\\A69WD\\bin\\Debug\\A69WD.exe","OutputItemRelativePath":"A69WD.exe"},{"OutputItemFullPath":"","OutputItemRelativePath":""}],"CopyToOutputEntries":[]}
+10 -9
View File
@@ -63,26 +63,24 @@
<Compile Include="Data\cRac.cs" /> <Compile Include="Data\cRac.cs" />
<Compile Include="Data\DBTools.cs" /> <Compile Include="Data\DBTools.cs" />
<Compile Include="Data\Helper.cs" /> <Compile Include="Data\Helper.cs" />
<Compile Include="General\Navigator.cs" />
<Compile Include="Net\eLinkState.cs" /> <Compile Include="Net\eLinkState.cs" />
<Compile Include="Net\cLink_A69.cs" /> <Compile Include="Net\cLink_A69.cs" />
<Compile Include="Service\Service_Crawler.cs" /> <Compile Include="Service\Service_Crawler.cs" />
<Compile Include="Service\Service_Importer.cs" /> <Compile Include="Service\Service_Importer.cs" />
<Compile Include="Site\cSite_A69.cs" /> <Compile Include="Site\cSite_A69.cs" />
<Compile Include="UI\frmDownloader.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UI\frmDownloader.Designer.cs">
<DependentUpon>frmDownloader.cs</DependentUpon>
</Compile>
<Compile Include="General\Cfg.cs" /> <Compile Include="General\Cfg.cs" />
<Compile Include="General\cTools.cs" /> <Compile Include="General\cTools.cs" />
<Compile Include="General\Logger.cs" /> <Compile Include="General\Logger.cs" />
<Compile Include="Net\iLink.cs" /> <Compile Include="Net\iLink.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Site\iSiteType.cs" /> <Compile Include="Site\iSiteType.cs" />
<EmbeddedResource Include="UI\frmDownloader.resx"> <Compile Include="UI\frmReader.cs">
<DependentUpon>frmDownloader.cs</DependentUpon> <SubType>Form</SubType>
</EmbeddedResource> </Compile>
<Compile Include="UI\frmReader.Designer.cs">
<DependentUpon>frmReader.cs</DependentUpon>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx"> <EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator> <Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput> <LastGenOutput>Resources.Designer.cs</LastGenOutput>
@@ -93,6 +91,9 @@
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>
</Compile> </Compile>
<EmbeddedResource Include="UI\frmReader.resx">
<DependentUpon>frmReader.cs</DependentUpon>
</EmbeddedResource>
<None Include="Properties\Settings.settings"> <None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator> <Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput> <LastGenOutput>Settings.Designer.cs</LastGenOutput>
+3 -1
View File
@@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows.Forms; using System.Windows.Forms;
using A69WD.UI;
@@ -34,7 +35,8 @@ namespace A69WD {
// Start application: // Start application:
Logger.Information(" - - - START Application - - - "); Logger.Information(" - - - START Application - - - ");
if (DB.DB_ok) { if (DB.DB_ok) {
Application.Run(new frmDownloader()); //Application.Run(new frmDownloader());
Application.Run(new frmReader());
Logger.Information(" - - - STOP Application - - - "); Logger.Information(" - - - STOP Application - - - ");
+81
View File
@@ -1725,8 +1725,18 @@ namespace A69WD {
// Metodi ricavati ottimizzando i miei tramite gemini // Metodi ricavati ottimizzando i miei tramite gemini
/// <summary> /// <summary>
/// Ricava il racconto con l'ID indicato leggendolo dal DB /// Ricava il racconto con l'ID indicato leggendolo dal DB
/// </summary> /// </summary>
@@ -1934,6 +1944,77 @@ namespace A69WD {
#region Reader function: GetReport, GetRandomIDrac
private long GetNumRacs(string TagFilter = "") {
string query = "SELECT count (IDrac) FROM Racconti";
if (TagFilter != "") { query = "SELECT count (Racconti.IDrac) AS NUM FROM Racconti, Links_Rac_Vot, Voti WHERE Racconti.IDrac=Links_Rac_Vot.IDrac AND Links_Rac_Vot.IDvot=Voti.IDvot AND Voti.Voto='" + TagFilter + "'"; }
return Helper.ExecuteScalar(cn,query,objLock);
}
private long GetNumOri() { return Helper.CountSimpleRecord(cn, "Links_Rac_Ori", "IDori", objLock); }
private long GetNumAuts() { return Helper.CountSimpleRecord(cn, "Links_Rac_Aut", "IDaut", objLock); }
private long GetNumTags() { return Helper.CountSimpleRecord(cn, "Links_Rac_Tag", "IDtag", objLock); }
private long GetNumVot() { return Helper.CountSimpleRecord(cn, "Links_Rac_Vot", "IDvot", objLock); }
/// <summary>
/// ritorna il riepilogo del DB:
/// </summary>
/// <returns>Stringa con il riepilogo del DB</returns>
public string Report {
get {
string report = "A69WD:\r\n\r\n";
report += string.Format("L'archivio contiene {0} racconti:\r\n", GetNumRacs().ToString("000"));
report += string.Format("> {0} non letti\r\n", GetNumRacs("Non Letto").ToString("000"));
report += string.Format("> {0} sorgenti\r\n", GetNumOri().ToString("00"));
report += string.Format("> {0} autori\r\n", GetNumAuts().ToString("000"));
report += string.Format("> {0} tags\r\n", GetNumTags().ToString("000"));
report += string.Format("> {0} voti\r\n", GetNumVot().ToString("000"));
return report;
}
}
/// <summary>
/// Metodo per trovare un identificativo di un racconto scelto casualmente fra quelli che soddisfano il filtro indicato.
/// </summary>
/// <param name="queryFilter">Eventuale query per filtrare i racconti selezionabili</param>
/// <returns>Identificativo del racconto scelto casualmente</returns>
public long GetRandomIDrac(string queryFilter = "") {
//long ID = -3;
//SQLiteDataReader rdr = null;
//lock (objLock) {
//try {
//// Preparo i comandi SQL da usare:
//string query = "SELECT Links_Rac_Vot.IDrac AS IDrac FROM Links_Rac_Vot, Voti WHERE Voti.Voto='Non Letto' AND Links_Rac_Vot.IDVot=Voti.IDvot ORDER BY RANDOM() LIMIT 1";
//if (!string.IsNullOrEmpty(queryFilter)) query = string.Format("SELECT Links_Rac_Vot.IDrac AS IDrac FROM Links_Rac_Vot, Voti WHERE Links_Rac_Vot.IDVot=Voti.IDvot AND {0} ORDER BY RANDOM() LIMIT 1", queryFilter);
//SQLiteCommand cmd = new SQLiteCommand(query, cn);
//rdr = cmd.ExecuteReader();
//while (rdr.Read()) { ID = (long)rdr["IDrac"]; }
//rdr.Close();
//rdr = null;
//} catch (Exception ex) {
//Logger.Error(string.Format("Error Code: {0} - Errore in {1}.{2}: {3}", "ER00070", System.Reflection.MethodInfo.GetCurrentMethod().DeclaringType.FullName, System.Reflection.MethodInfo.GetCurrentMethod().Name, ex.Message));
//ID = -2;
//}
//}
//return ID;
string query = "SELECT Links_Rac_Vot.IDrac AS IDrac FROM Links_Rac_Vot, Voti WHERE Voti.Voto='Non Letto' AND Links_Rac_Vot.IDVot=Voti.IDvot ORDER BY RANDOM() LIMIT 1";
if (!string.IsNullOrEmpty(queryFilter)) query = string.Format("SELECT Links_Rac_Vot.IDrac AS IDrac FROM Links_Rac_Vot, Voti WHERE Links_Rac_Vot.IDVot=Voti.IDvot AND {0} ORDER BY RANDOM() LIMIT 1", queryFilter);
return Helper.ExecuteScalar(cn, query, objLock);
}
public int UpdateVoto(long IDrac, string NewVoto) {
Logger.Warning("Funzione 'UpdateVoto(IDrac, NewVoto) ancora da fare.");
return -1;
}
#endregion
} //class DBTools } //class DBTools
+55
View File
@@ -70,6 +70,61 @@ namespace A69WD.Data {
/// <summary>
/// Esegue una query che ritorna un scalare
/// </summary>
/// <param name="query">Query da eseguire sul DB</param>
/// <returns>Scalare ritornato dalla query</returns>
public static long ExecuteScalar(SQLiteConnection conn, string query, object objLock) {
lock (objLock) {
try {
// Eseguo il comando
System.Data.SQLite.SQLiteCommand cm = new SQLiteCommand(query, conn);
long res = (long)cm.ExecuteScalar(System.Data.CommandBehavior.SingleResult);
return res;
} catch (Exception ex) {
if (ex.Message == "Object reference not set to an instance of an object.") {
// nessun record trovato che soddisfi la query
return 0;
} else {
Logger.Error(string.Format("Error Code: {0} - Errore in {1}.{2}: {3}", "ER00100", System.Reflection.MethodInfo.GetCurrentMethod().DeclaringType.FullName, System.Reflection.MethodInfo.GetCurrentMethod().Name, ex.Message));
return -1;
}
}
}
} // ExecuteScalar
/// <summary>
/// Conteggia il numero di record nella colonna indicata contenuti nella tabella indicata.
/// </summary>
/// <param name="conn">Connessione al DB</param>
/// <param name="tableName">Nome della tabella in cui fare la query</param>
/// <param name="columName">Nome del campo da contare</param>
/// <param name="objLock">Oggetto per il lock fra i thread</param>
/// <returns>Il numero di record trovati, oppure un codice negativo in caso di errore.</returns>
public static long CountSimpleRecord(SQLiteConnection conn, string tableName, string columName, object objLock) {
// Ricreo la query:
string query = $"SELECT count(Distinct {tableName}.{columName}) AS NUM FROM {tableName}";
lock (objLock) {
try {
// Eseguo il comando
System.Data.SQLite.SQLiteCommand cm = new SQLiteCommand(query, conn);
long res = (long)cm.ExecuteScalar(System.Data.CommandBehavior.SingleResult);
return res;
} catch (Exception ex) {
if (ex.Message == "Object reference not set to an instance of an object.") {
// nessun record trovato che soddisfi la query
return 0;
} else {
Logger.Error(string.Format("Error Code: {0} - Errore in {1}.{2}: {3}", "ER00100", System.Reflection.MethodInfo.GetCurrentMethod().DeclaringType.FullName, System.Reflection.MethodInfo.GetCurrentMethod().Name, ex.Message));
return -1;
}
}
}
}//CountSimpleRecord
}//class Helper }//class Helper
public enum SaveResult { public enum SaveResult {
+186
View File
@@ -0,0 +1,186 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using A69WD.Data;
namespace A69WD {
public class Navigator {
#region Fields: buffer, indice, DB
/// <summary>
/// Array interno che mi memorizza gli ID degli ultimi racconti visualizzati
/// </summary>
private long[] buffer = null;
/// <summary>
/// Indice del racconto attualmente visualizzato
/// </summary>
private long indice = 0;
/// <summary>
/// Interfaccia con il database
/// </summary>
private DBTools DB = null;
#endregion
#region Costrutore
/// <summary>
/// Costruttore
/// </summary>
/// <param name="size">Dimensione del buffer, cioè numero di racconti di cui tener memoria</param>
public Navigator(int size) {
buffer = new long[size];
for (int i = 0; i < size; i++) { buffer[i] = -1; }
DB = App.DB;
}
#endregion
#region Metodi di navigazione:
/// <summary>
/// Ritorna l'ID del racconto attualmente visualizzato
/// 0 indica la pagina home con il riepilogo del ATDB
/// </summary>
public long ActualID { get { return buffer[indice]; } }
/// <summary>
/// Ritorna il riepilogo dell'archivio
/// </summary>
public string Home { get { return DB.Report; } }
/// <summary>
/// Ritorna il testo del racconto successivo a quello visualizzato attualmente, nel buffer di navigazione
/// </summary>
public string Forward {
get {
// Aggiorno indice attuale:
long tmp = indice + 1;
if (tmp >= buffer.Length) tmp = 0;
if (buffer[tmp] != -1) indice = tmp;
// Ritorno il testo del racconto:
return DB.GetRacById(buffer[indice]).ToString();
}
}
/// <summary>
/// Ritorna il testo del racconto precedente a quello visualizzato attualmente, nel buffer di navigazione
/// </summary>
public string Backward {
get {
// Aggiorno indice attuale:
long tmp = indice - 1;
if (tmp < 0) tmp = buffer.Length - 1;
if (buffer[tmp] != -1) indice = tmp;
// Ritorno il testo del racconto:
return DB.GetRacById(buffer[indice]).ToString();
}
}
/// <summary>
/// Ritorna il testo del racconto con ID successivo a quello visualizzato attualmente
/// </summary>
public string Next {
get {
// Aggiorno indice attuale:
long newID = buffer[indice];
if (newID > 0) {
newID++;
return SwitchTo(newID);
} else {
return Refresh;
}
}
}
/// <summary>
/// Ritorna il testo del racconto con ID precedente a quello visualizzato attualmente
/// </summary>
public string Previous {
get {
// Aggiorno indice attuale:
long newID = buffer[indice];
if (newID > 1) {
newID--;
return SwitchTo(newID);
} else {
return Refresh;
}
}
}
/// <summary>
/// Ricarica il testo del racconto attuale
/// </summary>
public string Refresh {
get {
if (buffer[indice] > 0) {
return DB.GetRacById(buffer[indice]).ToString();
} else { return Home; }
}
}
/// <summary>
/// Ritorna il testo di un racconto scelto casualmente nel DB
/// </summary>
public string RandomRac {
get {
// Aggiorno indice attuale:
indice++;
if (indice >= buffer.Length) indice = 0;
buffer[indice] = DB.GetRandomIDrac();
// Ritorno il testo del racconto:
return DB.GetRacById(buffer[indice]).ToString();
}
}
/// <summary>
/// Ritorna l'ID del nuovo racconto prendendo quello indicato
/// </summary>
/// <param name="NewIdRac">ID del racconto da visualizzare</param>
/// <returns></returns>
public string SwitchTo(long NewIdRac) {
// Aggiorno indice attuale:
indice++;
if (indice >= buffer.Length) indice = 0;
buffer[indice] = NewIdRac;
// Ritorno il testo del racconto:
cRac r = DB.GetRacById(buffer[indice]);
if (r != null) {
return r.ToString();
} else {
return $"Indice {NewIdRac} non valido";
}
}
/// <summary>
/// Ricarica il testo del racconto attuale
/// </summary>
public string UpdateVoto(string newVoto) {
long id = buffer[indice];
if (id > 0) {
DB.UpdateVoto(id, newVoto);
return DB.GetRacById(id).ToString();
} else { return Home; }
}
#endregion
}//class Navigator
}//namespace A69WD
+174
View File
@@ -287,6 +287,180 @@ namespace A69WD.Net {
return rac; return rac;
} }
public cRac EstraiRac(HtmlDocument doc) {
/*
* Analisi html dei racconti aggiornata al 2025/12/27:
*
*
* Per ciascun file html, si ha un unico racconto che ha un formato interno pari a:
* <html xmlns="http://www.w3.org/1999/xhtml">
* <body>
* ...
* <div class="targhetta_racconti" style=" width:100%; background-color:#5d5d5d;">incesto</div>
* ...
* <h1 class="titolone_nero" ...>Mia Madre , La mia Amante</h1>
* <strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;di<a href="/user/Bambino">Bambino</a>
* ...
* <div style="float:left; margin-right:5px; color: #9999CC; ">
* <span class="text_grigio" style="line-height:1.6em; color: #9999CC; font-size:13px;">&nbsp;<strong>Scritto il</strong> 22.08.2015 &nbsp;&nbsp; | &nbsp;&nbsp;
* <strong>Letture:</strong> 8.947&nbsp;&nbsp;| &nbsp;&nbsp;
* <strong>Votazione 8.0:</strong></span>
* </div>
* ...
* <div class="testoracc" style="color:#666666; text-align:justify; padding:20px 20px 0px 0px;">
* Eliminare i DIV interni che hanno cose grafiche
* Il testo è quello che rimane.
* </div>
* </body>
* </html>
*
* quindi i dati del racconto che si possono estrapolare sono:
* Titolo: --> Testo del nodo <h1 class="titolone_nero">
* SubTitle: --> Sempre Vuoto
* Autore: --> Testo del nodo <strong><a>
* Creato: --> Estrarre la parte dal <div style="float:left; margin-right:5px; color: #9999CC; ">
* Tags: --> Testo del nodo div class="targhetta_racconti">
* Trama: --> Testo del nodo <div class="testoracc"> a cui si levano i DIV interni.
* Notes: --> SrcFile - Nome del file che si analizza
* Origini: --> Sempre l'ID della sorgente web
* Voto: --> Sempre "Non Letto"
* Updated: --> Data attuale
*
*/
cRac rac = new cRac();
HtmlNodeCollection nodes;
try {
Console.WriteLine($"A69 - Importo: {FileName}");
// Ricavo il nodo radice del racconto:
HtmlNode root = doc.DocumentNode;
if (root == null) {
// racconto non presente
return null;
}
#region Origini: --> Sempre l'ID della sorgente web
rac.Origini = new List<string> { ID };
#endregion
#region Titolo: --> Testo del nodo <h1 class="titolone_nero">
try {
nodes = root.SelectNodes("//h1[@class='titolone_nero']");
rac.Title = cTools.FormattaTesto(nodes[0].InnerText.Trim(), false);
if (string.IsNullOrEmpty(rac.Title)) {
Logger.Error($"A69 - Import - No Title - {FileName}");
return null;
}
} catch (Exception ex) { Logger.Error(string.Format("Fallita estrazione titolo dal file {0}\r\n{1}", FileName, ex.Message)); return null; }
#endregion
#region SubTitle: --> Sempre Vuoto
rac.SubTitle = "";
#endregion
#region Autore: --> Testo del nodo <strong><a>
try {
// Autore --> Testo del nodo <span class="text_grigio><a>"
nodes = root.SelectNodes("//span[@class='text_grigio']//a");
List<string> items = new List<string>();
foreach (HtmlNode nd in nodes) {
string aut = nd.ParentNode.InnerText.Replace("&nbsp;", "").Trim();
if (aut.StartsWith("di")) {
items.Add(aut.Replace("di", "").Trim());
}
}
items.Sort();
string tmp = "";
rac.Autori = new List<string>();
// Rimuovo eventuali duplicati
foreach (string aut in items) {
if (tmp != aut) {
rac.Autori.Add(aut);
tmp = aut;
}
}
if (rac.Autori == null || string.IsNullOrEmpty(rac.Autori[0])) {
Logger.Error($"A69 - Import - No Autors - {FileName}");
return null;
}
} catch (Exception ex) { Logger.Error(string.Format("Fallita estrazione autore dal file {0}\r\n{1}", FileName, ex.Message)); return null; }
#endregion
#region Creato: --> Estrarre la parte dal <div style="float:left; margin-right:5px; color: #9999CC; ">
rac.Creato = DateTime.Now;
try {
// Creato --> Estrarre la prima parte dal <span class="text_grigio"> che ha il testo "Data|Visite|Commenti":
nodes = root.SelectNodes("//span[@class='text_grigio']");
foreach (HtmlNode nd in nodes) {
string txt = nd.InnerText.Trim().Replace("&nbsp;", "");
string[] parts = txt.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length == 3) {
CultureInfo culture = CultureInfo.CreateSpecificCulture("it-IT");
DateTimeStyles styles = DateTimeStyles.None;
DateTime tmpDT = DateTime.Now;
if (!DateTime.TryParse(parts[0].Trim(), culture, styles, out tmpDT)) {
Logger.Error($"A69 - Import - No data - {FileName}");
}
rac.Creato = tmpDT;
}
}
} catch (Exception ex) { Logger.Warning(string.Format("Data non riconosciuta nel file {0}\r\n{1}", FileName, ex.Message)); return null; }
#endregion
#region Updated: --> Data attuale
rac.Updated = DateTime.Now;
#endregion
#region Tags: --> Testo del nodo div class="targhetta_racconti">
try {
nodes = root.SelectNodes("//div[@class='targhetta_racconti']");
List<string> items = new List<string>();
foreach (HtmlNode nd in nodes) {
items.Add(cTools.FormattaTesto(nd.InnerText.Replace("genere", "").Trim(), false));
}
//items.Sort();
items = items
.OrderBy(s => s) // ordina alfabeticamente
.Distinct() // elimina duplicati
.ToList();
Format_Insert_Tags(rac, items); // rac.Tags = items;
} catch (Exception ex) { Logger.Warning(string.Format("Fallita estrazione Tags dal file {0}\r\n{1}", FileName, ex.Message)); return null; }
#endregion
#region Trama: --> Testo del nodo <div class="testoracc"> a cui si levano i DIV interni.
try {
nodes = root.SelectNodes("//div[@class='testoracc']");
foreach (HtmlNode nd in nodes) {
foreach (HtmlNode n in nd.ChildNodes) {
if (n.Name.ToUpper() == "#TEXT") { rac.Trama += cTools.FormattaTesto(n.InnerText.Trim(), false); }
if (n.Name.ToUpper() == "BR") { rac.Trama += "\r"; }
if (n.Name.ToUpper() == "DIV") {; }
}
}
} catch (Exception ex) { Logger.Error(string.Format("Fallita estrazione Trama dal file {0}\r\n{1}", FileName, ex.Message)); return null; }
#endregion
#region Voto: --> Sempre "Non Letto"
rac.Voto = "Non Letto";
#endregion
#region Notes: --> SrcFile - Nome del file che si analizza
rac.Notes = new List<Data.cNota>();
rac.Notes.Add(new Data.cNota("SrcFile", System.IO.Path.GetFileName(FileName)));
#endregion
// Formalizzo esito estrazione:
if (!rac.Validate()) {
rac = null;
}
} catch (Exception ex) {
Logger.Error($"A69 - Import Error - {FileName}: {ex.Message}");
Console.WriteLine($"A69 - Import Error - {FileName}: {ex.Message}");
return null;
}
return rac;
}
protected virtual void Format_Insert_Tags(Data.cRac rac, List<string> items) { protected virtual void Format_Insert_Tags(Data.cRac rac, List<string> items) {
// Per ora riporto tutti i tag rilevati, mentre in futuro dovrò: // Per ora riporto tutti i tag rilevati, mentre in futuro dovrò:
+5
View File
@@ -3,6 +3,9 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using A69WD.Data;
using HtmlAgilityPack;
namespace A69WD.Net { namespace A69WD.Net {
@@ -42,6 +45,8 @@ namespace A69WD.Net {
eLinkState Status { get; set; } eLinkState Status { get; set; }
cRac EstraiRac(HtmlDocument doc);
}//interface iLink }//interface iLink
}//namespace A69WD.Net }//namespace A69WD.Net
+18 -2
View File
@@ -32,8 +32,24 @@ using System.Runtime.InteropServices;
// È possibile specificare tutti i valori oppure impostare valori predefiniti per i numeri relativi alla revisione e alla build // È 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: // usando l'asterisco '*' come illustrato di seguito:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.4.0.0")] [assembly: AssemblyVersion("0.5.0.0")]
[assembly: AssemblyFileVersion("0.4.0.0")] [assembly: AssemblyFileVersion("0.5.0.0")]
/*
*
* Vrs 0.5.0.0
*
* Compilata da CSiCoAlm il 2025/12/29
* Inserito reader basilare (solo lettura, navigazione random o sequenziale)
* Integrato import e skraping sul reader
*
* ToDo:
* - Aggiungere gestione parallela della FIFO secondo vecchi modello per aumentare il feedback alla UI
* - Inserire anche l'estrazione dei racconti
* - Inserire funzionalità avanzate sul lettore
*
*/
/* /*
+18 -33
View File
@@ -32,26 +32,14 @@ namespace A69WD.Service {
// HttpClient autenticato (fornito da AuthService) // HttpClient autenticato (fornito da AuthService)
private iSiteType _site; private iSiteType _site;
public Service_Crawler(Label lblInCorso, ProgressBar pbStatus) {
_semaphore = new SemaphoreSlim(Cfg.Settings.nThread);
_lblInCorso = lblInCorso;
_progressBar = pbStatus;
}
// Riferimenti ai controlli UI per aggiornare i contatori e la progress bar // Riferimenti ai controlli UI per aggiornare i contatori e la progress bar
private readonly Label _lblInCorso; private readonly StatusStrip _sb;
//private readonly Label _lblCompletati;
//private readonly Label _lblDaFare;
//private readonly Label _lblErrori;
private readonly ProgressBar _progressBar;
public Service_Crawler(StatusStrip sb) {
_semaphore = new SemaphoreSlim(Cfg.Settings.nThread);
_sb = sb;
}
@@ -93,13 +81,13 @@ namespace A69WD.Service {
try { try {
List<iLink> urls = await _site.CrawlPageAsync(link); List<iLink> urls = await _site.CrawlPageAsync(link);
Logger.Information("ProcessQueue: end url " + link.FileName + " - URL trovati: " + urls.Count.ToString("000")); Logger.Information("ProcessQueue: end url " + link.FileName + " - URL trovati: " + urls.Count.ToString("000"));
foreach (iLink url in urls) { foreach (iLink url in urls) {
if (url.Validate) { if (url.Validate) {
// Logger.Warning("URL Validato: " + url.FileName); // Logger.Warning("URL Validato: " + url.FileName);
App.DB.LinkLog(url); App.DB.LinkLog(url);
_urlQueue.Add(url); _urlQueue.Add(url);
//} else { //} else {
// Logger.Warning("URL NON Validato: " + url.FileName); // Logger.Warning("URL NON Validato: " + url.FileName);
} }
} }
} catch (Exception ex) { } catch (Exception ex) {
@@ -121,30 +109,27 @@ namespace A69WD.Service {
/// Aggiorna i contatori e la progress bar sulla UI. /// Aggiorna i contatori e la progress bar sulla UI.
/// </summary> /// </summary>
private void UpdateCounters() { private void UpdateCounters() {
if (_lblInCorso.InvokeRequired) { if (_sb.InvokeRequired) {
_lblInCorso.Invoke(new Action(UpdateCounters)); _sb.Invoke(new Action(UpdateCounters));
return; return;
} }
int daFare = _urlQueue.Count; int daFare = _urlQueue.Count;
_lblInCorso.Text = $"In corso: {_inCorso} - Completati: {_completati} - Errori: {_errori} - Da fare: {daFare}";
int totale = _inCorso + _completati + _errori + daFare; int totale = _inCorso + _completati + _errori + daFare;
int fatti = _completati + _errori; int fatti = _completati + _errori;
_progressBar.Maximum = totale > 0 ? totale : 1; //_sb.Items["sbStatusLabel"].Text = $"In corso: {_inCorso} - Completati: {_completati} - Errori: {_errori} - Da fare: {daFare}";
_progressBar.Value = fatti; _sb.Items["sbStatusLabel"].Text = $"{totale}|{_inCorso}|{fatti}|{_errori}";
_sb.Items["sbStatusLabel"].ToolTipText = "Totali | In Corso | Fatti | Error";
(_sb.Items["sbProgressBar"] as ToolStripProgressBar).Maximum = totale > 0 ? totale : 1;
(_sb.Items["sbProgressBar"] as ToolStripProgressBar).Value = fatti;
} }
} }
} }
+9 -10
View File
@@ -19,17 +19,15 @@ namespace A69WD.Service {
// Thread worker che consuma la coda // Thread worker che consuma la coda
private Thread _workerThread; private Thread _workerThread;
private readonly Label _lblInCorso; private readonly StatusStrip _sb;
private readonly ProgressBar _progressBar;
private string _path; private string _path;
// Contatori // Contatori
private int _totali = 0; private int _totali = 0;
private int _completati = 0; private int _completati = 0;
private int _errori = 0; private int _errori = 0;
public Service_Importer(Label lblInCorso, ProgressBar pbStatus) { public Service_Importer(StatusStrip sb) {
_lblInCorso = lblInCorso; _sb = sb;
_progressBar = pbStatus;
} }
public void StartWorker(string path) { public void StartWorker(string path) {
@@ -104,17 +102,18 @@ namespace A69WD.Service {
private void UpdateCounters() { private void UpdateCounters() {
if (_lblInCorso.InvokeRequired) { if (_sb.InvokeRequired) {
_lblInCorso.Invoke(new Action(UpdateCounters)); _sb.Invoke(new Action(UpdateCounters));
return; return;
} }
int daFare = _totali - _completati - _errori; int daFare = _totali - _completati - _errori;
_lblInCorso.Text = $"Totali: {_totali} - Completati: {_completati} - Errori: {_errori} - Da fare: {daFare}"; _sb.Items["sbStatusLabel"].Text = $"{_totali}|{_completati}|{_errori}";
_sb.Items["sbStatusLabel"].ToolTipText = "Totali | Completati | Error";
_progressBar.Maximum = _totali > 0 ? _totali : 1; (_sb.Items["sbProgressBar"] as ToolStripProgressBar).Maximum = _totali > 0 ? _totali : 1;
_progressBar.Value = _completati + _errori; (_sb.Items["sbProgressBar"] as ToolStripProgressBar).Value = _completati + _errori;
} }
+1 -1
View File
@@ -20,7 +20,7 @@
<TextEditor>C:\Program Files\Notepad++\notepad++.exe</TextEditor> <TextEditor>C:\Program Files\Notepad++\notepad++.exe</TextEditor>
<!-- Numero di thread secondari. --> <!-- Numero di thread secondari. -->
<nThread>9</nThread> <nThread>3</nThread>
</Cfg> </Cfg>
+12
View File
@@ -5,6 +5,7 @@ using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using A69WD.Data;
using A69WD.Net; using A69WD.Net;
using HtmlAgilityPack; using HtmlAgilityPack;
@@ -239,6 +240,17 @@ namespace A69WD.Site {
} }
#endregion #endregion
#region Estraggo il racconto dal file e lo inserisco nel DB
if (lk.FileName.StartsWith("A69_")) {
// Link ad un racconto
cRac rac = lk.EstraiRac(tdoc);
if (rac != null) {
// Racconto estratto correttamente, lo salvo sul DB
App.DB.ImportRac(rac);
}
}
#endregion
lk.Status = eLinkState.End; lk.Status = eLinkState.End;
App.DB.LinkLog(lk); App.DB.LinkLog(lk);
} }
-153
View File
@@ -1,153 +0,0 @@
namespace A69WD {
partial class frmDownloader {
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent() {
this.btnClose = new System.Windows.Forms.Button();
this.btnDownloadAll = new System.Windows.Forms.Button();
this.lblST = new System.Windows.Forms.Label();
this.btnImportLinks = new System.Windows.Forms.Button();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
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
//
this.btnClose.Location = new System.Drawing.Point(348, 12);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(79, 33);
this.btnClose.TabIndex = 14;
this.btnClose.Text = "Close";
this.btnClose.UseVisualStyleBackColor = true;
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// btnDownloadAll
//
this.btnDownloadAll.Location = new System.Drawing.Point(12, 12);
this.btnDownloadAll.Name = "btnDownloadAll";
this.btnDownloadAll.Size = new System.Drawing.Size(79, 33);
this.btnDownloadAll.TabIndex = 11;
this.btnDownloadAll.Text = "Start A69";
this.btnDownloadAll.UseVisualStyleBackColor = true;
this.btnDownloadAll.Click += new System.EventHandler(this.btnDownloadAll_Click);
//
// lblST
//
this.lblST.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.lblST.Dock = System.Windows.Forms.DockStyle.Bottom;
this.lblST.Location = new System.Drawing.Point(0, 73);
this.lblST.Name = "lblST";
this.lblST.Size = new System.Drawing.Size(433, 22);
this.lblST.TabIndex = 9;
this.lblST.Text = "Status";
this.lblST.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// btnImportLinks
//
this.btnImportLinks.Enabled = false;
this.btnImportLinks.Location = new System.Drawing.Point(97, 12);
this.btnImportLinks.Name = "btnImportLinks";
this.btnImportLinks.Size = new System.Drawing.Size(79, 33);
this.btnImportLinks.TabIndex = 15;
this.btnImportLinks.Text = "From DB";
this.btnImportLinks.UseVisualStyleBackColor = true;
this.btnImportLinks.Click += new System.EventHandler(this.btnImportLinks_Click);
//
// openFileDialog1
//
this.openFileDialog1.FileName = "openFileDialog1";
this.openFileDialog1.Filter = "File Testo|*.tes|Tutti i file|*.*";
//
// btnShowLog
//
this.btnShowLog.Location = new System.Drawing.Point(263, 12);
this.btnShowLog.Name = "btnShowLog";
this.btnShowLog.Size = new System.Drawing.Size(79, 33);
this.btnShowLog.TabIndex = 17;
this.btnShowLog.Text = "Show Log";
this.btnShowLog.UseVisualStyleBackColor = true;
this.btnShowLog.Click += new System.EventHandler(this.btnShowLog_Click);
//
// pbST
//
this.pbST.Dock = System.Windows.Forms.DockStyle.Bottom;
this.pbST.Location = new System.Drawing.Point(0, 55);
this.pbST.Name = "pbST";
this.pbST.Size = new System.Drawing.Size(433, 18);
this.pbST.TabIndex = 18;
//
// btnImport
//
this.btnImport.Location = new System.Drawing.Point(182, 12);
this.btnImport.Name = "btnImport";
this.btnImport.Size = new System.Drawing.Size(79, 33);
this.btnImport.TabIndex = 19;
this.btnImport.Text = "Import Rac";
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);
this.Controls.Add(this.btnImportLinks);
this.Controls.Add(this.btnClose);
this.Controls.Add(this.btnDownloadAll);
this.Controls.Add(this.lblST);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "frmDownloader";
this.Text = "frmDownloader";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.Button btnDownloadAll;
private System.Windows.Forms.Label lblST;
private System.Windows.Forms.Button btnImportLinks;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.Button btnShowLog;
private System.Windows.Forms.ProgressBar pbST;
private System.Windows.Forms.Button btnImport;
private System.Windows.Forms.Button btnTest;
}
}
-259
View File
@@ -1,259 +0,0 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
using System.Net;
using static System.Windows.Forms.LinkLabel;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using A69WD.Site;
using A69WD.Net;
using System.Collections.Concurrent;
using System.Xml.Linq;
using A69WD.Service;
using A69WD.Data;
namespace A69WD {
public partial class frmDownloader : Form {
// Coda thread-safe di URL da scaricare
private readonly BlockingCollection<iLink> _urlQueue = new BlockingCollection<iLink>(new ConcurrentQueue<iLink>());
// Semaforo per limitare il numero massimo di download simultanei
private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1);
public frmDownloader() {
InitializeComponent();
this.Text = String.Format("A69WD - Dowloader Testi Vrs {0}", cTools.AssemblyVersion);
//engine = new cA69Engine();
//engine.Updating += Engine_Updating;
}
//cA69Engine engine = null;
/// <summary>
/// Metodo per scansionare i link da un file di testo ed inserirli come da downloadare se non ci sono già
/// </summary>
private void btnImportLinks_Click(object sender, EventArgs e) {
//// Chiedo il file di testo da caricare
//lblST.Text = " ";
//this.openFileDialog1.InitialDirectory = Cfg.Settings.PathApplicationRoot;
//if (this.openFileDialog1.ShowDialog() == DialogResult.OK) {
// lblST.Text = string.Format("Importati {0} link", engine.ImportLinkFromFile(openFileDialog1.FileNames[0]));
//}
}
private async void btnDownloadAll_Click(object sender, EventArgs e) {
btnDownloadAll.Enabled = false;
// - Creo istanza del client per il sito con autenticazione:
lblST.Text = DateTime.Now.ToString() + " - Login";
A69WD.Site.iSiteType siteA69 = new cSite_A69();
// - Eseguo l'autenticazione
bool res = await siteA69.Authenticate();
if (res) {
lblST.Text = DateTime.Now.ToString() + " - sito loggato: " + res.ToString();
Logger.Information("Sito correttamente loggato.");
} else {
Logger.Information("Errore di autenticazione al sito.");
return;
}
// - Verifico path per il download
if (!System.IO.Directory.Exists(Cfg.Settings.PathDownloadWorking)) System.IO.Directory.CreateDirectory(Cfg.Settings.PathDownloadWorking);
// // Test downloadando tutti i 10 primi link per categoria
// List<iLink> links = cLink_A69.GetStartLink();
// int i = 1;
// foreach (iLink link in links) {
// lblST.Text = "Start url " + link.FileName;
// Logger.Information("Start url " + link.FileName);
// await siteA69.CrawlPageAsync(link);
// Logger.Information(" end url " + link.FileName);
// i++;
// }
// // Inserisco i link iniziali sulla coda dei download:
// if (!cLink_A69.InsertStartLink(_urlQueue)) {
// lblST.Text = "Inserimento A69 start link fault.";
// return;
// }
// lblST.Text = "In coda vi sono: " + _urlQueue.Count.ToString() + " url.";
//
// // Test estrazione link dal primo indice:
// iLink link = new cLink_A69("https://www.annunci69.it/racconti-erotici/racconti_lista.php?genere=altro&pagina=1", "Idx_altro_1.html");
// Logger.Information("Start url " + link.FileName);
// List<iLink> urls = await siteA69.CrawlPageAsync(link);
// Logger.Information(" end url " + link.FileName + " - URL trovati: " + urls.Count.ToString("000"));
// foreach (iLink url in urls) { _urlQueue.Add(url); }
// lblST.Text = "In coda vi sono: " + _urlQueue.Count.ToString() + " url.";
// Preparo il servizio
serviceCrawler = new Service_Crawler(lblST, pbST);
// Inserisco i link iniziali nella coda
if (!cLink_A69.InsertStartLink(serviceCrawler)) {
lblST.Text = "Inserimento A69 start link fault.";
return;
}
// avvio il servizio
serviceCrawler.StartWorker(siteA69);
}
private Service_Crawler serviceCrawler = null;
private void btnShowLog_Click(object sender, EventArgs e) {
cTools.ShowOnNotepad(Cfg.Settings.PathFileLogs);
}
private void btnHide_Click(object sender, EventArgs e) {
if (MessageBox.Show("Metodo ancora da terminare, la finestra non sarà più visibile, killare il processo", "ATTENZIONE", MessageBoxButtons.OKCancel) == DialogResult.OK){
this.Hide();
}
}
private void btnClose_Click(object sender, EventArgs e) {
//if (engine.Stop()) this.Close();
// fermo i servizi
if (serviceCrawler != null) serviceCrawler.StopWorker();
if (serviceImporter != null) serviceImporter.StopWorker();
this.Close();
}
#region Gestione eventi dal engine
//
// private void Engine_Updating(object sender, EngineEventArgs e) { EngineUpdatingStatus(e.Message, e.NTot, e.NtoDown, e.NDown); }
//
// delegate void EngineUpdatingStatusCallback(string Message, int NTot, int NtoDown, int NDown);
// private void EngineUpdatingStatus(string Message, int NTot, int NtoDown, int NDown) {
// try {
// // InvokeRequired required compares the thread ID of the
// // calling thread to the thread ID of the creating thread.
// // If these threads are different, it returns true.
// if (lblST.InvokeRequired) {
// EngineUpdatingStatusCallback callBack = new EngineUpdatingStatusCallback(EngineUpdatingStatus);
// this.Invoke(callBack, new object[] { Message, NTot, NtoDown, NDown });
// } else {
// lblST.Text = string.Format("{4} - {3} | {2} | {1} - {0}", Message, NTot, NtoDown, NDown, DateTime.Now.ToString("HH:mm:ss"));
// Logger.Information(lblST.Text);
// }
// } catch (Exception ex) {
// Logger.Log(new object[] { "Error Code: ER05553", "Errore in EngineUpdatingStatus():", ex });
// }
// }
//
#endregion
private void btnImport_Click(object sender, EventArgs e) {
// string fp = "C:\\Commesse\\_zPrivate\\A69WD\\Test\\Down\\__A69_altro_Collarini-e-fantasie_166756.html";
// cLink_A69 lk = new cLink_A69("Tmp", "tmp");
// cRac rac = await lk.EstraiRac(fp);
// if (rac != null) {
// //foreach (string tag in rac.Tags) {
// for (int i = 0; i<rac.Tags.Count; i++) {
// Console.WriteLine(rac.Tags[i]);
// }
// // Racconto estratto correttamente, lo salvo sul DB
// App.DB.ImportRac(rac);
// }
// Preparo il servizio
serviceImporter = new Service_Importer(lblST, pbST);
// Per ora uso la directory di default, poi metteremo selezione
string path = Cfg.Settings.PathDownloadWorking;
// avvio il servizio
serviceImporter.StartWorker(path);
}
private Service_Importer serviceImporter = null;
private async void btnTest_Click(object sender, EventArgs e) {
// // Test dell'esportazione in html
// 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";
// // Test funzione di lettura dal DB
// Logger.Information("-- Start test 100*50 letture originali --");
// DateTime start = DateTime.Now;
// for (int j = 0; j < 100; j++) {
// for (int i = 1; i <= 50; i++) {
// cRac rac = App.DB.GetRacById_Orig(i);
// if (rac.IDrac != i) Logger.Information($"Letto ID={i.ToString()}");
// }
// }
// TimeSpan tp = start-DateTime.Now;
// Logger.Information($" End test in {tp.ToString()}");
// Logger.Information("-- Start test 100*50 letture nuove --");
// start = DateTime.Now;
// for (int j = 0; j < 100; j++) {
// for (int i = 1; i <= 50; i++) {
// cRac rac = App.DB.GetRacById(i);
// if (rac.IDrac != i) Logger.Information($"Letto ID={i.ToString()}");
// }
// }
// tp = start - DateTime.Now;
// Logger.Information($" End test in {tp.ToString()}");
// Test di salvataggio sul DB
// leggo 3 nuovi racconti
string file = @"C:\Commesse\_zPrivate\A69WD\Test\Down\A69_altro_Decisione-estrema_133364.html";
cLink_A69 lk = new cLink_A69(file, "A69_altro_Decisione-estrema_133364.html");
cRac rac1 = await lk.EstraiRac(file);
file = @"C:\Commesse\_zPrivate\A69WD\Test\Down\A69_altro_Decisione_133364 - Copy.html";
lk = new cLink_A69(file, "A69_altro_Decisione_133364 - Copy.html");
cRac rac2 = await lk.EstraiRac(file);
file = @"C:\Commesse\_zPrivate\A69WD\Test\Down\A69_altro_Dammi-un-bacio_153877.html";
lk = new cLink_A69(file, "A69_altro_Dammi-un-bacio_153877.html");
cRac rac3 = await lk.EstraiRac(file);
file = @"C:\Commesse\_zPrivate\A69WD\Test\Down\A69_altro_dammi-la-mano_157904.html";
lk = new cLink_A69(file, "A69_altro_dammi-la-mano_157904.html");
cRac rac4 = await lk.EstraiRac(file);
// // Controprova:
// var res1 = App.DB.ImportRac(rac1);
// var res2 = App.DB.ImportRac(rac2);
// var res3 = App.DB.ImportRac(rac3);
// var res4 = App.DB.ImportRac(rac4);
// Provo a salvarli
var res1 = App.DB.SalvaRacconto(rac1);
var res2 = App.DB.SalvaRacconto(rac2);
var res3 = App.DB.SalvaRacconto(rac3);
var res4 = App.DB.SalvaRacconto(rac4);
//
}
}//class frmDownloader
}//namespace A69WD
+120
View File
@@ -0,0 +1,120 @@
namespace A69WD.UI {
partial class frmReader {
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent() {
this.rtb = new System.Windows.Forms.RichTextBox();
this.sb = new System.Windows.Forms.StatusStrip();
this.sbMessage = new System.Windows.Forms.ToolStripStatusLabel();
this.sbProgressBar = new System.Windows.Forms.ToolStripProgressBar();
this.sbStatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
this.sb.SuspendLayout();
this.SuspendLayout();
//
// rtb
//
this.rtb.BackColor = System.Drawing.Color.White;
this.rtb.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.rtb.Dock = System.Windows.Forms.DockStyle.Fill;
this.rtb.Font = new System.Drawing.Font("Verdana", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.rtb.Location = new System.Drawing.Point(0, 0);
this.rtb.Name = "rtb";
this.rtb.Size = new System.Drawing.Size(700, 420);
this.rtb.TabIndex = 3;
this.rtb.Text = "";
this.rtb.KeyDown += new System.Windows.Forms.KeyEventHandler(this.KeyDownAnalisi);
//
// sb
//
this.sb.AutoSize = false;
this.sb.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.sbMessage,
this.sbProgressBar,
this.sbStatusLabel});
this.sb.Location = new System.Drawing.Point(0, 420);
this.sb.Name = "sb";
this.sb.Size = new System.Drawing.Size(700, 24);
this.sb.TabIndex = 2;
this.sb.Text = "statusStrip1";
//
// sbMessage
//
this.sbMessage.BorderSides = ((System.Windows.Forms.ToolStripStatusLabelBorderSides)((((System.Windows.Forms.ToolStripStatusLabelBorderSides.Left | System.Windows.Forms.ToolStripStatusLabelBorderSides.Top)
| System.Windows.Forms.ToolStripStatusLabelBorderSides.Right)
| System.Windows.Forms.ToolStripStatusLabelBorderSides.Bottom)));
this.sbMessage.BorderStyle = System.Windows.Forms.Border3DStyle.SunkenInner;
this.sbMessage.Name = "sbMessage";
this.sbMessage.Size = new System.Drawing.Size(452, 19);
this.sbMessage.Spring = true;
this.sbMessage.Tag = "Messaggi";
this.sbMessage.Text = "Messaggi";
this.sbMessage.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.sbMessage.ToolTipText = "Messaggio";
//
// sbProgressBar
//
this.sbProgressBar.Name = "sbProgressBar";
this.sbProgressBar.Size = new System.Drawing.Size(100, 18);
this.sbProgressBar.Tag = "ProgressBar";
this.sbProgressBar.ToolTipText = "Percentuale di lavoro";
//
// sbStatusLabel
//
this.sbStatusLabel.AutoSize = false;
this.sbStatusLabel.BorderSides = ((System.Windows.Forms.ToolStripStatusLabelBorderSides)((((System.Windows.Forms.ToolStripStatusLabelBorderSides.Left | System.Windows.Forms.ToolStripStatusLabelBorderSides.Top)
| System.Windows.Forms.ToolStripStatusLabelBorderSides.Right)
| System.Windows.Forms.ToolStripStatusLabelBorderSides.Bottom)));
this.sbStatusLabel.BorderStyle = System.Windows.Forms.Border3DStyle.SunkenInner;
this.sbStatusLabel.Name = "sbStatusLabel";
this.sbStatusLabel.Size = new System.Drawing.Size(100, 19);
this.sbStatusLabel.Tag = "Label";
this.sbStatusLabel.ToolTipText = "Stato di eventuali operazioni in background";
//
// frmReader
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(700, 444);
this.ControlBox = false;
this.Controls.Add(this.rtb);
this.Controls.Add(this.sb);
this.Name = "frmReader";
this.Text = "PlugIn_App_Reader.UI Reader (DB vrs1.3, App" +
" vrsX.X.X.X)";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmReader_FormClosing);
this.sb.ResumeLayout(false);
this.sb.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.RichTextBox rtb;
private System.Windows.Forms.StatusStrip sb;
private System.Windows.Forms.ToolStripStatusLabel sbMessage;
private System.Windows.Forms.ToolStripProgressBar sbProgressBar;
private System.Windows.Forms.ToolStripStatusLabel sbStatusLabel;
}
}
+737
View File
@@ -0,0 +1,737 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using A69WD.Data;
using A69WD.Net;
using A69WD.Service;
using A69WD.Site;
namespace A69WD.UI {
public partial class frmReader : Form {
MenuItem mSkrStart;
MenuItem mSkrStop;
MenuItem mImpStart;
MenuItem mImpStop;
private Service_Crawler serviceCrawler = null;
private Service_Importer ServiceImporter = null;
A69WD.Site.iSiteType siteA69 = null;
public frmReader() {
InitializeComponent();
// Imposto caption:
this.Text = String.Format("A69WD - Reader Vrs {0}", cTools.AssemblyVersion);
// Imposto field interni:
nav = new Navigator(25);
// Visualizzo la pagina iniziale di riepilogo dell'archivio
rtb.Text = nav.Home;
// Aggiorno la status bar
sbMessage.Text = string.Format("Racconto {0}", nav.ActualID.ToString("00000"));
// Menu comandi skraping:
MenuItem mSkr = new MenuItem("Skraping");
mSkrStart = new MenuItem("Start", MenuItem_Skraping_Start_Click, Shortcut.None);
mSkrStop = new MenuItem("Stop", MenuItem_Skraping_Stop_Click, Shortcut.None);
mSkr.MenuItems.Add(mSkrStart);
mSkr.MenuItems.Add(mSkrStop);
// Menu comandi importer:
MenuItem mImp = new MenuItem("Importer");
mImpStart = new MenuItem("Start", MenuItem_Importer_Start_Click, Shortcut.None);
mImpStop = new MenuItem("Stop", MenuItem_Importer_Stop_Click, Shortcut.None);
mImp.MenuItems.Add(mImpStart);
mImp.MenuItems.Add(mImpStop);
// Menu contestuale:
this.ContextMenu = new ContextMenu();
this.ContextMenu.MenuItems.Add(mSkr);
this.ContextMenu.MenuItems.Add(mImp);
// Enable only start
mSkrStart.Enabled = true;
mSkrStop.Enabled = false;
mImpStart.Enabled = true;
mImpStop.Enabled = false;
}
/// <summary>
/// Gestione della navigazione fra i racconti
/// </summary>
private Navigator nav = null;
private void KeyDownAnalisi(object sender, KeyEventArgs e) {
#region Keys.F1 --> Show Help
//if (e.KeyCode == Keys.F1) {
// sbMessage.Text = "Show Help";
// MessageBox.Show(this, Help(), "Help", MessageBoxButtons.OK);
// return;
//}
#endregion
#region Keys.ESC --> Hide Reader
if (e.KeyCode == Keys.Escape) {
//this.Hide();
this.Close();
return;
}
#endregion
#region Keys.F2 --> Show Rac by ID
//if (e.KeyCode == Keys.F2) {
// // Form per richiedere l'ID di un racconto specifico da visualizzare:
// frmRqId frmi = new frmRqId();
// frmi.Left = Left + (Width - frmi.Width) / 2;
// frmi.Top = Top + (Height - frmi.Height) / 2;
// // Visualizzo il racconto richiesto:
// if (frmi.ShowDialog() == DialogResult.OK) {
// rtb.Text = nav.SwitchTo(frmi.ID);
// sbMessage.Text = string.Format("Racconto {0}", nav.ActualID.ToString("00000"));
// }
// frmi.Close();
// return;
//}
#endregion
#region Keys.F3 --> Show Rac random
if (e.KeyCode == Keys.F3) {
// Show New Random Rac
rtb.Text = nav.RandomRac;
sbMessage.Text = string.Format("Racconto {0}", nav.ActualID.ToString("00000"));
return;
}
#endregion
#region Keys.F4 --> Genera un racconto nuovo
if (e.KeyCode == Keys.F4) {
// Genera un racconto nuovo
StringBuilder sb = new StringBuilder();
sb.AppendLine("- ID Rac: 0");
sb.AppendLine("- Title: Titolo del nuovo racconto");
sb.AppendLine("- SubTit: ");
sb.AppendLine("- Autors: Mrk");
sb.AppendLine("- Voto: Non Letto");
sb.AppendLine("- Tags: Uncategorized");
sb.AppendLine("- Notes: SrcFile -|- Generated Internally");
sb.AppendLine(string.Format("- Creato: {0}", DateTime.Now.ToString("yyyy/MM/dd")));
sb.AppendLine(string.Format("- Update: {0}", DateTime.Now.ToString("yyyy/MM/dd")));
sb.AppendLine("- Origin: Mrk");
sb.AppendLine("- Trama: Trama del nuovo racconto");
rtb.Text = sb.ToString();
System.Windows.Forms.Clipboard.SetText(sb.ToString());
sbMessage.Text = string.Format("Generato un racconto nuovo, salvarlo con F8");
return;
}
#endregion
#region Keys.F5 --> Refresh Rac
if (e.KeyCode == Keys.F5) {
rtb.Text = nav.Refresh;
sbMessage.Text = string.Format("Racconto {0} Refresh", nav.ActualID.ToString("00000"));
return;
}
#endregion
#region Keys.F8 --> Edit Rac
if (e.KeyCode == Keys.F8) {
// Edit Rac
// Rileggo il testo che visualizzo (e che ho eventualmente editato) per recuperare i testi in esso e li salvo
// Se ID=0 o non specificato, aggiungo il testo come nuovo, altrimenti faccio l'update del racconto.
cRac[] racs = null;
int res = cRac.Read(rtb.Text, out racs);
if (res > 0) {
rtb.Text = string.Format("Trovati {0} racconti:\r\n", racs.Length);
res = 0;
foreach (cRac rac in racs) {
// Aggiorno il racconto in memoria
res += App.DB.UpdateRac(rac);
}
if (res == racs.Length) {
rtb.Text = nav.SwitchTo(racs[0].IDrac);
sbMessage.Text = string.Format("Importato/Aggiornato correttamente {0} racconti", res.ToString("00000"));
} else {
rtb.Text = App.DB.GetRacById(nav.ActualID).ToString();
sbMessage.Text = string.Format("Errore in lettura di {0}", nav.ActualID.ToString("00000"));
}
} else {
rtb.Text = "Lettura del racconto non riuscita";
}
return;
}
#endregion
#region Keys.F10 --> Bookmarks
if (e.KeyCode == Keys.F10) {
// ToDo: Keys.F10 --> Bookmarks
sbMessage.Text = "Keys.F10 --> Comando in sviluppo, non tutte le funzioni sono completate";
return;
}
#endregion
#region Keys.F12 --> Votazione
//if (e.KeyCode == Keys.F12 && (!e.Control) && (!e.Alt) && (!e.Shift)) {
// // Vote Rac
// long id = nav.ActualID;
// if (id < 0) return;
// frmVoto frmv = new frmVoto(App.DB.GetRacById(id));
// frmv.Left = Left + (Width - frmv.Width) / 2;
// frmv.Top = Top + (Height - frmv.Height) / 2;
// if (frmv.ShowDialog() == DialogResult.OK) {
// rtb.Text = nav.UpdateVoto(frmv.Voto);
// sbMessage.Text = string.Format("Racconto {0} Voted", nav.ActualID.ToString("00000"));
// } else {
// rtb.Text = nav.Refresh;
// sbMessage.Text = string.Format("Racconto {0} Refresh", nav.ActualID.ToString("00000"));
// }
// frmv.Close();
// return;
//}
#endregion
#region Keys.Alt+keys.H --> Home
if (e.Alt && (e.KeyCode == Keys.H)) {
rtb.Text = nav.Home;
sbMessage.Text = string.Format("Home {0}", nav.ActualID.ToString("00000"));
}
#endregion
#region Keys.Alt+Keys.Left --> Navigazione backward fra i racconti già visualizzati
if (e.Alt && (e.KeyCode == Keys.Left)) {
// Show Rac Backward
rtb.Text = nav.Backward;
sbMessage.Text = string.Format("Racconto {0}", nav.ActualID.ToString("00000"));
return;
}
#endregion
#region Keys.Alt+keys.Right --> Navigazione forward fra i racconti già visualizzati
if (e.Alt && (e.KeyCode == Keys.Right)) {
// Show Rac Forward
rtb.Text = nav.Forward;
sbMessage.Text = string.Format("Racconto {0}", nav.ActualID.ToString("00000"));
return;
}
#endregion
#region Keys.Alt+keys.Down --> Navigazione verso il racconto con ID precedente (ID Meno 1) a quello visualizzato
if (e.Alt && (e.KeyCode == Keys.Down)) {
// Show Rac Meno 1
rtb.Text = nav.Previous;
sbMessage.Text = string.Format("Racconto {0}", nav.ActualID.ToString("00000"));
return;
}
#endregion
#region Keys.Alt+keys.Up --> Navigazione verso il racconto con ID successivo (ID Più 1) a quello visualizzato
if (e.Alt && (e.KeyCode == Keys.Up)) {
// Show Rac Più 1
rtb.Text = nav.Next;
sbMessage.Text = string.Format("Racconto {0}", nav.ActualID.ToString("00000"));
return;
}
#endregion
#region Keys.Alt+keys.+ --> Incrementa la dimensione del font
if (e.Alt && (e.KeyCode == Keys.Add)) {
// Increse text size
Font f = new System.Drawing.Font(rtb.Font.FontFamily, rtb.Font.Size + 1.0F);
rtb.Font = f;
sbMessage.Text = string.Format("Racconto {0} Size Increase", nav.ActualID.ToString("00000"));
return;
}
#endregion
#region Keys.Alt+keys.- --> Decrementa la dimensione del font
if (e.Alt && (e.KeyCode == Keys.Subtract)) {
// Decrease text size
Font f = new System.Drawing.Font(rtb.Font.FontFamily, rtb.Font.Size - 1.0F);
rtb.Font = f;
sbMessage.Text = string.Format("Racconto {0} Size Decrease", nav.ActualID.ToString("00000"));
return;
}
#endregion
#region Keys.Alt+keys.* --> Imposta il font alla dimensione di default
if (e.Alt && (e.KeyCode == Keys.Multiply)) {
// Reset text size
Font f = new System.Drawing.Font(rtb.Font.FontFamily, (float)10.0);
rtb.Font = f;
sbMessage.Text = string.Format("Racconto {0} Size Default", nav.ActualID.ToString("00000"));
return;
}
#endregion
#region Keys.Alt+keys.F --> Editazione filtri:
//if (e.Alt && (e.KeyCode == Keys.F)) {
// // preparo l'interfaccia per la gestione filtri:
// frmFilters frmF = new frmFilters(DB);
// frmF.Left = Left + (Width - frmF.Width) / 2;
// frmF.Top = Top + (Height - frmF.Height) / 2;
// // Visualizzo l'interfaccia:
// if (frmF.ShowDialog() == DialogResult.OK) { sbMessage.Text = string.Format("FVoti: {0} - FTags: {1}", DB.FVoti, DB.FTags); }
// frmF.Close();
// return;
//}
#endregion
#region Keys.Alt+keys.A --> Navigazione fra i racconti dello stesso autore
//if (e.Alt && (e.KeyCode == Keys.A)) {
// // Show All Rac of this Autor
// frmList frml = new frmList();
// frml.Height = this.Height - 64;
// frml.Width = this.Width - 64;
// frml.Left = Left + (Width - frml.Width) / 2;
// frml.Top = Top + (Height - frml.Height) / 2;
// frml.Title = "Racconti dell'autore:";
// int res = DB.GetListByRacAutor(nav.ActualID, frml.LV);
// if ((res > 0) && (frml.ShowDialog() == DialogResult.OK)) {
// // Se racconto selezionato è uno solo, lo visualizzo, altrimenti mostro nuovo elenco
// if (frml.Num > 1) {
// // più racconti dallo stesso titolo:
// res = DB.GetListByTitle(frml.Descr, frml.LV);
// frml.Title = "Racconti con il titolo: " + frml.Descr;
// if ((res > 0) && (frml.ShowDialog() == DialogResult.OK)) {
// rtb.Text = nav.SwitchTo(frml.ID);
// sbMessage.Text = string.Format("Racconto {0}", nav.ActualID.ToString("00000"));
// }
// } else {
// // 1 solo racconto
// rtb.Text = nav.SwitchTo(frml.ID);
// sbMessage.Text = string.Format("Racconto {0}", nav.ActualID.ToString("00000"));
// }
// }
// frml.Close();
// return;
//}
#endregion
#region Keys.Alt+keys.T --> Navigazione fra i racconti via tag:
//if (e.Alt && (e.KeyCode == Keys.T)) {
// // Show All Tag
// frmList frml = new frmList();
// frml.Height = this.Height - 64;
// frml.Width = this.Width - 64;
// frml.Left = Left + (Width - frml.Width) / 2;
// frml.Top = Top + (Height - frml.Height) / 2;
// frml.Title = "Elenco Tags:";
// int res = DB.GetListTags(nav.ActualID, frml.LV);
// if ((res > 0) && (frml.ShowDialog() == DialogResult.OK)) {
// // Show all rac del tag selezionato
// res = DB.GetListByTags(frml.ID, frml.LV);
// frml.Title = "Racconti del tag: " + frml.Descr;
// if ((res > 0) && (frml.ShowDialog() == DialogResult.OK)) {
// // Se racconto selezionato è uno solo, lo visualizzo, altrimenti mostro nuovo elenco
// if (frml.Num > 1) {
// // più racconti dallo stesso titolo:
// res = DB.GetListByTitle(frml.Descr, frml.LV);
// frml.Title = "Racconti con il titolo: " + frml.Descr;
// if ((res > 0) && (frml.ShowDialog() == DialogResult.OK)) {
// rtb.Text = nav.SwitchTo(frml.ID);
// sbMessage.Text = string.Format("Racconto {0}", nav.ActualID.ToString("00000"));
// }
// } else {
// // 1 solo racconto
// rtb.Text = nav.SwitchTo(frml.ID);
// sbMessage.Text = string.Format("Racconto {0}", nav.ActualID.ToString("00000"));
// }
// }
// }
// frml.Close();
// return;
//}
#endregion
#region Keys.Alt+keys.V --> Navigazione fra i racconti via Voto:
//if (e.Alt && (e.KeyCode == Keys.V)) {
// // Show All Voto
// frmList frml = new frmList();
// frml.Height = this.Height - 64;
// frml.Width = this.Width - 64;
// frml.Left = Left + (Width - frml.Width) / 2;
// frml.Top = Top + (Height - frml.Height) / 2;
// frml.Title = "Elenco Voti Assegnati:";
// int res = DB.GetListVoti(nav.ActualID, frml.LV);
// if ((res > 0) && (frml.ShowDialog() == DialogResult.OK)) {
// // Show all rac del tag selezionato
// frml.Title = "Racconti del voto: " + frml.Descr;
// res = DB.GetListByVoto(frml.ID, frml.LV);
// if ((res > 0) && (frml.ShowDialog() == DialogResult.OK)) {
// rtb.Text = nav.SwitchTo(frml.ID);
// sbMessage.Text = string.Format("Racconto {0}", nav.ActualID.ToString("00000"));
// }
// }
// frml.Close();
// return;
//}
#endregion
#region Keys.Alt+keys.D --> Navigazione fra i racconti via Data:
//if (e.Alt && (!e.Shift) && (e.KeyCode == Keys.D)) {
// // Show All Year
// frmList frml = new frmList();
// frml.Height = this.Height - 64;
// frml.Width = this.Width - 64;
// frml.Left = Left + (Width - frml.Width) / 2;
// frml.Top = Top + (Height - frml.Height) / 2;
// frml.Title = "Elenco per anno di creazione:";
// int res = DB.GetListByCreationDate(frml.LV);
// if ((res > 0) && (frml.ShowDialog() == DialogResult.OK)) {
// if (frml.Num == 1) {
// // Per l'anno vi è 1 solo racconto, e quindi lo mostro direttamente:
// rtb.Text = nav.SwitchTo(frml.ID);
// sbMessage.Text = string.Format("Racconto {0}", nav.ActualID.ToString("00000"));
// } else {
// // Show all Month dell'anno selezionato
// string strYear = frml.Descr;
// res = DB.GetListByYear(strYear, frml.LV);
// frml.Title = "Elenco mesi dell'anno " + strYear;
// if ((res > 0) && (frml.ShowDialog() == DialogResult.OK)) {
// if (frml.Num == 1) {
// // Per l'anno e mese selezionato, vi è 1 solo racconto, e quindi lo mostro direttamente:
// rtb.Text = nav.SwitchTo(frml.ID);
// sbMessage.Text = string.Format("Racconto {0}", nav.ActualID.ToString("00000"));
// } else {
// // Show all Days del mese, dell'anno, selezionato
// string strMonth = frml.Descr;
// res = DB.GetListByMonth(strYear, strMonth, frml.LV);
// frml.Title = "Elenco giorni del mese " + strMonth + "/" + strYear;
// if ((res > 0) && (frml.ShowDialog() == DialogResult.OK)) {
// if (frml.Num == 1) {
// // solo un racconto nel mese indicato, lo visualizzo subito
// rtb.Text = nav.SwitchTo(frml.ID);
// sbMessage.Text = string.Format("Racconto {0}", nav.ActualID.ToString("00000"));
// } else {
// string strDay = frml.Descr;
// res = DB.GetListByDay(strYear, strMonth, strDay, frml.LV);
// frml.Title = "Elenco racconti del giorno " + strDay + "/" + strMonth + "/" + strYear;
// if ((res > 0) && (frml.ShowDialog() == DialogResult.OK)) {
// // Se racconto selezionato è uno solo, lo visualizzo, altrimenti mostro nuovo elenco
// if (frml.Num > 1) {
// // più racconti dallo stesso titolo:
// res = DB.GetListByTitle(frml.Descr, frml.LV);
// frml.Title = "Racconti con il titolo: " + frml.Descr;
// if ((res > 0) && (frml.ShowDialog() == DialogResult.OK)) {
// rtb.Text = nav.SwitchTo(frml.ID);
// sbMessage.Text = string.Format("Racconto {0}", nav.ActualID.ToString("00000"));
// }
// } else {
// // 1 solo racconto
// rtb.Text = nav.SwitchTo(frml.ID);
// sbMessage.Text = string.Format("Racconto {0}", nav.ActualID.ToString("00000"));
// }
// }
// }
// }
// }
// }
// }
// }
// frml.Close();
// return;
//}
#endregion
#region Keys.Alt+keys.L --> Navigazione degli ultimi 25 racconti updated e non letti:
//if (e.Alt && (e.KeyCode == Keys.L)) {
// #region
// // Show last 25 racconti updated:
// frmList frml = new frmList();
// frml.Height = this.Height - 64;
// frml.Width = this.Width - 64;
// frml.Left = Left + (Width - frml.Width) / 2;
// frml.Top = Top + (Height - frml.Height) / 2;
// frml.Title = "Ultimi 25 racconti modificati:";
// int res = DB.GetListByUpdate(50, frml.LV);
// if ((res > 0) && (frml.ShowDialog() == DialogResult.OK)) {
// // Vi è un solo racocnto e lo visualizzo:
// rtb.Text = nav.SwitchTo(frml.ID);
// sbMessage.Text = string.Format("Racconto {0}", nav.ActualID.ToString("00000"));
// }
// frml.Close();
// //this.Select();
// return;
// #endregion
//}
#endregion
#region Keys.Alt+keys.I --> Navigazione fra i racconti via iniziale titolo:
//if (e.Alt && (!e.Shift) && (e.KeyCode == Keys.I)) {
// // Show All Iniziali
// frmList frml = new frmList();
// frml.Height = this.Height - 64;
// frml.Width = this.Width - 64;
// frml.Left = Left + (Width - frml.Width) / 2;
// frml.Top = Top + (Height - frml.Height) / 2;
// frml.Title = "Elenco iniziali dei titoli:";
// int res = DB.GetListByIniziali(frml.LV);
// if ((res > 0) && (frml.ShowDialog() == DialogResult.OK)) {
// if (frml.Num == 1) {
// // Per l'iniziale vi è 1 solo racconto, e quindi lo mostro direttamente:
// rtb.Text = nav.SwitchTo(frml.ID);
// sbMessage.Text = string.Format("Racconto {0}", nav.ActualID.ToString("00000"));
// } else {
// // Show all titoli con l'iniziale selezionata
// string iniziale = frml.Descr;
// res = DB.GetListByIniziale(iniziale, frml.LV);
// frml.Title = "Elenco titoli con l'iniziale " + iniziale;
// if ((res > 0) && (frml.ShowDialog() == DialogResult.OK)) {
// // Se racconto selezionato è uno solo, lo visualizzo, altrimenti mostro nuovo elenco
// if (frml.Num > 1) {
// // più racconti dallo stesso titolo:
// res = DB.GetListByTitle(frml.Descr, frml.LV);
// frml.Title = "Racconti con il titolo: " + frml.Descr;
// if ((res > 0) && (frml.ShowDialog() == DialogResult.OK)) {
// rtb.Text = nav.SwitchTo(frml.ID);
// sbMessage.Text = string.Format("Racconto {0}", nav.ActualID.ToString("00000"));
// }
// } else {
// // 1 solo racconto
// rtb.Text = nav.SwitchTo(frml.ID);
// sbMessage.Text = string.Format("Racconto {0}", nav.ActualID.ToString("00000"));
// }
// }
// }
// }
// frml.Close();
// return;
//}
#endregion
#region Shift+keys.Alt+keys.D --> Visualizza tutti i racconti non letti con la data attuale:
//if (e.Alt && e.Shift && (e.KeyCode == Keys.D)) {
// // ricavo la data del racconto visualizzato:
// cRac rac = App.DB.GetRacById(nav.ActualID);
// string strYear = rac.Creato.Year.ToString("0000");
// string strMonth = rac.Creato.Month.ToString("00");
// string strDay = rac.Creato.Day.ToString("00");
// // Show tutti i racconti non letti della data indicata:
// frmList frml = new frmList();
// frml.Height = this.Height - 64;
// frml.Width = this.Width - 64;
// frml.Left = Left + (Width - frml.Width) / 2;
// frml.Top = Top + (Height - frml.Height) / 2;
// int res = DB.GetListByDay(strYear, strMonth, strDay, frml.LV);
// frml.Title = "Elenco racconti del giorno " + strDay + "/" + strMonth + "/" + strYear;
// if ((res > 0) && (frml.ShowDialog() == DialogResult.OK)) {
// // Se racconto selezionato è uno solo, lo visualizzo, altrimenti mostro nuovo elenco
// if (frml.Num > 1) {
// // più racconti dallo stesso titolo:
// res = DB.GetListByTitle(frml.Descr, frml.LV);
// frml.Title = "Racconti con il titolo: " + frml.Descr;
// if ((res > 0) && (frml.ShowDialog() == DialogResult.OK)) {
// rtb.Text = nav.SwitchTo(frml.ID);
// sbMessage.Text = string.Format("Racconto {0}", nav.ActualID.ToString("00000"));
// }
// } else {
// // 1 solo racconto
// rtb.Text = nav.SwitchTo(frml.ID);
// sbMessage.Text = string.Format("Racconto {0}", nav.ActualID.ToString("00000"));
// }
// }
// frml.Close();
// return;
//}
#endregion
#region Shift+Keys.Alt+keys.I --> Navigazione fra i racconti con la stessa iniziale del titolo:
//if (e.Alt && e.Shift && (e.KeyCode == Keys.I)) {
// // ricavo L'iniziale del titolo del racocnto visualizzato:
// cRac rac = App.DB.GetRacById(nav.ActualID);
// string iniziale = rac.Title.Substring(0, 1);
// // Show All Iniziali
// frmList frml = new frmList();
// frml.Height = this.Height - 64;
// frml.Width = this.Width - 64;
// frml.Left = Left + (Width - frml.Width) / 2;
// frml.Top = Top + (Height - frml.Height) / 2;
// int res = DB.GetListByIniziale(iniziale, frml.LV);
// frml.Title = "Elenco titoli con l'iniziale " + iniziale;
// if ((res > 0) && (frml.ShowDialog() == DialogResult.OK)) {
// // Se racconto selezionato è uno solo, lo visualizzo, altrimenti mostro nuovo elenco
// if (frml.Num > 1) {
// // più racconti dallo stesso titolo:
// res = DB.GetListByTitle(frml.Descr, frml.LV);
// frml.Title = "Racconti con il titolo: " + frml.Descr;
// if ((res > 0) && (frml.ShowDialog() == DialogResult.OK)) {
// rtb.Text = nav.SwitchTo(frml.ID);
// sbMessage.Text = string.Format("Racconto {0}", nav.ActualID.ToString("00000"));
// }
// } else {
// // 1 solo racconto
// rtb.Text = nav.SwitchTo(frml.ID);
// sbMessage.Text = string.Format("Racconto {0}", nav.ActualID.ToString("00000"));
// }
// }
// frml.Close();
// return;
//}
#endregion
#region Shift+keys.Alt+F12 --> Ricrea l'intero DB eliminando i racconti segnati da eliminare
if (e.KeyCode == Keys.F12 && (!e.Control) && e.Alt && e.Shift) {
// ToDo: Shift+Alt+F12 --> Ricrea l'intero DB eliminando i racconti segnati da eliminare
sbMessage.Text = "Shift+Alt+F12 --> Comando in sviluppo, non tutte le funzioni sono completate";
return;
}
#endregion
#region Keys.Alt+Keys.Q --> Esegue una query personalizzata:
if (e.Alt && (e.KeyCode == Keys.Z)) {
// ToDo: Keys.Alt+Keys.Q --> Esegue una query personalizzata
sbMessage.Text = "Keys.Alt+Keys.Q --> Comando in sviluppo, non tutte le funzioni sono completate";
return;
}
#endregion
#region Keys.Alt+keys.Z --> Analisi Racconti Duplicati:
if (e.Alt && (e.KeyCode == Keys.Z)) {
// ToDo: Keys.Alt+keys.Z --> Analisi Racconti Duplicati:
sbMessage.Text = "Shift+Alt+F12 --> Comando in sviluppo, non tutte le funzioni sono completate";
return;
}
#endregion
#region Keys.Alt+keys.S --> Crea uno snapshot di n racconti formattati e li converte in ebook
//if (e.Alt && (e.KeyCode == Keys.S)) {
// // // ToDo: Keys.Alt+keys.S --> Crea uno snapshot di n racconti formattati e li converte in ebook
// // sbMessage.Text = "Keys.Alt+keys.S --> Comando in sviluppo, non tutte le funzioni sono completate";
// // return;
// cmdCreaEbook();
//}
#endregion
#region Keys.Alt+keys.U --> Unione di due racconti
//if (e.Alt && (e.KeyCode == Keys.U)) {
// // ToDo: Keys.Alt+keys.U --> Unione di due racconti
// // - chiede l'ID dei due racconti da unire
// frmIDs frmid = new frmIDs();
// frmid.Left = Left + (Width - frmid.Width) / 2;
// frmid.Top = Top + (Height - frmid.Height) / 2;
// if (frmid.ShowDialog() != DialogResult.OK) {
// sbMessage.Text = "Anullato inserimento degli ID dei racconti da unire";
// return;
// }
// if ((frmid.IDleft <= 0) || (frmid.IDright <= 0)) {
// sbMessage.Text = "ID dei racconti da unire non validi";
// return;
// }
// // - ricavo i due racconti da unire:
// cRac left = DB.GetRacById(frmid.IDleft);
// cRac right = DB.GetRacById(frmid.IDright);
// frmid.Close();
// // - visualizza il form di unione
// frmUnion frm = new frmUnion(left, right, DB);
// if (frm.ShowDialog() == DialogResult.OK) {
// // - Left: il racconto unione:
// left = frm.Unione;
// // - Right: lo indico come duplicato:
// right.Title = "Doppione";
// right.SubTitle = left.strIDrac;
// right.Voto = "Da Cancellare";
// right.Tags.Clear();
// right.Tags.Add("Doppione");
// right.Notes.Clear();
// right.Notes.Add(new cNota("SrcFile", "Doppione"));
// right.Trama = "Racconto duplicato del " + left.strIDrac;
// // - Aggiorno il DB
// if ((right.IsValid) && (left.IsValid)) {
// App.DB.UpdateRac(right);
// App.DB.UpdateRac(left);
// }
// }
// frm.Close();
// return;
//}
#endregion
#region
#endregion
}
private void frmReader_FormClosing(object sender, FormClosingEventArgs e) {
// Prima di chiudere, devo fermare l'importazione o lo scraping
if (serviceCrawler != null) { serviceCrawler.StopWorker(); }
if (ServiceImporter != null) { ServiceImporter.StopWorker(); }
}
async void MenuItem_Skraping_Start_Click(object sender, EventArgs e) {
// Update menu
mSkrStart.Enabled = false;
mSkrStop.Enabled = true;
mImpStart.Enabled = false;
mImpStop.Enabled = false;
// - Creo istanza del client per il sito con autenticazione:
sbStatusLabel.Text = "Login on A69";
siteA69 = new cSite_A69();
// - Eseguo l'autenticazione
bool res = await siteA69.Authenticate();
if (res) {
sbStatusLabel.Text = "A69 logged";
Logger.Information("Sito A69 loggato: " + res.ToString());
} else {
Logger.Information("Login Fault");
return;
}
// - 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_A69.InsertStartLink(serviceCrawler)) {
sbStatusLabel.Text = "A69 fault.";
return;
}
// avvio il servizio
serviceCrawler.StartWorker(siteA69);
}
void MenuItem_Skraping_Stop_Click(object sender, EventArgs e) {
// Update menu
mSkrStart.Enabled = false;
mSkrStop.Enabled = false;
mImpStart.Enabled = true;
mImpStop.Enabled = false;
if (serviceCrawler != null) { serviceCrawler.StopWorker(); }
}
void MenuItem_Importer_Start_Click(object sender, EventArgs e) {
// Update menu
mSkrStart.Enabled = false;
mSkrStop.Enabled = false;
mImpStart.Enabled = false;
mImpStop.Enabled = true;
// Preparo il servizio
ServiceImporter = new Service_Importer(sb);
// Per ora uso la directory di default, poi metteremo selezione
string path = Cfg.Settings.PathDownloadWorking;
// avvio il servizio
ServiceImporter.StartWorker(path);
}
void MenuItem_Importer_Stop_Click(object sender, EventArgs e) {; }
}
}
@@ -117,7 +117,7 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="sb.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value> <value>17, 17</value>
</metadata> </metadata>
</root> </root>