using System; using System.Collections.Generic; //using System.Collections; using System.Text; using System.Data; using System.Configuration; using System.Diagnostics; using SEILoader.SEI; using SEILoader.SIMPB; using System.Security.Cryptography.X509Certificates; using System.Net.Security; using System.Runtime.CompilerServices; using System.Threading; using log4net; namespace SEILoader { class Program { private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static string idElaborazione; static int Main(string[] args) { log4net.Config.XmlConfigurator.Configure(); CommandLineArgs clArgs = new CommandLineArgs(args); string tipoOperazione; int sleepTime; int maxRichieste; int maxErrors ; int exitcode=0; char tipoElaborazioneParallela= '?' ; bool sendMail = false; bool calcolaPB = false; string interattivo = clArgs["interattivo"]; //Controlliamo se il task parte in modalità tng o interattiva if (interattivo == null) { // Il Servizio è partito in modalità tng TngManager.init(args); } else { if (clArgs["?"] != null || clArgs["help"] != null) { log.Info("fine elaborazione - linea di comando vuota. "); Console.Write("usage example:\n seiloader -filtro={A|S|F|C|N} [-id=] [-richieste=] [-sleep=] [-errori=] -interattivo"); pausa(interattivo); return 1; } } tipoOperazione = clArgs["filtro"]; idElaborazione = clArgs["id"]; if(clArgs["tipo"]!= null && clArgs["tipo"].Length>0) tipoElaborazioneParallela = clArgs["tipo"][0]; int.TryParse(clArgs["sleep"], out sleepTime); int.TryParse(clArgs["richieste"], out maxRichieste); int.TryParse(clArgs["errori"], out maxErrors); if (clArgs["mail"] != null) sendMail = ("yYSs".Contains(clArgs["mail"])); else sendMail = Properties.Settings.Default.sendMail; if (clArgs["riassegnazione"] != null) calcolaPB = true; else calcolaPB = Properties.Settings.Default.calcolaPB; if (tipoOperazione == null) tipoOperazione = Properties.Settings.Default.tipoOperazione; if (idElaborazione == null) idElaborazione = Properties.Settings.Default.idElaborazione; if (maxErrors == 0) maxErrors = Properties.Settings.Default.maxErrors; if (maxRichieste == 0) maxRichieste = Properties.Settings.Default.maxRichieste; if (sleepTime == 0) sleepTime = Properties.Settings.Default.sleepTime; if (tipoElaborazioneParallela == '?') tipoElaborazioneParallela = Properties.Settings.Default.tipoElaborazioneParallela; log.Info("-------------------------------------------------------------------------"); log.Info("avvio elaborazione"); log.Info("argomenti linea di comando:" + string.Join(" ", args)); log.Debug("tipoOperazione=" + tipoOperazione); log.Debug("idElaborazione=" + idElaborazione); log.Debug("sleepTime=" + sleepTime); log.Debug("maxRichieste=" + maxRichieste); log.Debug("maxErrors=" + maxErrors); log.Debug("sendMail=" + sendMail); log.Debug("calcolaPB=" + calcolaPB); log.Debug("tipoElaborazioneParallela=" + tipoElaborazioneParallela); try { //START TngManager.avviaTNG(); Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress); if (!DbManager.inizioElaborazione(idElaborazione, string.Join(" ", args), tipoOperazione)) { TngManager.erroreTNG(); log.Info("richiesta di elaborazione annullata. in corso un'altra elaborazione"); exitcode = 1; } else { int numeroClienti = 0; if (tipoElaborazioneParallela == 'Z') { DbManager.cleanVar(); numeroClienti = DbManager.contaTabellaC6(idElaborazione); log.Info("Numero clienti = " + numeroClienti); DbManager.leggiTabellaC6(idElaborazione); } else { if (tipoOperazione != "N") DbManager.popolaTabella(idElaborazione, tipoOperazione); numeroClienti = DbManager.contaTabella(idElaborazione); log.Info("Numero clienti = " + numeroClienti); DbManager.leggiTabella(idElaborazione); } TracingManager.Inizializza(idElaborazione, numeroClienti); ThreadPool.SetMaxThreads(60, 40); //ThreadPool.SetMinThreads(10, 5); CaricamentoParallelo.avviaCaricamentoParallelo(maxRichieste, idElaborazione, sleepTime, maxErrors, calcolaPB, numeroClienti, tipoElaborazioneParallela); if (!CaricamentoParallelo.aspettaConclusione()) { DbManager.annullaTabella(idElaborazione); log.Info("Esecuzione interrotta per raggiungimento del numero massimo di errrori"); TngManager.erroreTNG(); exitcode = 1; } else { TngManager.terminaTNG(); exitcode = 0; } } } catch (DataBaseException ex) { log.Error("Errore Database:\n" + TracingManager.getDataBaseException(ex)); //ERROR TngManager.erroreTNG(); exitcode = 1; } catch (Exception ex) { log.Error("Errore:\n" + TracingManager.getException(ex)); //ERROR TngManager.erroreTNG(); exitcode = 1; } finally { log.Info("fine elaborazione"); log.Info("-------------------------------------------------------------------------"); try { TracingManager.terminaElaborazione(exitcode); TracingManager.TracciaStatistiche(idElaborazione, sendMail); } catch { } } if (tipoElaborazioneParallela != 'Z') pausa(interattivo); return exitcode; } static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e) { DbManager.annullaTabella(idElaborazione); log.Info("elaborazione interrotta"); log.Info("-------------------------------------------------------------------------"); //FINISH TngManager.erroreTNG(); TracingManager.terminaElaborazione(1); Environment.Exit(1); } private static void pausa(string pausa) { if (pausa == null) return; Console.Write("premere Enter per continuare"); Console.ReadLine(); } } }