- Autocommit - 2021/10/27 11:01:11

This commit is contained in:
CSiCoAlm committed 2021-10-27 11:01:12 +02:00
1 parent b0b60c14a5
commit ae8d3b0dce
7 files changed
+308 -39

No files matched your search

+1
View File
@@ -50,6 +50,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="App.cs" /> <Compile Include="App.cs" />
<Compile Include="Data\DBTools.cs" /> <Compile Include="Data\DBTools.cs" />
<Compile Include="Net\cA69Engine.cs" />
<Compile Include="Net\frmDownloader.cs"> <Compile Include="Net\frmDownloader.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
+34 -34
View File
@@ -140,43 +140,43 @@ namespace A69WD {
#endregion #endregion
/// <summary> ///// <summary>
/// Ricava dal DB tutti i dati ///// Ricava dal DB tutti i dati
/// </summary> ///// </summary>
/// <returns>Numero di link inseriti nell'engine. Un numero negativo se si è avuto un errore.</returns> ///// <returns>Numero di link inseriti nell'engine. Un numero negativo se si è avuto un errore.</returns>
public long RetrieveLinks() { //public long RetrieveLinks() {
// MRK: TODO: // // MRK: TODO:
// Può essere utile amplificare questa funzione in modo che si possa specificare quali link reinserire: // // Può essere utile amplificare questa funzione in modo che si possa specificare quali link reinserire:
// Ad esempio dei filtri tipo: // // Ad esempio dei filtri tipo:
// - solo link con Status pari a ErrorDownload o CancelDownload // // - solo link con Status pari a ErrorDownload o CancelDownload
// - solo link con Status pari a OnDownload // // - solo link con Status pari a OnDownload
// - ecc... // // - ecc...
//return 0; // MRK: BYPASSATO TUTTO PER EVITARE CHE ALL'INIZIO CARICHI I LINK IN SOSPESO. // //return 0; // MRK: BYPASSATO TUTTO PER EVITARE CHE ALL'INIZIO CARICHI I LINK IN SOSPESO.
object obj = new Object(); // object obj = new Object();
lock (obj) { // lock (obj) {
long Res = 0; // long Res = 0;
System.Data.DataTable table = new System.Data.DataTable("LinksLog"); // System.Data.DataTable table = new System.Data.DataTable("LinksLog");
try { // try {
System.Data.SQLite.SQLiteCommand cmd = new SQLiteCommand("SELECT [URL], [Tipo], [Status], [LastUp] FROM [LinksLog] WHERE [Tipo]='Testo' AND [Status]<>4", cn); // Donwloaded = 4 // System.Data.SQLite.SQLiteCommand cmd = new SQLiteCommand("SELECT [URL], [Tipo], [Status], [LastUp] FROM [LinksLog] WHERE [Tipo]='Testo' AND [Status]<>4", cn); // Donwloaded = 4
SQLiteDataReader rdr = cmd.ExecuteReader(); // SQLiteDataReader rdr = cmd.ExecuteReader();
while (rdr.Read()) { // while (rdr.Read()) {
string url = rdr["URL"] as string; // string url = rdr["URL"] as string;
ATLinkState status = ATLinkState.ToDownload; // ATLinkState status = ATLinkState.ToDownload;
try { status = ((ATLinkState)((long)rdr["Status"])); } catch (Exception ex) { throw new Exception("ERRORE AFFABULANTE \n" + ex.Message); } // try { status = ((ATLinkState)((long)rdr["Status"])); } catch (Exception ex) { throw new Exception("ERRORE AFFABULANTE \n" + ex.Message); }
ATLib.Net.ATLink lk = new ATLib.Net.ATLink(plugin, url, fileName, status); // ATLib.Net.ATLink lk = new ATLib.Net.ATLink(plugin, url, fileName, status);
ATLib.ATWDEngine.Instance.AddLink(lk); // ATLib.ATWDEngine.Instance.AddLink(lk);
Res++; // Res++;
} // }
} catch (Exception ex) { // } catch (Exception ex) {
ATLib.Logger.Log(new object[] { "Error Code: DB07003", "Errore in ATLib.Data.DBTools.RetrieveLinks()", ex }); // ATLib.Logger.Log(new object[] { "Error Code: DB07003", "Errore in ATLib.Data.DBTools.RetrieveLinks()", ex });
if (Res > 0) Res = -1 * Res; // if (Res > 0) Res = -1 * Res;
} // }
return Res; // return Res;
} // }
} //}
+2 -2
View File
@@ -161,7 +161,7 @@ namespace A69WD {
public virtual string PathDownloadWorking { get { return Path.Combine(PathApplicationRoot, "Down"); } } public virtual string PathDownloadWorking { get { return Path.Combine(PathApplicationRoot, "Down"); } }
/// <summary> /// <summary>
/// Path della directory su cui riporto i file di indice correttamente analizzati. /// Path della directory su cui riporto i file di indice, correttamente analizzati.
/// </summary> /// </summary>
public virtual string PathAnalizadedIndexFile { public virtual string PathAnalizadedIndexFile {
get { get {
@@ -177,7 +177,7 @@ namespace A69WD {
/// <summary> /// <summary>
/// Path della directory su cui riporto i file di indice correttamente analizzati. /// Path della directory su cui riporto i file dei racconti, correttamente analizzati.
/// </summary> /// </summary>
public virtual string PathAnalizadedRaccFile { public virtual string PathAnalizadedRaccFile {
get { get {
+233
View File
@@ -0,0 +1,233 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace A69WD {
public class cA69Engine {
#region Property: State, Tipologie, BASE_URL, BASE_LINK_IDX, BASE_LINK_RAC
public EngineStatusEnum State { get { return state; } }
public int NumDownload { get { return downloaded.Count; } }
string[] Tipologie = { "altro", "bdsm", "gay", "incesto", "lesbo", "orge", "prime", "scambio", "tradimenti", "trans", "trio" };
const string BASE_URL = "https://www.annunci69.it/racconti-erotici/{Tip}.html";
const string BASE_LINK_IDX = "https://www.annunci69.it/racconti-erotici/racconti_lista.php";
const string BASE_LINK_RAC = "https://www.annunci69.it/racconti-erotici/";
#endregion
#region Fields: allLinks, toDownload, downloaded, racLinks, dtStartTime, aborting, downRac, state, wb
List<string> allLinks = null;
List<string> toDownload = null;
List<string> downloaded = null;
List<string> racLinks = null;
DateTime dtStartTime;
bool aborting = false;
bool downRac = false;
EngineStatusEnum state = EngineStatusEnum.NotReady;
WebBrowser wb = null;
#endregion
#region Costruttore e distruttore
public cA69Engine(WebBrowser WB) {
// Inizializzo gli archivi (dai file in memoria)
allLinks = new List<string>();
toDownload = new List<string>();
downloaded = new List<string>();
racLinks = new List<string>();
wb = WB;
wb.DocumentCompleted += Wb_DocumentCompleted;
// Per ora non serializzo gli archivi e quindi carico le pagine iniziali delle 11 tipologie:
foreach (string tipologia in Tipologie) {
toDownload.Add(BASE_URL.Replace("{Tip}", tipologia));
allLinks.Add(BASE_URL.Replace("{Tip}", tipologia));
}
state = EngineStatusEnum.StandBy;
}
#endregion
#region Method:
public bool Start(bool DownRac) {
if (state != EngineStatusEnum.StandBy) return false;
dtStartTime = DateTime.Now;
downRac = DownRac;
UpdateST("Inizio lo scrap dei link dei racconti");
state = EngineStatusEnum.Starting;
if (toDownload.Count > 0) {
// proseguo con il download:
string lk = toDownload.First();
toDownload.Remove(lk);
wb.Navigate(lk);
}
return true;
}
public void Stop() {
}
#endregion
private void Wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
object obj = new Object();
lock (obj) {
StringBuilder sb;
if (state == EngineStatusEnum.Starting) state = EngineStatusEnum.Started;
WebBrowser wb = sender as WebBrowser;
string link = wb.Url.ToString();
// aggiorno UI
UpdateST(wb.Name + " - Donwloaded: " + link);
// Se pagina è un racconto, lo salvo
if (IsRacLink(link)) {
sb = new StringBuilder();
sb.Append(wb.DocumentText);
string fn = Path.Combine(Cfg.Settings.PathAnalizadedRaccFile, GetFileName(link));
cTools.WriteTextFile(fn, sb);
}
// Registro che ho eseguito il download del link
downloaded.Add(link);
// Ciclo su tutti i link estratti dalla pagina:
foreach (HtmlElement item in wb.Document.Links) {
link = item.GetAttribute("href");
// Se link nuovo:
if (!allLinks.Contains(link)) {
// Link nuovo, mi comporto di conseguenza alla tipologia:
if (IsRacLink(link)) {
// Link ad un racconto
allLinks.Add(link);
if (downRac) { toDownload.Add(link); }
racLinks.Add(link);
} else {
if (IsIdxLink(link)) {
// Link ad un indice
allLinks.Add(link);
toDownload.Add(link);
} else {
// Link non riconosciuto, lo scarto
;
}
}
}
} // fine ciclo sui link estratti
// Se ho raggiunto il massimo numero di link, o non vi sono link da downloadare, mi fermo:
if ((toDownload.Count > 0) && (state==EngineStatusEnum.Started)) {
// proseguo con il download:
string lk = toDownload.First();
toDownload.Remove(lk);
wb.Navigate(lk);
} else {
// Finito download:
state = EngineStatusEnum.Stopping;
// salvo gli archivi:
SaveState();
}
}//lock
}
private void SaveState() {
StringBuilder sb;
// Finito download, salvo gli archivi:
string dt = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
// Salvo archivio: AllLinks
sb = new StringBuilder();
allLinks.Sort();
foreach (string lnk in allLinks) { sb.AppendLine(lnk); }
cTools.WriteTextFile(Path.Combine(Cfg.Settings.PathAnalizadedIndexFile, string.Format("_A69_AllLinks_{0}.tes", dt)), sb);
// Salvo archivio: toDownload
sb = new StringBuilder();
toDownload.Sort();
foreach (string lnk in toDownload) { sb.AppendLine(lnk); }
cTools.WriteTextFile(Path.Combine(Cfg.Settings.PathAnalizadedIndexFile, string.Format("_A69_toDownload_{0}.tes", dt)), sb);
// Salvo archivio: Downloaded
sb = new StringBuilder();
downloaded.Sort();
foreach (string lnk in downloaded) { sb.AppendLine(lnk); }
cTools.WriteTextFile(Path.Combine(Cfg.Settings.PathAnalizadedIndexFile, string.Format("_A69_Downloaded_{0}.tes", dt)), sb);
// Salvo archivio: RacLinks
sb = new StringBuilder();
racLinks.Sort();
foreach (string lnk in racLinks) { sb.AppendLine(lnk); }
cTools.WriteTextFile(Path.Combine(Cfg.Settings.PathAnalizadedIndexFile, string.Format("_A69_RacLinks_{0}.tes", dt)), sb);
// avviso utente:
UpdateST(string.Format("Finito il download in {0}", DateTime.Now - dtStartTime));
state = EngineStatusEnum.Stopped;
}
private void UpdateST(string Msg) {
//lblST.Text = string.Format("{0} - {1} - {2}", DateTime.Now.ToString("HH:mm:ss"), cnt.ToString("0000"), Msg);
}
private string GetFileName(string url) { return url.Replace("https://www.annunci69.it/racconti-erotici/", "A69_").Replace("/", "_").Replace(":", "_").Replace(@"\", "_"); }
private bool IsIdxLink(string link) { return link.StartsWith(BASE_LINK_IDX); }
private bool IsRacLink(string link) { foreach (string tip in Tipologie) { if (link.StartsWith(BASE_LINK_RAC + tip + "/")) return true; } return false; }
}//class cA69Engine
/// <summary>
/// Enumerazione di tutti i possibili stati dell'engine:
/// </summary>
public enum EngineStatusEnum {
/// <summary>
/// Engine da inizializzare
/// </summary>
NotReady = 1,
/// <summary>
/// Engine inizializzato e pronto a partire
/// </summary>
StandBy = 1,
Starting = 2,
Started = 3,
Stopping = 4,
Stopped = 5,
} // enum EngineStatusEnum
}//namespace A69WD
+4
View File
@@ -61,6 +61,7 @@
this.btnClose.TabIndex = 14; this.btnClose.TabIndex = 14;
this.btnClose.Text = "Close"; this.btnClose.Text = "Close";
this.btnClose.UseVisualStyleBackColor = true; this.btnClose.UseVisualStyleBackColor = true;
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
// //
// btnHide // btnHide
// //
@@ -70,6 +71,7 @@
this.btnHide.TabIndex = 13; this.btnHide.TabIndex = 13;
this.btnHide.Text = "Hide"; this.btnHide.Text = "Hide";
this.btnHide.UseVisualStyleBackColor = true; this.btnHide.UseVisualStyleBackColor = true;
this.btnHide.Click += new System.EventHandler(this.btnHide_Click);
// //
// btnDownloadAll // btnDownloadAll
// //
@@ -79,6 +81,7 @@
this.btnDownloadAll.TabIndex = 11; this.btnDownloadAll.TabIndex = 11;
this.btnDownloadAll.Text = "Download All"; this.btnDownloadAll.Text = "Download All";
this.btnDownloadAll.UseVisualStyleBackColor = true; this.btnDownloadAll.UseVisualStyleBackColor = true;
this.btnDownloadAll.Click += new System.EventHandler(this.btnDownloadAll_Click);
// //
// lblST // lblST
// //
@@ -111,6 +114,7 @@
this.btnDownloadLink.TabIndex = 10; this.btnDownloadLink.TabIndex = 10;
this.btnDownloadLink.Text = "Download only Link"; this.btnDownloadLink.Text = "Download only Link";
this.btnDownloadLink.UseVisualStyleBackColor = true; this.btnDownloadLink.UseVisualStyleBackColor = true;
this.btnDownloadLink.Click += new System.EventHandler(this.btnDownloadLink_Click);
// //
// frmDownloader // frmDownloader
// //
+32 -2
View File
@@ -8,9 +8,39 @@ using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
namespace A69WD { namespace A69WD {
public partial class frmDownloader : Form { public partial class frmDownloader : Form {
public frmDownloader() { public frmDownloader() {
InitializeComponent(); InitializeComponent();
engine = new cA69Engine(this.wb1);
} }
}
} cA69Engine engine = null;
private void btnDownloadLink_Click(object sender, EventArgs e) {
engine.Start(false);
}
private void btnDownloadAll_Click(object sender, EventArgs e) {
engine.Start(true);
}
private void btnHide_Click(object sender, EventArgs e) {
this.Hide();
}
private void btnClose_Click(object sender, EventArgs e) {
if ((engine.State == EngineStatusEnum.Stopped) || (engine.State == EngineStatusEnum.StandBy)) {
this.Close();
} else {
engine.Stop();
}
}
}//class frmDownloader
}//namespace A69WD
+2 -1
View File
@@ -3,7 +3,8 @@
<!-- Path root dell'applicazione. Da questo derivano tutti gli altri path. --> <!-- Path root dell'applicazione. Da questo derivano tutti gli altri path. -->
<PathApplicationRoot>C:\Temporary\A69WD</PathApplicationRoot> <!-- <PathApplicationRoot>C:\Temporary\A69WD</PathApplicationRoot> -->
<PathApplicationRoot>D:\Project\Private\Prj\MyTools\A69WD\Test</PathApplicationRoot>
<!-- Nome del database usato dall'applicazione. --> <!-- Nome del database usato dall'applicazione. -->
<DBName>A69DB.db</DBName> <DBName>A69DB.db</DBName>