- Autocommit - 2022/01/05 10:01:11
This commit is contained in:
1 parent
1e5548a9fc
commit
3c5c58b3b0
5 files changed
+393
-2
No files matched your search
@@ -35,6 +35,10 @@
|
||||
<ApplicationIcon>Tools.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="HtmlAgilityPack, Version=1.11.37.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\..\_Library\HtmlAgilityPack 1.11.37\Net40\HtmlAgilityPack.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data.SQLite, Version=1.0.65.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86">
|
||||
@@ -53,7 +57,11 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="App.cs" />
|
||||
<Compile Include="Data\DBTools.cs" />
|
||||
<Compile Include="Net\ATLink.cs" />
|
||||
<Compile Include="Net\ATLinkState.cs" />
|
||||
<Compile Include="Net\cA69Engine.cs" />
|
||||
<Compile Include="Net\cA69Engine2.cs" />
|
||||
<Compile Include="Net\DownloadClient.cs" />
|
||||
<Compile Include="Net\frmDownloader.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
||||
+26
-1
@@ -4,6 +4,31 @@ using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace A69WD.Net {
|
||||
class ATLink {
|
||||
|
||||
|
||||
public class ATLink {
|
||||
|
||||
public string URL { get { return _url; } }
|
||||
private string _url;
|
||||
|
||||
public string Dst { get { return _dst; } }
|
||||
private string _dst;
|
||||
|
||||
public string Testo { get; set; }
|
||||
|
||||
public ATLinkState Status { get; set; }
|
||||
|
||||
|
||||
public ATLink(string url, string fileName) { Initialize(url, fileName, ATLinkState.ToCheck); }
|
||||
|
||||
private void Initialize(string url, string fileName, ATLinkState status) {
|
||||
this._url = url;
|
||||
this._dst = fileName;
|
||||
this.Testo = "";
|
||||
this.Status = status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace A69WD.Net {
|
||||
|
||||
/// <summary>
|
||||
/// Enumerazione di tutti i bossibili stati di un link:
|
||||
/// </summary>
|
||||
public enum ATLinkState {
|
||||
/// <summary>
|
||||
/// Indica un link che deve venir testato per capire se è o meno da downloadare
|
||||
/// </summary>
|
||||
ToCheck = 1,
|
||||
/// <summary>
|
||||
/// Indica un link che deve venir downloadato
|
||||
/// </summary>
|
||||
ToDownload = 2,
|
||||
/// <summary>
|
||||
/// Indica un ATLink che è in download
|
||||
/// </summary>
|
||||
OnDownload = 3,
|
||||
/// <summary>
|
||||
/// Indica un ATLink correttamente downloadato
|
||||
/// </summary>
|
||||
Donwloaded = 4,
|
||||
/// <summary>
|
||||
/// Indica un link che deve venir downloadato
|
||||
/// </summary>
|
||||
ToAnalize = 5,
|
||||
/// <summary>
|
||||
/// Indica un ATLink che è in analizzazione
|
||||
/// </summary>
|
||||
OnAnalize = 6,
|
||||
/// <summary>
|
||||
/// Indica un ATLink correttamente downloadato
|
||||
/// </summary>
|
||||
Analized = 7,
|
||||
/// <summary>
|
||||
/// Indica un ATLink in cui si è concluso il lavoro.
|
||||
/// </summary>
|
||||
End = 8,
|
||||
/// <summary>
|
||||
/// Indica un ATLink il cui download ha avuto un errore
|
||||
/// </summary>
|
||||
ErrorDownload = 9,
|
||||
/// <summary>
|
||||
/// Indica un ATLink la cui analisi ha avuto un errore
|
||||
/// </summary>
|
||||
ErrorAnalize = 10,
|
||||
/// <summary>
|
||||
/// Indica un ATLink il cui download è stato abortito
|
||||
/// </summary>
|
||||
AbortDownload = 11,
|
||||
/// <summary>
|
||||
/// Indica un ATLink la cui analisi è stata abortita
|
||||
/// </summary>
|
||||
AbortAnalize = 12,
|
||||
/// <summary>
|
||||
/// Indica un ATLink il cui download è stato cancellato
|
||||
/// </summary>
|
||||
CancelDownload = 13,
|
||||
/// <summary>
|
||||
/// Indica un ATLink la cui analisi è stata cancellata
|
||||
/// </summary>
|
||||
CancelAnalize = 14,
|
||||
} // enum ATLinkState
|
||||
|
||||
|
||||
}
|
||||
@@ -3,7 +3,185 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using System.ComponentModel;
|
||||
using System.Net;
|
||||
using System.IO;
|
||||
|
||||
|
||||
namespace A69WD.Net {
|
||||
class DownloadClient {
|
||||
|
||||
public class DownloadClient {
|
||||
|
||||
#region Fields: _backgroundWorker, Link
|
||||
|
||||
private BackgroundWorker _backgroundWorker = null;
|
||||
|
||||
public ATLink Link { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Eventi:
|
||||
|
||||
public event EventHandler<System.ComponentModel.RunWorkerCompletedEventArgs> Starting;
|
||||
public event EventHandler<System.ComponentModel.RunWorkerCompletedEventArgs> Complete;
|
||||
public event EventHandler<System.ComponentModel.RunWorkerCompletedEventArgs> Cancelled;
|
||||
public event EventHandler<System.ComponentModel.RunWorkerCompletedEventArgs> Error;
|
||||
public event EventHandler<System.ComponentModel.ProgressChangedEventArgs> ProgressChanged;
|
||||
|
||||
|
||||
#region Gestione emissione degli eventi per le classi che utilizzano il DownloadClient
|
||||
|
||||
/// <summary>
|
||||
/// Attivo evento Starting
|
||||
/// </summary>
|
||||
private void RaiseEvent_Starting() {
|
||||
EventHandler<System.ComponentModel.RunWorkerCompletedEventArgs> tmp = Starting;
|
||||
if (null != tmp)
|
||||
tmp(this, new RunWorkerCompletedEventArgs(0F, null, false));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attivo evento Complete
|
||||
/// </summary>
|
||||
private void RaiseEvent_Complete() {
|
||||
//if ((this.Link.Status != ATLinkState.ErrorDownload) && (this.Link.Status != ATLinkState.CancelDownload)) {
|
||||
// this.Link.Status = ATLinkState.Donwloaded;
|
||||
EventHandler<System.ComponentModel.RunWorkerCompletedEventArgs> tmp = Complete;
|
||||
if (null != tmp)
|
||||
tmp(this, new RunWorkerCompletedEventArgs(100F, null, false));
|
||||
//}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attivo l'evento Cancelled
|
||||
/// </summary>
|
||||
private void RaiseEvent_Cancelled() {
|
||||
//this.Link.Status = ATLinkState.CancelDownload;
|
||||
Logger.Error(string.Format("Error Code: 00281 - Cancellazione del download del link: {0}", this.Link.ToString()));
|
||||
var copy = Cancelled;
|
||||
if (null != copy) copy(this, new RunWorkerCompletedEventArgs(0F, null, true));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attivo l'evento Error
|
||||
/// </summary>
|
||||
private void RaiseEvent_Error(Exception error) {
|
||||
//this.Link.Status = ATLinkState.ErrorDownload;
|
||||
Logger.Error(string.Format("Error Code: 00282 - Errore durante il download del link: {0}", this.Link.ToString()));
|
||||
var copy = Error;
|
||||
if (null != copy) copy(this, new RunWorkerCompletedEventArgs(-1F, error, false));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attivo l'evento ProgressChanged
|
||||
/// </summary>
|
||||
private void RaiseEvent_ProgressChanged(Int32 progress) {
|
||||
EventHandler<System.ComponentModel.ProgressChangedEventArgs> copy = ProgressChanged;
|
||||
if (null != copy)
|
||||
copy(this, new System.ComponentModel.ProgressChangedEventArgs(progress, this));
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
public DownloadClient(ATLink link) { this.Link = link; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Avvia il download su un thread in background
|
||||
/// </summary>
|
||||
public void Start() {
|
||||
//if (this.Link.Status == ATLinkState.ToDownload) {
|
||||
// Preparo gli argomenti da passare al thread in background:
|
||||
List<Object> arguments = new List<Object>();
|
||||
arguments.Add(this.Link);
|
||||
// Creo il thread
|
||||
_backgroundWorker = CreateWorker(arguments);
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region Gestione del thread in background:
|
||||
|
||||
/// <summary>
|
||||
/// Creo il thread in background e lo faccio partire.
|
||||
/// </summary>
|
||||
private BackgroundWorker CreateWorker(List<Object> Arguments) {
|
||||
// Creo un background worker:
|
||||
BackgroundWorker bg = new BackgroundWorker();
|
||||
bg.WorkerReportsProgress = true;
|
||||
bg.WorkerSupportsCancellation = true;
|
||||
// Assegno le risposte agli eventi del thread in background:
|
||||
bg.ProgressChanged += new ProgressChangedEventHandler(BackgroundThread_ProgressChanged);
|
||||
bg.RunWorkerCompleted += new RunWorkerCompletedEventHandler(BackgroundThread_RunWorkerCompleted);
|
||||
bg.DoWork += new DoWorkEventHandler(BackgroundThread_DoWork);
|
||||
// Assegno gli argomenti previsti:
|
||||
bg.RunWorkerAsync(Arguments);
|
||||
return bg;
|
||||
}
|
||||
|
||||
|
||||
#region Gestione eventi del thread in background:
|
||||
|
||||
/// <summary>
|
||||
/// Codice eseguito al completamento del thread in background
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
void BackgroundThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
|
||||
if (e.Error != null) {
|
||||
RaiseEvent_Error(e.Error);
|
||||
} else {
|
||||
if (e.Cancelled)
|
||||
RaiseEvent_Cancelled();
|
||||
else RaiseEvent_Complete();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Codice eseguito ad ogni progresso nel thread in background
|
||||
/// </summary>
|
||||
void BackgroundThread_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e) {
|
||||
RaiseEvent_ProgressChanged(e.ProgressPercentage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Codice eseguito dal trhead in background:
|
||||
/// cioè esegue il dowload asincrono del file indicato da web:
|
||||
/// </summary>
|
||||
void BackgroundThread_DoWork(object sender, DoWorkEventArgs e) {
|
||||
try {
|
||||
RaiseEvent_Starting();
|
||||
|
||||
HtmlAgilityPack.HtmlWeb web = new HtmlAgilityPack.HtmlWeb();
|
||||
HtmlAgilityPack.HtmlDocument doc = web.Load(this.Link.URL);
|
||||
this.Link.Testo = doc.Text;
|
||||
RaiseEvent_ProgressChanged(50);
|
||||
System.IO.StreamWriter sw = new System.IO.StreamWriter(this.Link.Dst);
|
||||
sw.Write(doc.Text);
|
||||
sw.Flush();
|
||||
sw.Close();
|
||||
RaiseEvent_Complete();
|
||||
} catch (Exception ex) {
|
||||
Console.Write(ex.Message);
|
||||
RaiseEvent_Error(ex);
|
||||
} finally {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using A69WD.Net;
|
||||
|
||||
|
||||
namespace A69WD {
|
||||
|
||||
public class cA69Engine2 {
|
||||
|
||||
#region Property: State, NumDownload, Tipologie, BASE_URL, BASE_LINK_IDX, BASE_LINK_RAC
|
||||
|
||||
public EngineStatusEnum State { get { return state; } }
|
||||
|
||||
public int NumDownload { get { return downloaded.Count; } }
|
||||
|
||||
static 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, downRac, state, wb
|
||||
|
||||
List<string> allLinks = null;
|
||||
List<string> toDownload = null;
|
||||
List<string> downloaded = null;
|
||||
List<string> racLinks = null;
|
||||
|
||||
DateTime dtStartTime;
|
||||
|
||||
bool downRac = false;
|
||||
|
||||
EngineStatusEnum state = EngineStatusEnum.NotReady;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Costruttore e distruttore
|
||||
|
||||
public cA69Engine2() {
|
||||
try {
|
||||
// Inizializzo gli archivi (dai file in memoria)
|
||||
allLinks = new List<string>();
|
||||
toDownload = new List<string>();
|
||||
downloaded = new List<string>();
|
||||
racLinks = new List<string>();
|
||||
int res = App.DB.LoadData(allLinks, toDownload, downloaded, racLinks);
|
||||
RaiseEvent_Updating("Ricaricati " + res.ToString("000") + " link di racconti da scaricare");
|
||||
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));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Logger.Log(new object[] { "Error Code: ER02220", "Errore in cA69Engine()", ex });
|
||||
throw ex;
|
||||
}
|
||||
state = EngineStatusEnum.StandBy;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#region Eventi:
|
||||
|
||||
/// <summary>
|
||||
/// Evento che indica un cambiamento di stato nell'AnalizeManager
|
||||
/// </summary>
|
||||
public event EventHandler<EngineEventArgs> Updating;
|
||||
|
||||
|
||||
#region Generazione degli eventi dell'engine verso le classi chiamanti:
|
||||
|
||||
/// <summary>
|
||||
/// Attiva l'evento che segnala un cambiamento di stato nel engine (per esempio, terminato il download di un singolo file)
|
||||
/// </summary>
|
||||
void RaiseEvent_Updating(string msg, int tot, int toDown, int down) {
|
||||
EventHandler<EngineEventArgs> tmp = Updating;
|
||||
if (null != tmp) tmp(this, new EngineEventArgs(msg, tot, toDown, down));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attiva l'evento che segnala un cambiamento di stato nel engine (per esempio, terminato il download di un singolo file)
|
||||
/// </summary>
|
||||
void RaiseEvent_Updating(string msg) {
|
||||
EventHandler<EngineEventArgs> tmp = Updating;
|
||||
if (null != tmp) tmp(this, new EngineEventArgs(msg, allLinks.Count, toDownload.Count, downloaded.Count));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user