diff --git a/Src/A69WD/.vs/A69WD.csproj.dtbcache.json b/Src/A69WD/.vs/A69WD.csproj.dtbcache.json index ec2b733..2e178ed 100644 --- a/Src/A69WD/.vs/A69WD.csproj.dtbcache.json +++ b/Src/A69WD/.vs/A69WD.csproj.dtbcache.json @@ -1 +1 @@ -{"RootPath":"C:\\Commesse\\_zPrivate\\A69WD\\Src\\A69WD","ProjectFileName":"A69WD.csproj","Configuration":"Debug|AnyCPU","FrameworkPath":"","Sources":[{"SourceFile":"App.cs"},{"SourceFile":"Data\\DBTools.cs"},{"SourceFile":"Net\\ATLink.cs"},{"SourceFile":"Net\\ATLinkState.cs"},{"SourceFile":"Net\\cA69Engine.cs"},{"SourceFile":"Net\\DownloadClient.cs"},{"SourceFile":"Net\\frmDownloader.cs"},{"SourceFile":"Net\\frmDownloader.Designer.cs"},{"SourceFile":"Data\\eLinkState.cs"},{"SourceFile":"General\\Cfg.cs"},{"SourceFile":"General\\cTools.cs"},{"SourceFile":"Test\\Form1.cs"},{"SourceFile":"Test\\Form1.Designer.cs"},{"SourceFile":"Logger.cs"},{"SourceFile":"Test\\frmTestSite.cs"},{"SourceFile":"Test\\frmTestSite.Designer.cs"},{"SourceFile":"Test\\Program.cs"},{"SourceFile":"Properties\\AssemblyInfo.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":[]} \ No newline at end of file +{"RootPath":"C:\\Commesse\\_zPrivate\\A69WD\\Src\\A69WD","ProjectFileName":"A69WD.csproj","Configuration":"Debug|AnyCPU","FrameworkPath":"","Sources":[{"SourceFile":"App.cs"},{"SourceFile":"Data\\DBTools.cs"},{"SourceFile":"Net\\ATLink.cs"},{"SourceFile":"Net\\ATLinkState.cs"},{"SourceFile":"Net\\cA69Engine.cs"},{"SourceFile":"Net\\DownloadClient.cs"},{"SourceFile":"Net\\frmDownloader.cs"},{"SourceFile":"Net\\frmDownloader.Designer.cs"},{"SourceFile":"Data\\eLinkState.cs"},{"SourceFile":"General\\Cfg.cs"},{"SourceFile":"General\\cTools.cs"},{"SourceFile":"Logger.cs"},{"SourceFile":"Properties\\AssemblyInfo.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":[]} \ No newline at end of file diff --git a/Src/A69WD/A69WD.csproj b/Src/A69WD/A69WD.csproj index 4a2a4ce..9a72457 100644 --- a/Src/A69WD/A69WD.csproj +++ b/Src/A69WD/A69WD.csproj @@ -60,22 +60,22 @@ - - - - - + + + + Form - + frmDownloader.cs - - + + - + + frmDownloader.cs diff --git a/Src/A69WD/A69WD.csproj.user b/Src/A69WD/A69WD.csproj.user index 56fd5d8..e0be25f 100644 --- a/Src/A69WD/A69WD.csproj.user +++ b/Src/A69WD/A69WD.csproj.user @@ -1,6 +1,6 @@ - ProjectFiles + ShowAllFiles \ No newline at end of file diff --git a/Src/A69WD/Data/DBTools.cs b/Src/A69WD/Data/DBTools.cs index 53926d1..27abf0d 100644 --- a/Src/A69WD/Data/DBTools.cs +++ b/Src/A69WD/Data/DBTools.cs @@ -2,33 +2,45 @@ using System.Collections.Generic; using System.Text; using System.Data.SQLite; +using A69WD.Net; namespace A69WD { public class DBTools { - /* - - Database: A69WD: - - Tabella per storicizzare i link downloadati: - -------------------------------------------- - CREATE TABLE [LinksLog] ( - [URL] TEXT UNIQUE NOT NULL PRIMARY KEY, - [Tipo] TEXT NOT NULL, - [Status] INTEGER NOT NULL, - [LastUp] TIMESTAMP NOT NULL - ) - - */ + /* + * + * Tabella per storicizzare i link downloadati: + * -------------------------------------------- + * CREATE TABLE [LinksLog] ( /* Tabella per salvare il lavoro fatto sui link * / + * [LinkURL] TEXT UNIQUE NOT NULL PRIMARY KEY, /* URL del link * / + * [FileName] TEXT UNIQUE NOT NULL, /* Nome del file su cui salvo quanto downloadato * / + * [PlugID] TEXT NOT NULL, /* ID del plugin utilizzato per gestire questo particolare link * / + * [Fields] INTEGER NOT NULL, /* Campo in cui salvo tutti i dati significativi sul link, separati fra loro da -|- * / + * [Status] INTEGER NOT NULL, /* Stato della lavorazione * / + * [LastUpdate] TIMESTAMP NOT NULL /* Timestamp all'ultimo aggiornamento del record * / + * ) + * + */ + #region Class Fields & Property: cn, DB_ok, objLock - #region Class Fields & Property: cn, DB_ok - + /// + /// Connessione al DB + /// public System.Data.SQLite.SQLiteConnection cn { get; set; } + + /// + /// Indicatore che il DB è ready + /// public bool DB_ok { get; set; } + /// + /// Oggetto per la sincronizzazione fra i threads: + /// + internal readonly object objLock = new object(); + #endregion #region Costruttore e distruttore: @@ -38,9 +50,6 @@ namespace A69WD { object obj = new Object(); lock (obj) { System.Data.SQLite.SQLiteConnection conn = null; - #region MyRegion - - #endregion // Check esistenza del DB dell'applicazione, altrimenti ne creo uno nuovo: try { if (!System.IO.File.Exists(System.IO.Path.Combine(Cfg.Settings.PathDB, Cfg.Settings.DBName))) { @@ -147,12 +156,14 @@ namespace A69WD { sb.AppendLine("-- Creazione delle tabelle principali:"); sb.AppendLine("-- "); sb.AppendLine("-- "); - sb.AppendLine("CREATE TABLE [LinksLog] ( -- COMMENT 'Tabella per la gestione di tutti i link'"); - sb.AppendLine(" [URL] TEXT UNIQUE NOT NULL PRIMARY KEY, -- COMMENT 'URL del link'"); - sb.AppendLine(" [Tipo] TEXT NOT NULL, -- COMMENT 'Tipologia del link: Idx=Link a un Indice, Rac=Link a un Racconto, Unk=Non Definito'"); - sb.AppendLine(" [Status] INTEGER NOT NULL, -- COMMENT 'Stato del link: 1=ToCheck, 2=ToDownload, 3=OnDownload, 4=Downloaded'"); - sb.AppendLine(" [LastUp] TIMESTAMP NOT NULL -- COMMENT 'Timestamp del record'"); - sb.AppendLine(");"); + sb.AppendLine("CREATE TABLE [LinksLog] ( /* Tabella per salvare il lavoro fatto sui link */ "); + sb.AppendLine(" [LinkURL] TEXT UNIQUE NOT NULL PRIMARY KEY, /* URL del link */"); + sb.AppendLine(" [FileName] TEXT UNIQUE NOT NULL, /* Nome del file su cui salvo quanto downloadato */ "); + sb.AppendLine(" [PlugID] TEXT NOT NULL, /* ID del plugin utilizzato per gestire questo particolare link */ "); + sb.AppendLine(" [Fields] INTEGER NOT NULL, /* Campo in cui salvo tutti i dati significativi sul link, separati fra loro da -|- */ "); + sb.AppendLine(" [Status] INTEGER NOT NULL, /* Stato della lavorazione */ "); + sb.AppendLine(" [LastUpdate] TIMESTAMP NOT NULL /* Timestamp all'ultimo aggiornamento del record */ "); + sb.AppendLine("); "); sb.AppendLine("-- "); sb.AppendLine("-- "); sb.AppendLine("------------------------------------------------------------------------------"); @@ -167,55 +178,59 @@ namespace A69WD { public int LoadData(List allLinks, List toDownload, List downloaded, List racLinks) { - object obj = new Object(); - lock (obj) { - int Res = 0; - try { - - // Carico tutti i racconti non ancora downloadati completamente: - System.Data.SQLite.SQLiteCommand cmd = new SQLiteCommand("SELECT [URL], [Tipo], [Status], [LastUp] FROM [LinksLog] WHERE [Tipo]='Rac' AND [Status]<>4", cn); // Donwloaded = 4 - SQLiteDataReader rdr = cmd.ExecuteReader(); - while (rdr.Read()) { - string url = rdr["URL"] as string; - allLinks.Add(url); - toDownload.Add(url); - racLinks.Add(url); - Res++; - } + //object obj = new Object(); + //lock (obj) { + // int Res = 0; + // try { - // Carico ora tutti i racconti downloadati completamente per evitare doppioni: - cmd = new SQLiteCommand("SELECT [URL], [Tipo], [Status], [LastUp] FROM [LinksLog] WHERE [Tipo]='Rac' AND [Status]=4", cn); // Donwloaded = 4 - rdr = cmd.ExecuteReader(); - while (rdr.Read()) { - string url = rdr["URL"] as string; - allLinks.Add(url); - racLinks.Add(url); - Res++; - } + // // Carico tutti i racconti non ancora downloadati completamente: + // System.Data.SQLite.SQLiteCommand cmd = new SQLiteCommand("SELECT [URL], [Tipo], [Status], [LastUp] FROM [LinksLog] WHERE [Tipo]='Rac' AND [Status]<>4", cn); // Donwloaded = 4 + // SQLiteDataReader rdr = cmd.ExecuteReader(); + // while (rdr.Read()) { + // string url = rdr["URL"] as string; + // allLinks.Add(url); + // toDownload.Add(url); + // racLinks.Add(url); + // Res++; + // } - } catch (Exception ex) { - Logger.Log(new object[] { "Error Code: DB07003", "Errore in Data.DBTools.LoadData()", ex }); - if (Res > 0) Res = -1 * Res; - } - return Res; - } + // // Carico ora tutti i racconti downloadati completamente per evitare doppioni: + // cmd = new SQLiteCommand("SELECT [URL], [Tipo], [Status], [LastUp] FROM [LinksLog] WHERE [Tipo]='Rac' AND [Status]=4", cn); // Donwloaded = 4 + // rdr = cmd.ExecuteReader(); + // while (rdr.Read()) { + // string url = rdr["URL"] as string; + // allLinks.Add(url); + // racLinks.Add(url); + // Res++; + // } + + // } catch (Exception ex) { + // Logger.Log(new object[] { "Error Code: DB07003", "Errore in Data.DBTools.LoadData()", ex }); + // if (Res > 0) Res = -1 * Res; + // } + // return Res; + //} + return 0; } public int SaveData(List allLinks, List toDownload, List downloaded, List racLinks) { - object obj = new Object(); - lock (obj) { - int Res = 0; - try { - foreach (string link in racLinks) { LinkLogUpdtate(link, cA69Engine.LinkType(link), eLinkState.Donwloaded); } - foreach (string link in toDownload) { LinkLogUpdtate(link, cA69Engine.LinkType(link), eLinkState.ToDownload); } - foreach (string link in downloaded) { LinkLogUpdtate(link, cA69Engine.LinkType(link), eLinkState.Donwloaded); } - } catch (Exception ex) { - Logger.Log(new object[] { "Error Code: DB07003", "Errore in Data.DBTools.LoadData()", ex }); - if (Res > 0) Res = -1 * Res; - } - return Res; - } + //object obj = new Object(); + //lock (obj) { + // int Res = 0; + // try { + // foreach (string link in racLinks) { LinkLogUpdtate(link, cA69Engine.LinkType(link), eLinkState.Donwloaded); } + // foreach (string link in toDownload) { LinkLogUpdtate(link, cA69Engine.LinkType(link), eLinkState.ToDownload); } + // foreach (string link in downloaded) { LinkLogUpdtate(link, cA69Engine.LinkType(link), eLinkState.Donwloaded); } + // } catch (Exception ex) { + // Logger.Log(new object[] { "Error Code: DB07003", "Errore in Data.DBTools.LoadData()", ex }); + // if (Res > 0) Res = -1 * Res; + // } + // return Res; + //} + return 0; } + + private bool LinkLogUpdtate(string url, string tip, eLinkState st) { // object obj = new Object(); // lock (obj) { @@ -275,9 +290,107 @@ namespace A69WD { } - + public eLinkState GetStateByURL(string url) { + lock (objLock) { + try { + System.Data.SQLite.SQLiteCommand cmd = new System.Data.SQLite.SQLiteCommand(); + cmd.Connection = cn; + cmd.CommandText = "SELECT Status FROM LinksLog WHERE LinkURL=@LinkURL LIMIT 1"; + cmd.CommandType = System.Data.CommandType.Text; + System.Data.SQLite.SQLiteParameter param = new System.Data.SQLite.SQLiteParameter(); + param.ParameterName = "@LinkURL"; + param.DbType = global::System.Data.DbType.String; + param.SourceColumn = "LinkURL"; + cmd.Parameters.Add(param); + cmd.Parameters[0].Value = url; + object obj = cmd.ExecuteScalar(); + if (obj != null) return (eLinkState)((long)obj); + return eLinkState.ToDownload; + } catch (Exception ex) { + Logger.Log(new object[] { "Error Code: DB06521", string.Format("MyDownloader.DBTools.GetStateByURL({0})", url), ex }); + return eLinkState.Error; + } + } + } + /// + /// Aggiorna il log relativo al link nel DB. + /// + /// True se tutto ok; False altrimenti. + public bool LinkLog(iLink link) { + lock (objLock) { + return LinkLogUpdtate(link); + } + } + private bool LinkLogUpdtate(iLink link) { + // object obj = new Object(); + // lock (obj) { + // Cancello riga (se non presente, non fa nulla) + // Inserisco riga + bool Res = false; + try { + // Cancello il link anche se non presente + System.Data.SQLite.SQLiteCommand cmd = new SQLiteCommand(string.Format("DELETE FROM [LinksLog] WHERE [LinkURL]='{0}'", link.URL), cn); + int res = cmd.ExecuteNonQuery(); + cmd = null; + // Inserisco il link come se fosse nuovo + cmd = new System.Data.SQLite.SQLiteCommand(); + cmd.Connection = cn; + cmd.CommandText = "INSERT INTO [LinksLog] VALUES(@LinkURL, @FileName, @PlugID, @Fields, @Status, @LastUpdate)"; + cmd.CommandType = System.Data.CommandType.Text; + System.Data.SQLite.SQLiteParameter param = new System.Data.SQLite.SQLiteParameter(); + param.ParameterName = "@LinkURL"; + param.DbType = global::System.Data.DbType.String; + param.SourceColumn = "LinkURL"; + cmd.Parameters.Add(param); + param = new System.Data.SQLite.SQLiteParameter(); + param.ParameterName = "@FileName"; + param.DbType = global::System.Data.DbType.String; + param.SourceColumn = "FileName"; + cmd.Parameters.Add(param); + param = new System.Data.SQLite.SQLiteParameter(); + param.ParameterName = "@PlugID"; + param.DbType = global::System.Data.DbType.String; + param.SourceColumn = "PlugID"; + cmd.Parameters.Add(param); + param = new System.Data.SQLite.SQLiteParameter(); + param.ParameterName = "@Fields"; + param.DbType = global::System.Data.DbType.String; + param.SourceColumn = "Fields"; + cmd.Parameters.Add(param); + param = new System.Data.SQLite.SQLiteParameter(); + param.ParameterName = "@Status"; + param.DbType = global::System.Data.DbType.Int32; + param.SourceColumn = "Status"; + cmd.Parameters.Add(param); + param = new System.Data.SQLite.SQLiteParameter(); + param.ParameterName = "@LastUpdate"; + param.DbType = global::System.Data.DbType.DateTime; + param.SourceColumn = "LastUpdate"; + cmd.Parameters.Add(param); + cmd.Parameters[0].Value = link.URL; + cmd.Parameters[1].Value = link.FileName; + cmd.Parameters[2].Value = link.ID; + cmd.Parameters[3].Value = link.Fields; + cmd.Parameters[4].Value = link.Status; + cmd.Parameters[5].Value = DateTime.Now; + res = cmd.ExecuteNonQuery(); + if (res != 1) { + Logger.Log(new object[] { "Error Code: DB06010", string.Format("MyDownloader.DBTools.LinkLogUpdtate({0})={1}", link, res), link.ToString() }); + Res = false; + } else { + Res = true; + } + } catch (Exception ex) { + Logger.Log(new object[] { "Error Code: DB06001", string.Format("MyDownloader.DBTools.LinkLogUpdtate({0})", link), link.ToString(), ex }); + return false; + } finally { + //if ((cn != null) && (cn.State != System.Data.ConnectionState.Closed)) cn.Close(); + } + return Res; + // } // lock (obj) + } } // class DBTools diff --git a/Src/A69WD/Data/eLinkState.cs b/Src/A69WD/Data/eLinkState.cs deleted file mode 100644 index c2ce43a..0000000 --- a/Src/A69WD/Data/eLinkState.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace A69WD { - - /// - /// Enumerazione di tutti i bossibili stati di un link: - /// - public enum eLinkState { - /// - /// Indica un link che deve venir testato per capire se è o meno da downloadare - /// - ToCheck = 1, - /// - /// Indica un link che deve venir downloadato - /// - ToDownload = 2, - /// - /// Indica un ATLink che è in download - /// - OnDownload = 3, - /// - /// Indica un ATLink correttamente downloadato - /// - Donwloaded = 4, - ///// - ///// Indica un link che deve venir downloadato - ///// - //ToAnalize = 5, - ///// - ///// Indica un ATLink che è in analizzazione - ///// - //OnAnalize = 6, - ///// - ///// Indica un ATLink correttamente downloadato - ///// - //Analized = 7, - ///// - ///// Indica un ATLink in cui si è concluso il lavoro. - ///// - //End = 8, - ///// - ///// Indica un ATLink il cui download ha avuto un errore - ///// - //ErrorDownload = 9, - ///// - ///// Indica un ATLink la cui analisi ha avuto un errore - ///// - //ErrorAnalize = 10, - ///// - ///// Indica un ATLink il cui download è stato abortito - ///// - //AbortDownload = 11, - ///// - ///// Indica un ATLink la cui analisi è stata abortita - ///// - //AbortAnalize = 12, - ///// - ///// Indica un ATLink il cui download è stato cancellato - ///// - //CancelDownload = 13, - ///// - ///// Indica un ATLink la cui analisi è stata cancellata - ///// - //CancelAnalize = 14, - } // enum eLinkState - -}//namespace A69WD diff --git a/Src/A69WD/Logger.cs b/Src/A69WD/General/Logger.cs similarity index 100% rename from Src/A69WD/Logger.cs rename to Src/A69WD/General/Logger.cs diff --git a/Src/A69WD/Net/ATLink.cs b/Src/A69WD/Net/ATLink.cs deleted file mode 100644 index eb7015f..0000000 --- a/Src/A69WD/Net/ATLink.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace A69WD.Net { - - - 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; - } - - - - } -} diff --git a/Src/A69WD/Net/ATLinkState.cs b/Src/A69WD/Net/ATLinkState.cs deleted file mode 100644 index 05a2f13..0000000 --- a/Src/A69WD/Net/ATLinkState.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace A69WD.Net { - - /// - /// Enumerazione di tutti i bossibili stati di un link: - /// - public enum ATLinkState { - /// - /// Indica un link che deve venir testato per capire se è o meno da downloadare - /// - ToCheck = 1, - /// - /// Indica un link che deve venir downloadato - /// - ToDownload = 2, - /// - /// Indica un ATLink che è in download - /// - OnDownload = 3, - /// - /// Indica un ATLink correttamente downloadato - /// - Donwloaded = 4, - /// - /// Indica un link che deve venir downloadato - /// - ToAnalize = 5, - /// - /// Indica un ATLink che è in analizzazione - /// - OnAnalize = 6, - /// - /// Indica un ATLink correttamente downloadato - /// - Analized = 7, - /// - /// Indica un ATLink in cui si è concluso il lavoro. - /// - End = 8, - /// - /// Indica un ATLink il cui download ha avuto un errore - /// - ErrorDownload = 9, - /// - /// Indica un ATLink la cui analisi ha avuto un errore - /// - ErrorAnalize = 10, - /// - /// Indica un ATLink il cui download è stato abortito - /// - AbortDownload = 11, - /// - /// Indica un ATLink la cui analisi è stata abortita - /// - AbortAnalize = 12, - /// - /// Indica un ATLink il cui download è stato cancellato - /// - CancelDownload = 13, - /// - /// Indica un ATLink la cui analisi è stata cancellata - /// - CancelAnalize = 14, - } // enum ATLinkState - - -} diff --git a/Src/A69WD/Net/DownloadClient.cs b/Src/A69WD/Net/DownloadClient.cs deleted file mode 100644 index 93211bb..0000000 --- a/Src/A69WD/Net/DownloadClient.cs +++ /dev/null @@ -1,187 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -using System.ComponentModel; -using System.Net; -using System.IO; - - -namespace A69WD.Net { - - public class DownloadClient { - - #region Fields: _backgroundWorker, Link - - private BackgroundWorker _backgroundWorker = null; - - public ATLink Link { get; set; } - - #endregion - - - #region Eventi: - - public event EventHandler Starting; - public event EventHandler Complete; - public event EventHandler Cancelled; - public event EventHandler Error; - public event EventHandler ProgressChanged; - - - #region Gestione emissione degli eventi per le classi che utilizzano il DownloadClient - - /// - /// Attivo evento Starting - /// - private void RaiseEvent_Starting() { - EventHandler tmp = Starting; - if (null != tmp) - tmp(this, new RunWorkerCompletedEventArgs(0F, null, false)); - } - - /// - /// Attivo evento Complete - /// - private void RaiseEvent_Complete() { - //if ((this.Link.Status != ATLinkState.ErrorDownload) && (this.Link.Status != ATLinkState.CancelDownload)) { - // this.Link.Status = ATLinkState.Donwloaded; - EventHandler tmp = Complete; - if (null != tmp) - tmp(this, new RunWorkerCompletedEventArgs(100F, null, false)); - //} - } - - /// - /// Attivo l'evento Cancelled - /// - 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)); - } - - /// - /// Attivo l'evento Error - /// - 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)); - } - - /// - /// Attivo l'evento ProgressChanged - /// - private void RaiseEvent_ProgressChanged(Int32 progress) { - EventHandler copy = ProgressChanged; - if (null != copy) - copy(this, new System.ComponentModel.ProgressChangedEventArgs(progress, this)); - } - - - #endregion - - #endregion - - public DownloadClient(ATLink link) { this.Link = link; } - - - /// - /// Avvia il download su un thread in background - /// - public void Start() { - //if (this.Link.Status == ATLinkState.ToDownload) { - // Preparo gli argomenti da passare al thread in background: - List arguments = new List(); - arguments.Add(this.Link); - // Creo il thread - _backgroundWorker = CreateWorker(arguments); - //} - } - - - - #region Gestione del thread in background: - - /// - /// Creo il thread in background e lo faccio partire. - /// - private BackgroundWorker CreateWorker(List 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: - - /// - /// Codice eseguito al completamento del thread in background - /// - /// - /// - void BackgroundThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { - if (e.Error != null) { - RaiseEvent_Error(e.Error); - } else { - if (e.Cancelled) - RaiseEvent_Cancelled(); - else RaiseEvent_Complete(); - } - } - - /// - /// Codice eseguito ad ogni progresso nel thread in background - /// - void BackgroundThread_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e) { - RaiseEvent_ProgressChanged(e.ProgressPercentage); - } - - /// - /// Codice eseguito dal trhead in background: - /// cioè esegue il dowload asincrono del file indicato da web: - /// - 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 - - - - - - - } -} diff --git a/Src/A69WD/Net/cA69Engine.cs b/Src/A69WD/Net/cA69Engine.cs deleted file mode 100644 index 61b6e11..0000000 --- a/Src/A69WD/Net/cA69Engine.cs +++ /dev/null @@ -1,509 +0,0 @@ -using System; -using System.IO; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Windows.Forms; -using System.Net; -using System.Text.RegularExpressions; - -namespace A69WD { - - public class cA69Engine { - - - #region Property: State, NumDownload, Tipologie, BASE_URL, BASE_LINK_IDX, BASE_LINK_RAC, conteggioEvt - - 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/"; - - int conteggioEvt = 0; - - #endregion - - - #region Fields: allLinks, toDownload, downloaded, racLinks, dtStartTime, downRac, state - - List allLinks = null; - List toDownload = null; - List downloaded = null; - List racLinks = null; - - DateTime dtStartTime; - - bool downRac = false; - - EngineStatusEnum state = EngineStatusEnum.NotReady; - - #endregion - - - #region Costruttore e distruttore - - public cA69Engine() { - try { - // Inizializzo gli archivi (dai file in memoria) - allLinks = new List(); - toDownload = new List(); - downloaded = new List(); - racLinks = new List(); - int res = App.DB.LoadData(allLinks, toDownload, downloaded, racLinks); - - RaiseEvent_Updating("Ricaricati " + res.ToString("000") + " link di racconti da scaricare"); - - // 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 Method: Start, Stop, ImportLinkFromFile - - public bool Start(bool DownRac) { - if (state != EngineStatusEnum.StandBy) return false; - - dtStartTime = DateTime.Now; - downRac = DownRac; - - RaiseEvent_Updating("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); - string fn = Path.Combine(Cfg.Settings.PathAnalizadedRaccFile, GetFileName(lk)); - using (MyWebClient client = new MyWebClient(lk, fn)) { - //client.Encoding = Encoding.ASCII; - client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0"); - client.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); - client.Headers.Add("Cookie", "euconsent-v2=CPG74goPG74goAKAeAENBcCsAP_AAH_AAAwIH3tf_X__bX9j-_59__t0eY1f9_7_v-wzjhfdt-8N2P_X_L0X42E7PF36pq4KuR4Eu3LBIQNlHOHUTUmw6okVrTPsak2Mr7NKJ7LEmnMZe2dYGHtfn91TuZKY7_78_9fz3_-v_v___9f3r-3_3__59X---_e_V399zLv9__3__9gfiASYal8AF2JY4Mk0aVQogQhWEh0AoAKKAYWiawgYXBTsrAI9QQMAEJqAjAiBBiCjFgEAAgEASERASAHggEQBEAgABACpAQgAImAQWAFgYBAAKAaFiBFAEIEhBkcFRymBARItFBPZWAJRd7GmEIZRYAUCj-iowEShBAsDISFg5gAA.YAAAAAAAAAAA"); - client.Headers.Add("DNT", "1"); - client.Headers.Add("TE", "Trailers"); - ////client.DownloadFile(new Uri(lk), fn); - //client.DownloadProgressChanged += Client_DownloadProgressChanged; - //client.DownloadFileCompleted += Client_DownloadFileCompleted; - //client.DownloadDataCompleted += Client_DownloadDataCompleted; - client.DownloadStringCompleted += Client_DownloadStringCompleted; - ////client.DownloadFileAsync(new Uri(lk), fn); - ////client.DownloadDataAsync(new Uri(lk)); - client.DownloadStringAsync(new Uri(lk)); - } - } - - return true; - } - - public bool StartParallel(bool DownRac,int numThred) { - if (state != EngineStatusEnum.StandBy) return false; - - dtStartTime = DateTime.Now; - downRac = DownRac; - - RaiseEvent_Updating("Inizio lo scrap dei link dei racconti con " + numThred.ToString("00") + " thread"); - - state = EngineStatusEnum.Starting; - - for (int i = 0; i < numThred; i++) { - if (toDownload.Count > 0) { - // proseguo con il download: - string lk = toDownload.First(); - toDownload.Remove(lk); - string fn = Path.Combine(Cfg.Settings.PathAnalizadedRaccFile, GetFileName(lk)); - using (MyWebClient client = new MyWebClient(lk, fn)) { - //client.Encoding = Encoding.ASCII; - client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0"); - client.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); - client.Headers.Add("Cookie", "euconsent-v2=CPG74goPG74goAKAeAENBcCsAP_AAH_AAAwIH3tf_X__bX9j-_59__t0eY1f9_7_v-wzjhfdt-8N2P_X_L0X42E7PF36pq4KuR4Eu3LBIQNlHOHUTUmw6okVrTPsak2Mr7NKJ7LEmnMZe2dYGHtfn91TuZKY7_78_9fz3_-v_v___9f3r-3_3__59X---_e_V399zLv9__3__9gfiASYal8AF2JY4Mk0aVQogQhWEh0AoAKKAYWiawgYXBTsrAI9QQMAEJqAjAiBBiCjFgEAAgEASERASAHggEQBEAgABACpAQgAImAQWAFgYBAAKAaFiBFAEIEhBkcFRymBARItFBPZWAJRd7GmEIZRYAUCj-iowEShBAsDISFg5gAA.YAAAAAAAAAAA"); - client.Headers.Add("DNT", "1"); - client.Headers.Add("TE", "Trailers"); - ////client.DownloadFile(new Uri(lk), fn); - //client.DownloadProgressChanged += Client_DownloadProgressChanged; - //client.DownloadFileCompleted += Client_DownloadFileCompleted; - //client.DownloadDataCompleted += Client_DownloadDataCompleted; - client.DownloadStringCompleted += Client_DownloadStringCompleted; - ////client.DownloadFileAsync(new Uri(lk), fn); - ////client.DownloadDataAsync(new Uri(lk)); - client.DownloadStringAsync(new Uri(lk)); - } - } - } - - return true; - } - - public bool Stop() { - switch (state) { - case EngineStatusEnum.NotReady: - case EngineStatusEnum.StandBy: - SaveState(); - state = EngineStatusEnum.Stopped; - return true; - case EngineStatusEnum.Starting: - case EngineStatusEnum.Started: - case EngineStatusEnum.Stopping: - state = EngineStatusEnum.Stopping; - return false; - case EngineStatusEnum.Stopped: - return true; - } - return true; - } - - public int ImportLinkFromFile(string SrcFilePath) { - int res = 0; - try { - if (File.Exists(SrcFilePath)) { - StreamReader sr = new StreamReader(SrcFilePath, Encoding.UTF8); - string row = sr.ReadLine().Trim(); - while (row != null) { - // verifico che non sia un commento: - if (!(row.StartsWith("#") || row.StartsWith("//"))) { - // Se link nuovo: - if (!allLinks.Contains(row)) { - // Link nuovo, mi comporto di conseguenza alla tipologia: - if (IsRacLink(row)) { - // Link ad un racconto - allLinks.Add(row); - toDownload.Add(row); - racLinks.Add(row); - res++; - } else { - if (IsIdxLink(row)) { - // Link ad un indice - allLinks.Add(row); - toDownload.Add(row); - res++; - } else { - // Link non riconosciuto, lo scarto - ; - } - } - } - } - //Read the next line - row = sr.ReadLine(); - } - } - - } catch (Exception ex) { - Logger.Log(new object[] { "Error Code: DB07403", "Errore in ImportLinkFromFile()", ex }); - if (res > 0) res = -1 * res; - } - return res; - } - - - #endregion - - - #region Eventi: Updating, Client_DownloadStringCompleted - - /// - /// Evento che indica un cambiamento di stato nell'AnalizeManager - /// - public event EventHandler Updating; - - private void Client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { - object obj = new Object(); - lock (obj) { - - conteggioEvt++; - - MyWebClient mwb = sender as MyWebClient; - if (state == EngineStatusEnum.Starting) state = EngineStatusEnum.Started; - - - // Verifico se download corretto - if (!e.Cancelled && e.Error == null) { - // aggiorno UI - //RaiseEvent_Updating("(Evt" + conteggioEvt.ToString("0000") + " " + (dtStartTime - DateTime.Now).ToString() + ") Donwloaded: " + mwb.URL.Replace("https://www.annunci69.it/racconti-erotici/", "./")); - RaiseEvent_Updating("[" + (DateTime.Now - dtStartTime).ToString() + "] Donwloaded: " + mwb.URL.Replace("https://www.annunci69.it/racconti-erotici/", "./")); - - // Se pagina è un racconto, lo salvo - if (IsRacLink(mwb.URL)) { - string textData = e.Result; - string FullFileName = mwb.FileName; - System.IO.StreamWriter sw = new System.IO.StreamWriter(FullFileName, false, Encoding.UTF8); - sw.Write(textData); - sw.Flush(); - sw.Close(); - } else { - // Salvo anche i file indice - if (IsIdxLink(mwb.URL)) { - string textData = e.Result; - string FullFileName = mwb.FileName; - System.IO.StreamWriter sw = new System.IO.StreamWriter(FullFileName, false, Encoding.UTF8); - sw.Write(textData); - sw.Flush(); - sw.Close(); - } else { - // non riconosciuto - - } - } - - // Registro che ho eseguito il download del link - downloaded.Add(mwb.URL); - - // Estraggo tutti i link net testo: - List links = new List(); - //if (EstraiA69Link(e.Result, links)) { - if (EstraiLink(e.Result, "/racconti-erotici/", links)) { - //Logger.Information(String.Format("Trovati {0} link nel file {1}", links.Count.ToString("000"), mwb.URL.Replace("https://www.annunci69.it/racconti-erotici/", "./"))); - - // Ciclo su tutti i link estratti dalla pagina: - foreach (string link in links) { - if (!allLinks.Contains(link)) { - // elimino il link di logon - if (link == "https://www.annunci69.it/accedi.php?nop") break; - // 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 - - } else { - // Download con errore, informo l'utente - //RaiseEvent_Updating("(Evt" + conteggioEvt.ToString("0000") + ") Donwload error: " + mwb.URL.Replace("https://www.annunci69.it/racconti-erotici/", "./")); - RaiseEvent_Updating("[" + (DateTime.Now - dtStartTime).ToString() + "] Donwload error: " + mwb.URL.Replace("https://www.annunci69.it/racconti-erotici/", "./")); - } - - - // 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); - string fn = Path.Combine(Cfg.Settings.PathAnalizadedRaccFile, GetFileName(lk)); - using (MyWebClient client = new MyWebClient(lk, fn)) { - client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0"); - client.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); - client.Headers.Add("Cookie", "euconsent-v2=CPG74goPG74goAKAeAENBcCsAP_AAH_AAAwIH3tf_X__bX9j-_59__t0eY1f9_7_v-wzjhfdt-8N2P_X_L0X42E7PF36pq4KuR4Eu3LBIQNlHOHUTUmw6okVrTPsak2Mr7NKJ7LEmnMZe2dYGHtfn91TuZKY7_78_9fz3_-v_v___9f3r-3_3__59X---_e_V399zLv9__3__9gfiASYal8AF2JY4Mk0aVQogQhWEh0AoAKKAYWiawgYXBTsrAI9QQMAEJqAjAiBBiCjFgEAAgEASERASAHggEQBEAgABACpAQgAImAQWAFgYBAAKAaFiBFAEIEhBkcFRymBARItFBPZWAJRd7GmEIZRYAUCj-iowEShBAsDISFg5gAA.YAAAAAAAAAAA"); - client.Headers.Add("DNT", "1"); - client.Headers.Add("TE", "Trailers"); - client.DownloadStringCompleted += Client_DownloadStringCompleted; - client.DownloadStringAsync(new Uri(lk)); - } - } else { - // Finito download: - state = EngineStatusEnum.Stopping; - // salvo gli archivi: - SaveState(); - } - - }//lock - - } - - - - #region Generazione degli eventi dell'engine verso le classi chiamanti: - - /// - /// Attiva l'evento che segnala un cambiamento di stato nel engine (per esempio, terminato il download di un singolo file) - /// - void RaiseEvent_Updating(string msg, int tot, int toDown, int down) { - EventHandler tmp = Updating; - if (null != tmp) tmp(this, new EngineEventArgs(msg, tot, toDown, down)); - } - - /// - /// Attiva l'evento che segnala un cambiamento di stato nel engine (per esempio, terminato il download di un singolo file) - /// - void RaiseEvent_Updating(string msg) { - EventHandler tmp = Updating; - if (null != tmp) tmp(this, new EngineEventArgs(msg, allLinks.Count, toDownload.Count, downloaded.Count)); - } - - #endregion - - - #endregion - - - #region Internal Method: SaveState, GetFileName, IsIdxLink, IsRacLink, LinkType, EstraiLink - - private void SaveState() { - int res = App.DB.SaveData(allLinks, toDownload, downloaded, racLinks); - - 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: - RaiseEvent_Updating(string.Format("Finito il download in {0}", DateTime.Now - dtStartTime)); - - state = EngineStatusEnum.Stopped; - - } - - private string GetFileName(string url) { - if (IsRacLink(url)) { - return url.Replace("https://www.annunci69.it/racconti-erotici/", "A69_").Replace("/", "_").Replace(":", "_").Replace(@"\", "_"); - } else { - return url.Replace("https://www.annunci69.it/racconti-erotici/", "_A69_").Replace("racconti_lista.php?genere=", "Idx_").Replace("&pagina=","_").Replace("/", "_").Replace(":", "_").Replace(@"\", "_") + ".html"; - } - } - - static private bool IsIdxLink(string link) { return link.StartsWith(BASE_LINK_IDX); } - static private bool IsRacLink(string link) { foreach (string tip in Tipologie) { if (link.StartsWith(BASE_LINK_RAC + tip + "/")) return true; } return false; } - static public string LinkType(string link) { - if (IsIdxLink(link)) return "Idx"; - if (IsRacLink(link)) return "Rac"; - //return "Unknown"; - return "Unk"; - } - - public static bool EstraiLink(string txt, string startWith, List links) { - try { - Regex regex = new Regex("(?<=href=\")\\S+?(?=\")"); - Match matchObj = regex.Match(txt); - while (matchObj.Success) { - if (matchObj.Value.StartsWith(startWith)) { links.Add(matchObj.Value.Replace(startWith, "https://www.annunci69.it/racconti-erotici/")); } - if (matchObj.Groups.Count > 1) { - for (int i = 1; i < matchObj.Groups.Count; i++) { - Group group = matchObj.Groups[i]; - if (group.Success) { - if (group.Value.StartsWith(startWith)) { links.Add(group.Value.Replace(startWith, "https://www.annunci69.it/racconti-erotici/")); } - } - } - } - matchObj = matchObj.NextMatch(); - } - return true; - } catch { return false; } - } - - - - #endregion - - - }//class cA69Engine - - - /// - /// Enumerazione di tutti i possibili stati dell'engine: - /// - public enum EngineStatusEnum { - /// - /// Engine da inizializzare - /// - NotReady = 0, - /// - /// Engine inizializzato e pronto a partire - /// - StandBy = 1, - Starting = 2, - Started = 3, - Stopping = 4, - Stopped = 5, - } // enum EngineStatusEnum - - - public class EngineEventArgs : EventArgs { - - - #region Property and Fields: - - - /// - /// Numero di file da analizzare, in totale - /// - public int NTot { get { return nTot; } } - private int nTot; - - public int NtoDown { get { return ntoDown; } } - private int ntoDown; - - public int NDown { get { return nDown; } } - private int nDown; - - public string Message { get { return message; } } - private string message; - - #endregion - - - public EngineEventArgs(string Message, int NTot, int NtoDown, int NDown) { - this.nTot = NTot; - this.ntoDown = NtoDown; - this.nDown = NDown; - this.message = Message; - } - - } // class EngineEventArgs - - - public class MyWebClient : WebClient { - - public string URL; - public string FileName; - public MyWebClient(string url, string fileName) { - this.URL = url; - this.FileName = fileName; - } - - - } // class MyWebClient - - -}//namespace A69WD diff --git a/Src/A69WD/Net/cLink_A69.cs b/Src/A69WD/Net/cLink_A69.cs new file mode 100644 index 0000000..8b24934 --- /dev/null +++ b/Src/A69WD/Net/cLink_A69.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Remoting.Messaging; +using System.Security.Policy; +using System.Text; +using System.Threading.Tasks; + +namespace A69WD.Net { + public class cLink_A69 : iLink { + public static string PageBase { get { return "https://www.annunci69.it"; } } + public static string LoginPageUrl { get { return "https://www.annunci69.it/accedi.php"; } } + public static string LoginPostUrl { get { return "https://www.annunci69.it/include/auth/index.php"; } } + public static string LinkIdxBase { get { return "https://www.annunci69.it/racconti-erotici/racconti_lista.php?genere={Categoria}&pagina={ID}"; } } + public string[] Categorie { get { return Categorie; } } + private static readonly string[] categorie = { "altro", "bdsm", "gay", "incesto", "lesbo", "orge", "prime", "scambio", "tradimenti", "trans", "trio" }; + private readonly string filename; + private readonly string filepath; + private eLinkState status = eLinkState.ToConfirm; + private string fields; + + public string ID => "A69"; + + public string URL { get; } + + public string FileName => filename; + + public string FilePath { get => filepath; } + + public bool Validate => true; + + public eLinkState Status { get => status; set { status = value; } } + + public string Fields { get => fields; set => fields = value; } + + public cLink_A69(string Url, string Filename, string fields = "none", string Filepath = "") { + this.URL = Url; + this.filename = Filename; + this.fields = fields; + this.filepath = string.IsNullOrEmpty(Filepath) ? Cfg.Settings.PathDownloadWorking : Filepath; + this.status = eLinkState.ToConfirm; + } + + + }//class cLink_A69 + +}//namespace A69WD.Net + diff --git a/Src/A69WD/Net/eLinkState.cs b/Src/A69WD/Net/eLinkState.cs new file mode 100644 index 0000000..21f7f27 --- /dev/null +++ b/Src/A69WD/Net/eLinkState.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace A69WD.Net { + + /// + /// Possibili stati ammessi + /// + public enum eLinkState { + + /// + /// Indica un iLink che deve venir testato per capire se è o meno da downloadare + /// + ToConfirm = 1, + /// + /// Indica un iLink che deve venir downloadato + /// + ToDownload = 2, + /// + /// Indica un iLink che è in download + /// + OnDownload = 3, + /// + /// Indica un iLink che deve venir downloadato + /// + ToAnalize = 4, + /// + /// Indica un iLink in cui si è concluso il lavoro. + /// + End = 5, + /// + /// Indica un iLink il cui download/analisi ha avuto un errore + /// + Error = 6, + /// + /// Indica un iLink il cui download/analisi è stato abortito + /// + Abort = 7, + /// + /// Indica un iLink il cui download/analisi è stato cancellato + /// + Cancel = 8, + + }//enum eLinkState + +}//namespace A69WD.Net diff --git a/Src/A69WD/Net/frmDownloader.cs b/Src/A69WD/Net/frmDownloader.cs deleted file mode 100644 index 9d240cf..0000000 --- a/Src/A69WD/Net/frmDownloader.cs +++ /dev/null @@ -1,93 +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; - -namespace A69WD { - - public partial class frmDownloader : Form { - - - public frmDownloader() { - InitializeComponent(); - this.Text = String.Format("A69WD - Dowloader Testi Vrs {0}", cTools.AssemblyVersion); - engine = new cA69Engine(); - engine.Updating += Engine_Updating; - } - - cA69Engine engine = null; - - - /// - /// Metodo per scansionare i link da un file di testo ed inserirli come da downloadare se non ci sono già - /// - 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 void btnDownloadAll_Click(object sender, EventArgs e) { - //engine.Start(true); - //engine.Start(!cbSoloFileIndice.Checked); - engine.StartParallel(!cbSoloFileIndice.Checked, int.Parse(tbNumThred.Text)); - } - - 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(); } - - #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 - - - - }//class frmDownloader -}//namespace A69WD diff --git a/Src/A69WD/Net/iLink.cs b/Src/A69WD/Net/iLink.cs new file mode 100644 index 0000000..19799e8 --- /dev/null +++ b/Src/A69WD/Net/iLink.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace A69WD.Net { + + + public interface iLink { + + /// + /// Stringa identificativa della tipologia di link + /// + string ID { get; } + + + /// + /// URL dell'oggetto da downloadare + /// + string URL { get; } + + /// + /// Nome del file su cui riportare l'oggetto downloadato + /// + string FileName { get; } + + /// + /// Path del file su cui riportare l'oggetto downloadato + /// + string FilePath { get; } + + /// + /// Campo in cui salvo tutti i dati significativi sul link, separati fra loro da -|- + /// + string Fields { get; set; } + + /// + /// Esegue la conferma del link per capire se è valido e si può downloadare. + /// + bool Validate { get; } + + eLinkState Status { get; set; } + + }//interface iLink + +}//namespace A69WD.Net diff --git a/Src/A69WD/Site/cSite_A69.cs b/Src/A69WD/Site/cSite_A69.cs new file mode 100644 index 0000000..2927f96 --- /dev/null +++ b/Src/A69WD/Site/cSite_A69.cs @@ -0,0 +1,215 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using A69WD.Net; +using HtmlAgilityPack; + +namespace A69WD.Site { + + + public class cSite_A69 : iSiteType { + + private readonly HttpClient client; + private readonly string nickname = @"Toky78"; + private readonly string password = @"p!fw05Q9Hc6j5"; + private bool logged = false; + + + public bool Logged => logged; + + /// + /// Esegue l'autenticazione al sito: + /// - Scarica la pagina di autenticazione + /// - analizza quanto scaricato per determinare i campi dinamici 'ts' e 'token' + /// - prepara la risposta al form di identificazione + /// - invia il POST di autenticazione + /// - analizza la risposta per virificare il corretto login + /// + public async Task Authenticate() { + try { + // 1) GET pagina di login + Console.WriteLine("A69 - Richiedo la pagina di login..."); + string loginPageHtml = await client.GetStringAsync(cLink_A69.LoginPageUrl); + + // 2) Parsing HTML per estrarre ts e token + var doc = new HtmlAgilityPack.HtmlDocument(); + doc.LoadHtml(loginPageHtml); + + string ts = doc.DocumentNode + .SelectSingleNode("//input[@name='ts']") + ?.GetAttributeValue("value", ""); + string token = doc.DocumentNode + .SelectSingleNode("//input[@name='token']") + ?.GetAttributeValue("value", ""); + + if (string.IsNullOrWhiteSpace(ts) || string.IsNullOrWhiteSpace(token)) { + Console.WriteLine("A69 - Impossibile estrarre 'ts' o 'token' dalla pagina di login."); + return logged; + } + Console.WriteLine($"A69 - Parametri dinamici trovati: ts={ts}, token={token}"); + + // 3) POST login con valori dinamici + var loginData = new FormUrlEncodedContent(new[] + { + new KeyValuePair("nick", nickname), + new KeyValuePair("pwd", password), + new KeyValuePair("ricordami","1"), + new KeyValuePair("login", "Entra"), + new KeyValuePair("ts", ts), + new KeyValuePair("token", token) + }); + + Console.WriteLine("Invio credenziali di login..."); + var loginResponse = await client.PostAsync(cLink_A69.LoginPostUrl, loginData); + + if (!loginResponse.IsSuccessStatusCode) { + Console.WriteLine($"A69 - Login fallito. HTTP {(int)loginResponse.StatusCode} {loginResponse.ReasonPhrase}"); + return logged; + } + + // Verifica semplice: sulla pagina di login effettuato, ricerco il nome dell'utente: + string loginResult = await loginResponse.Content.ReadAsStringAsync(); + if (loginResult.Contains(nickname)) { + Console.WriteLine("A69 - Login effettuato con successo! Sessione autenticata attiva."); + logged = true; + } else { + Console.WriteLine("A69 - Login non riuscito: il server ha restituito un messaggio di errore."); + logged = false; + } + + } catch (Exception ex) { + Console.WriteLine($"Errore generale: {ex.Message}"); + } + return logged; + } + + public async Task> CrawlPageAsync(iLink lk) { + var links = new List(); + try { + Console.WriteLine($"A69 - Scarico: {lk.URL}"); + HtmlDocument tdoc = null; + + #region ToConfirm + if (lk.Status == eLinkState.ToConfirm) { + // Eseguo la verifica se link da downloadare + eLinkState tstate = App.DB.GetStateByURL(lk.URL); + if ( + (tstate == eLinkState.ToConfirm) || + (tstate == eLinkState.ToDownload) || + (tstate == eLinkState.Error) + ) { + lk.Status = eLinkState.ToDownload; + App.DB.LinkLog(lk); + } else { + lk.Status = eLinkState.End; + App.DB.LinkLog(lk); + } + } + #endregion + + #region ToDownload + if (lk.Status == eLinkState.ToDownload) { + lk.Status = eLinkState.OnDownload; + } + #endregion + + #region OnDownload + if (lk.Status == eLinkState.OnDownload) { + // Scarico il file + var resp = await client.GetAsync(lk.URL); + if (!resp.IsSuccessStatusCode) { + Console.WriteLine($"A69 - Errore HTTP {(int)resp.StatusCode} {resp.ReasonPhrase} per {lk.URL}"); + lk.Status = eLinkState.Error; + //App.DB.LinkLog(lk); + return links; + } + // Scarico la pagina + var thtml = await client.GetStringAsync(lk.URL); + tdoc = new HtmlDocument(); + tdoc.LoadHtml(thtml); + // Salvo il file downloadato + //System.IO.StreamWriter tsw = new System.IO.StreamWriter(lk.DstFilePath, false, Encoding.UTF8); + System.IO.StreamWriter tsw = new System.IO.StreamWriter(System.IO.Path.Combine(lk.FilePath, lk.FileName), false, Encoding.UTF8); + tsw.Write(thtml); + + lk.Status = eLinkState.ToAnalize; + } + #endregion + + #region ToAnalize + // if (lk.Status == eLinkState.ToAnalize) { + // // Estraggo i link alle altre pagine: + // var tnodes = tdoc.DocumentNode.SelectNodes("//div[@id='pagination']//li//a[@href]"); + // if (tnodes != null) { + // foreach (var link in tnodes) { + // var href = link.GetAttributeValue("href", ""); + // if (!string.IsNullOrEmpty(href) && href.StartsWith("/racconti-erotici/racconti_lista.php?genere=")) + // links.Add(cLink_A69.PageBase + href); + // } + // } + // // Rimuove duplicati e ordina alfabeticamente + // links = links + // .Distinct() // elimina duplicati + // .OrderBy(s => s) // ordina alfabeticamente + // .ToList(); + // } + // lk.Status = eLinkState.End; + // App.DB.LinkLog(lk); + #endregion + + #region End + if (lk.Status == eLinkState.End) { + } + #endregion + + #region Error + if (lk.Status == eLinkState.Error) { + } + #endregion + + #region Abort + if (lk.Status == eLinkState.Abort) { + } + #endregion + + #region Cancel + if (lk.Status == eLinkState.Cancel) { + } + #endregion + + Console.WriteLine("Link.Count=" + links.Count.ToString("00")); + + } catch (Exception ex) { + Console.WriteLine($"Errore con {lk.URL}: {ex.Message}"); + lk.Status = eLinkState.Error; + //App.DB.LinkLog(lk); + } + return links; + } + + + public cSite_A69() { + var handler = new HttpClientHandler { + CookieContainer = new CookieContainer(), + UseCookies = true, + AllowAutoRedirect = true, + AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate + }; + + client = new HttpClient(handler); + client.Timeout = TimeSpan.FromSeconds(60); + client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"); + client.DefaultRequestHeaders.Referrer = new Uri(cLink_A69.LoginPageUrl); + } + + + + + + }//class cSite_A69 + +}//namespace A69WD.Site diff --git a/Src/A69WD/Site/iSiteType.cs b/Src/A69WD/Site/iSiteType.cs new file mode 100644 index 0000000..4d4eec7 --- /dev/null +++ b/Src/A69WD/Site/iSiteType.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using A69WD.Net; + + +/* + * + * Interfaccia iSiteType + * --------------------- + * Questa interfaccia definisce il contratto per le diverse tipologie di siti gestiti dal crawler. + * Ogni sito deve implementare: + * - Authenticate(): eventuale autenticazione al sito (PUT, POST, ecc.) + * - ValidateLink(string href): regole di validazione dei link estratti + * - CrawlPageAsync(string url): scarica una pagina e la analizza + * + * In questo modo il programma principale può distinguere facilmente tra siti autenticati e pubblici, + * mantenendo il codice modulare ed estensibile. + * + */ + + + +namespace A69WD.Site { + + /// + /// Interfaccia per gestire le operazioni da fare su un sito + /// + public interface iSiteType { + + /// + /// Booleano per sapere se siamo autenticati al sito + /// (sempre true per i siti senza autenticazione) + /// + bool Logged { get; } + + /// + /// Esegue l'autenticazione al sito + /// + Task Authenticate(); + + /// + /// Elaborazione della pagina linkata: + /// Scarica il link e analizza quanto downloadato + /// + /// + /// + Task> CrawlPageAsync(iLink lk); + + }//interface iSiteType + +}//namespace A69WD.Site diff --git a/Src/A69WD/Net/frmDownloader.Designer.cs b/Src/A69WD/UI/frmDownloader.Designer.cs similarity index 100% rename from Src/A69WD/Net/frmDownloader.Designer.cs rename to Src/A69WD/UI/frmDownloader.Designer.cs diff --git a/Src/A69WD/UI/frmDownloader.cs b/Src/A69WD/UI/frmDownloader.cs new file mode 100644 index 0000000..704402f --- /dev/null +++ b/Src/A69WD/UI/frmDownloader.cs @@ -0,0 +1,112 @@ +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; + +namespace A69WD { + + public partial class frmDownloader : Form { + + + public frmDownloader() { + InitializeComponent(); + this.Text = String.Format("A69WD - Dowloader Testi Vrs {0}", cTools.AssemblyVersion); + //engine = new cA69Engine(); + //engine.Updating += Engine_Updating; + } + + //cA69Engine engine = null; + + + /// + /// Metodo per scansionare i link da un file di testo ed inserirli come da downloadare se non ci sono già + /// + 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) { + ////engine.Start(true); + ////engine.Start(!cbSoloFileIndice.Checked); + //engine.StartParallel(!cbSoloFileIndice.Checked, int.Parse(tbNumThred.Text)); + + // - 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(); + lblST.Text = DateTime.Now.ToString() + " - sito loggato: " + res.ToString(); + // - Verifico directory pe ri download + if (!System.IO.Directory.Exists(Cfg.Settings.PathDownloadWorking)) { System.IO.Directory.CreateDirectory(Cfg.Settings.PathDownloadWorking); } + // - Test di download di un link di indice + iLink lk = new cLink_A69("https://www.annunci69.it/racconti-erotici/altro.html", "Idx_altro_01.html"); + await siteA69.CrawlPageAsync(lk); + // - Test di download di un link di racconto + lk = new cLink_A69("https://www.annunci69.it/racconti-erotici/altro/Oltre-il-desiderio_166769.html", "Rac_0001.html"); + await siteA69.CrawlPageAsync(lk); + // - Test di download di un link protetto + lk = new cLink_A69("https://www.annunci69.it/racconti-erotici/racconti_lista.php?genere=altro&pagina=11", "Idx_altro_11.html"); + await siteA69.CrawlPageAsync(lk); + + } + + 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(); + 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 + + + + }//class frmDownloader +}//namespace A69WD diff --git a/Src/A69WD/Net/frmDownloader.resx b/Src/A69WD/UI/frmDownloader.resx similarity index 100% rename from Src/A69WD/Net/frmDownloader.resx rename to Src/A69WD/UI/frmDownloader.resx