Importazione dei racconti dai file in una cartella
- Testata procedura e sembra corretta, ma diagnostica non corretta - Manca navigazione per selezione della cartella. ToDo: - Aggiungere gestione parallela della FIFO secondo vecchi modello per aumentare il feedback alla UI - Inserire anche l'estrazione dei racconti - Per ora metto tutto il DB in memoria, poi dovrò ottimizzare come su ATDB
This commit is contained in:
1 parent
608268b36e
commit
27795c5620
3 files changed
+134
-19
No files matched your search
@@ -90,7 +90,7 @@ namespace A69WD.Net {
|
||||
public static bool InsertStartLink(Service_Crawler service) {
|
||||
//string url = LinkIdxBase.Replace("{Categoria}", "altro").Replace("{ID}", "1"); //LinkIdxBase.Replace("{Categoria}", "trio").Replace("{ID}", "1");
|
||||
//string name = "_A69_altro_0001.html"; //"_A69_trio_0001.html";
|
||||
//service.EnqueueUrl(new cLink_A69(url, name));
|
||||
//serviceCrawler.EnqueueUrl(new cLink_A69(url, name));
|
||||
//return true;
|
||||
int i = 1;
|
||||
try {
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using A69WD.Data;
|
||||
using A69WD.Net;
|
||||
using A69WD.Site;
|
||||
|
||||
|
||||
|
||||
namespace A69WD.Service {
|
||||
|
||||
@@ -12,6 +19,103 @@ namespace A69WD.Service {
|
||||
|
||||
// Thread worker che consuma la coda
|
||||
private Thread _workerThread;
|
||||
private readonly Label _lblInCorso;
|
||||
private readonly ProgressBar _progressBar;
|
||||
private string _path;
|
||||
// Contatori
|
||||
private int _totali = 0;
|
||||
private int _completati = 0;
|
||||
private int _errori = 0;
|
||||
|
||||
public Service_Importer(Label lblInCorso, ProgressBar pbStatus) {
|
||||
_lblInCorso = lblInCorso;
|
||||
_progressBar = pbStatus;
|
||||
}
|
||||
|
||||
public void StartWorker(string path) {
|
||||
_path = path;
|
||||
_workerThread = new Thread(ProcessWorking) { IsBackground = true };
|
||||
_workerThread.Start();
|
||||
}
|
||||
|
||||
public void StopWorker() {
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private async void ProcessWorking() {
|
||||
string[] files = System.IO.Directory.GetFiles(_path, "A69_*.html");
|
||||
_totali = files.Length;
|
||||
_completati = 0;
|
||||
_errori = 0;
|
||||
UpdateCounters();
|
||||
|
||||
// foreach (string file in files) {
|
||||
// Task.Run(async () => {
|
||||
// Logger.Warning($"Start estrazione racconto: {file}");
|
||||
// cLink_A69 lk = new cLink_A69("url", file);
|
||||
// cRac rac = await lk.EstraiRac(file);
|
||||
// if (rac != null) {
|
||||
// // Racconto estratto correttamente, lo salvo sul DB
|
||||
// Logger.Warning($"Start estrazione racconto: {file}");
|
||||
// int res = App.DB.ImportRac(rac);
|
||||
// if (res != 1) {
|
||||
// // Errore nel salvataggio
|
||||
// Interlocked.Increment(ref _errori);
|
||||
// } else {
|
||||
// // salvataggio corretto
|
||||
// Interlocked.Increment(ref _completati);
|
||||
// }
|
||||
// } else {
|
||||
// Interlocked.Increment(ref _errori);
|
||||
// }
|
||||
// UpdateCounters();
|
||||
// });
|
||||
// }
|
||||
|
||||
foreach (string file in files) {
|
||||
string name = System.IO.Path.GetFileName(file);
|
||||
Logger.Warning($"Import - Start estrazione racconto: {name}");
|
||||
|
||||
cLink_A69 lk = new cLink_A69(file, name);
|
||||
cRac rac = await lk.EstraiRac(file);
|
||||
if (rac != null) {
|
||||
// Racconto estratto correttamente, lo salvo sul DB
|
||||
Logger.Warning($"Import - estrazione corretta: {name}");
|
||||
int res = App.DB.ImportRac(rac);
|
||||
if (res != 1) {
|
||||
// errore nel salvataggio
|
||||
Logger.Warning($"Import - errore nel salvataggio: {name}");
|
||||
Interlocked.Increment(ref _errori);
|
||||
} else {
|
||||
// salvataggio ok
|
||||
Logger.Warning($"Import - racconto salvato: {name}");
|
||||
Interlocked.Increment(ref _completati);
|
||||
}
|
||||
} else {
|
||||
Logger.Warning($"Import - estrazione errata: {name}");
|
||||
Interlocked.Increment(ref _errori);
|
||||
}
|
||||
UpdateCounters();
|
||||
}
|
||||
UpdateCounters();
|
||||
}
|
||||
|
||||
|
||||
private void UpdateCounters() {
|
||||
if (_lblInCorso.InvokeRequired) {
|
||||
_lblInCorso.Invoke(new Action(UpdateCounters));
|
||||
return;
|
||||
}
|
||||
|
||||
int daFare = _totali - _completati - _errori;
|
||||
|
||||
_lblInCorso.Text = $"Totali: {_totali} - Completati: {_completati} - Errori: {_errori} - Da fare: {daFare}";
|
||||
|
||||
_progressBar.Maximum = _totali > 0 ? _totali : 1;
|
||||
_progressBar.Value = _completati + _errori;
|
||||
}
|
||||
|
||||
|
||||
}//class Service_Importer
|
||||
|
||||
@@ -98,18 +98,18 @@ namespace A69WD {
|
||||
|
||||
|
||||
// Preparo il servizio
|
||||
service = new Service_Crawler(lblST, pbST);
|
||||
serviceCrawler = new Service_Crawler(lblST, pbST);
|
||||
// Inserisco i link iniziali nella coda
|
||||
if (!cLink_A69.InsertStartLink(service)) {
|
||||
if (!cLink_A69.InsertStartLink(serviceCrawler)) {
|
||||
lblST.Text = "Inserimento A69 start link fault.";
|
||||
return;
|
||||
}
|
||||
// avvio il servizio
|
||||
service.StartWorker(siteA69);
|
||||
serviceCrawler.StartWorker(siteA69);
|
||||
|
||||
|
||||
}
|
||||
private Service_Crawler service = null;
|
||||
private Service_Crawler serviceCrawler = null;
|
||||
|
||||
|
||||
private void btnShowLog_Click(object sender, EventArgs e) {
|
||||
@@ -125,8 +125,9 @@ namespace A69WD {
|
||||
private void btnClose_Click(object sender, EventArgs e) {
|
||||
//if (engine.Stop()) this.Close();
|
||||
|
||||
// fermo il servizio
|
||||
if (service != null) service.StopWorker();
|
||||
// fermo i servizi
|
||||
if (serviceCrawler != null) serviceCrawler.StopWorker();
|
||||
if (serviceImporter != null) serviceImporter.StopWorker();
|
||||
|
||||
this.Close();
|
||||
}
|
||||
@@ -157,20 +158,30 @@ namespace A69WD {
|
||||
//
|
||||
#endregion
|
||||
|
||||
private async void btnImport_Click(object sender, EventArgs e) {
|
||||
string fp = "C:\\Commesse\\_zPrivate\\A69WD\\Test\\Down\\__A69_altro_Collarini-e-fantasie_166756.html";
|
||||
cLink_A69 lk = new cLink_A69("Tmp", "tmp");
|
||||
cRac rac = await lk.EstraiRac(fp);
|
||||
if (rac != null) {
|
||||
//foreach (string tag in rac.Tags) {
|
||||
for (int i = 0; i<rac.Tags.Count; i++) {
|
||||
Console.WriteLine(rac.Tags[i]);
|
||||
}
|
||||
// Racconto estratto correttamente, lo salvo sul DB
|
||||
App.DB.ImportRac(rac);
|
||||
}
|
||||
private void btnImport_Click(object sender, EventArgs e) {
|
||||
// string fp = "C:\\Commesse\\_zPrivate\\A69WD\\Test\\Down\\__A69_altro_Collarini-e-fantasie_166756.html";
|
||||
// cLink_A69 lk = new cLink_A69("Tmp", "tmp");
|
||||
// cRac rac = await lk.EstraiRac(fp);
|
||||
// if (rac != null) {
|
||||
// //foreach (string tag in rac.Tags) {
|
||||
// for (int i = 0; i<rac.Tags.Count; i++) {
|
||||
// Console.WriteLine(rac.Tags[i]);
|
||||
// }
|
||||
// // Racconto estratto correttamente, lo salvo sul DB
|
||||
// App.DB.ImportRac(rac);
|
||||
// }
|
||||
|
||||
// Preparo il servizio
|
||||
serviceImporter = new Service_Importer(lblST, pbST);
|
||||
|
||||
// Per ora uso la directory di default, poi metteremo selezione
|
||||
string path = Cfg.Settings.PathDownloadWorking;
|
||||
|
||||
// avvio il servizio
|
||||
serviceImporter.StartWorker(path);
|
||||
|
||||
}
|
||||
private Service_Importer serviceImporter = null;
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user