Beispiel #1
0
        public static bool DeComprimi(string percNomeFileZip, string percorsoEstrazione, ref Thread thrZip, string password = null, int timeOutMs = -1, Progressione progressione = null)
        {
            if (Zip.inizializzato == false && inizializza() == false)
            {
                return(false);
            }

            if (FS.ValidaNomeFile(percNomeFileZip, true, CheckExistenceOf.FolderAndFile) == false)
            {
                return(false);
            }

            if (FS.ValidaPercorsoFile(percorsoEstrazione, true, percFileFormattato: out percorsoEstrazione, verEsistenza: CheckExistenceOf.PathFolderOnly) == false)
            {
                return(false);
            }

            bool   esito  = false;
            Thread thread = Thr.AvviaNuovo(() => esito = ThrDeComprimi(percNomeFileZip, percorsoEstrazione, password, progressione));

            if (timeOutMs != 0)   //Non attendo il completamento del thr se = 0
            {
                if (Thr.AttesaCompletamento(ref thread, timeOutMs) == false || esito == false)
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #2
0
        /// <param name="oggDaCompr">può essere: string (file o cartella), List(Of String) (file o cartella), oggDaComprimere (file o cartella), List(Of oggDaComprimere) (file o cartella)</param>
        /// <param name="timeOutMs">0  ==  Non attende la compressione ma ritorna subito  |  -1 ==  Attesa infinita  |  XX ==  Attesa massima fino a XX ms</param>
        public static bool Comprimi(object oggDaCompr, string percNomeFileCompr, out Thread thrZip, TipiArchivio formatoArchivio = TipiArchivio.sevenZip, CompressionLevels livelloCompr = CompressionLevels.Ultra,
                                    string password = null, int timeOutMs = -1, Progressione progressione = null, Mess logMess = null)
        {
            thrZip = null;

            try
            {
                if (logMess == null)
                {
                    logMess = new Mess(LogType.Warn, Log.main.warnUserText);
                }

                if ((Zip.inizializzato == false) && inizializza(logMess) == false)
                {
                    return(false);
                }

                Dictionary <string, string> dizionario; bool esito;

                if (FS.ValidaPercorsoFile(percNomeFileCompr, true, percFileFormattato: out percNomeFileCompr, verEsistenza: CheckExistenceOf.PathFolderOnly, logMess: logMess) == false)
                {
                    return(false);
                }

                if (PreparazioneDizionario(oggDaCompr, out dizionario, logMess) == false)
                {
                    return(false);
                }

                if (dizionario.Count == 0)
                {
                    Log.main.Add(new Mess(LogType.info, "Non ci sono file da comprimere"));
                    return(true);
                }

                esito  = false;
                thrZip = Thr.AvviaNuovo(() => esito = ThrComprimi(dizionario, percNomeFileCompr, formatoArchivio, livelloCompr, password, progressione));

                if (timeOutMs != 0)
                { //Non attendo il completamento del thr se = 0
                    if (Thr.AttesaCompletamento(ref thrZip, timeOutMs) == false || esito == false)
                    {
                        return(false);
                    }
                }

                if (thrZip.ThreadState == ThreadState.Aborted)
                {
                    return(false);
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #3
0
        internal UpLoad(string nome, object configSource = null) : base(nome)
        {
            queue       = new ConcurrentDictionary <UInt64, UploadItem>();
            this.config = new ConfigUpload(this.nome);
            //this.config = (ConfigUpload)Savable.Load(this.config);
            if (configSource != null)
            {
                this.config = (ConfigUpload)this.config.Load(configSource, out _);
            }

            thrScoda = Thr.AvviaNuovo(() => ThrCicloReadInputBufferAndElaborateMainQueue()); //ATTENZIONE deve stare dopo l'inizializzazione di coda
        }
Beispiel #4
0
        private void ThrAvvioUpload(UploadItem elemUpload)
        {
            Thr.SbloccaThrPadre();

            Thread thrDL;

            thrDL = Thr.AvviaNuovo(() => ThrUpload(ref elemUpload));

            if (Thr.AttesaCompletamento(ref thrDL, (elemUpload.TimeoutSec == -1 ? -1 : elemUpload.TimeoutSec * 1000)) == false)
            { //TimeOut
                elemUpload.DescErr     = "Timeout:<" + elemUpload.TimeoutSec + "> secondi, raggiunto";
                elemUpload.UploadState = UplItemState.Timeout;

                Log.main.Add(new Mess(elemUpload.tipoLogTimeout, "", "per l'url:<" + elemUpload.url + ">, " + elemUpload.DescErr));
            }
        }
Beispiel #5
0
        private void CambioProprietaOggT(object sender, PropertyChangedEventArgs args)
        {
            ProprietàOggTCambiata?.Invoke(this, args); //?.Invoke invice della parentesi tonda diretta poichè se nessuno ha sottoscritto l'evento non va in eccezione

            //se la proprietà dell'oggetto di tipo T che è cambiata è tra la lista delle prop.che concorrono all'ordinamento allora rieseguo l'ordinamento
            if ((from tmp in listaOrdinamenti where tmp.PropertyDescriptor.Name == args.PropertyName select tmp).Count() > 0)
            {
                if (this.oggConValidazione == true)                                //ATTENZIONE: Se c'è la validazione di un item della lista da parte del datagrid, tale validazione viene richiamata solamente una volta terminati gli eventi richiamati...
                {
                    Thr.AvviaNuovo(() => thrAttesaValidazioneEOrdina(ref sender)); //...dall'onPropertyChange della proprietà variata(quindi al termine di questa CambioProprietaOggettoT), quindi lancio un thread separato...
                }
                else //                                                         ...che attenderà la fine della validazione per poi eseguire il riordino se l'oggetto risulterà valido
                {
                    Ordina();
                }
            }
        }
Beispiel #6
0
        private void ThrAvvioDownLoad(UInt64 itemKey)
        {
            Thr.SbloccaThrPadre();

            Thread thrDL;

            thrDL = Thr.AvviaNuovo(() => ThrDownload(itemKey));

            DownloadItem elemDownload = null;

            if (Concur.Dictionary_TryGet(this.queue, itemKey, ref elemDownload, out _) == false)
            {
                return;
            }

            if (Thr.AttesaCompletamento(ref thrDL, elemDownload.TimeoutSec == -1 ? -1 : elemDownload.TimeoutSec * 1000) == false)
            { //TimeOut
                elemDownload.DescErr       = "Timeout:<" + elemDownload.TimeoutSec + "> secondi, raggiunto";
                elemDownload.DownloadState = DwlItemState.Timeout;

                Log.main.Add(new Mess(elemDownload.tipoLogTimeout, "", "per l'url:<" + elemDownload.url + ">, " + elemDownload.DescErr));
            }
        }
Beispiel #7
0
        public bool ConnettiDB(Mess logMess = null) //StrConnection strConn = null,
        {
            if (logMess == null)
            {
                logMess = new Mess(LogType.Warn, Log.main.warnUserText);
            }

            this.DisconnettiDB();  //Seve perchè se riutilizzo più volte ConnettiDB dentro una stessa funzione devo chiudere la connessione precedente
            bool esito; Thread thread; string testoTmp;

            esito = false;

            if (connStr == null)
            {
                logMess.testoDaLoggare = "Impossibile connettersi al DB poichè connStr è null";
                Log.main.Add(logMess);
                return(false);
            }

            if (connStr.DbRemoto == false)
            {
                try
                {
                    cmd.Connection = new OleDbConnection(connStr.Completa);

                    thread = Thr.AvviaNuovo(() => esito = ThrCDB_Exec());

                    if (Thr.AttesaCompletamento(ref thread, connStr.TimeOutConnMs) == false)
                    {
                        logMess.testoDaLoggare = "query:<" + cmd.CommandText + "> andata in timeOut, strConn.timeOutConnMs:<" + connStr.TimeOutConnMs + ">";
                        Log.main.Add(logMess);
                        return(false);
                    }

                    if (esito == false)
                    {
                        testoTmp = thrEx != null ? ", ex.mess:<" + thrEx.Message + ">" : "il thread ThrCDB_Exec è ritornato false ma senza eccezioni";

                        logMess.testoDaLoggare = "strConn.completa:<" + connStr.Completa + ">" + testoTmp;
                        Log.main.Add(logMess);
                        return(false);
                    }
                }
                catch
                {
                    Log.main.Add(new Mess(LogType.ERR, logMess.testoDaVisual, "Non è stato possibile connettersi al DataBase locale, strConn.completa:<" + connStr.Completa + ">", visualMsgBox: false));
                    return(false);
                }
            }
            else
            {
                //Dim idRndXConnRemote As String
                //idRndXConnRemote = GeneraStrRandom(5)
                //While stackConnRemoteCmd.TryAdd(idRndXConnRemote, sqlCmd) = False ' * **ATTENZIONE: usare sempre 'TryAdd' e mai la 'GetOrAdd' poichè quest'ultima non è detto che lo faccia l'add
                //End While
                //While stackConnRemoteTra.TryAdd(idRndXConnRemote, sqlTra) = False ' * **ATTENZIONE: usare sempre 'TryAdd' e mai la 'GetOrAdd' poichè quest'ultima non è detto che lo faccia l'add
                //End While
                //While stackConnRemoteStato.TryAdd(idRndXConnRemote, 2) = False  ' * **ATTENZIONE: usare sempre 'TryAdd' e mai la 'GetOrAdd' poichè quest'ultima non è detto che lo faccia l'add
                //End While
                //While stackConnRemoteStato(idRndXConnRemote) = 2
                //    Sleep(1)
                //End While
                //If stackConnRemoteStato(idRndXConnRemote) = 1 Then
                //    sqlCmd = stackConnRemoteCmd.GetOrAdd(idRndXConnRemote, sqlCmd)
                //    sqlTra = stackConnRemoteTra.GetOrAdd(idRndXConnRemote, sqlTra)
                //    EliminaIdRndXConnRemote(idRndXConnRemote)
                //    Return True
                //Else
                //    EliminaIdRndXConnRemote(idRndXConnRemote)
                //    Return False
                //End If
            }
            return(true);
        }
Beispiel #8
0
        public bool ExecNoQuery(string query, CommitRoll commitRollback = CommitRoll.commitRollback, NuovaConn nuovaConn = NuovaConn.seNecessario, StrConnection strConn = null, Int32 timeOutQuery = 0, Mess logMess = null)
        {
            if (logMess == null)
            {
                logMess = new Mess(LogType.ERR, Log.main.errUserText);
            }
            logMess.testoDaLoggare = "";

            Thread thread; Exception thrEx = null; bool esito; string testoTmp;

            if (PreExec(true, query, ref strConn, nuovaConn, ref timeOutQuery, logMess) == false)
            {
                return(false);
            }

            esito  = false;
            thread = Thr.AvviaNuovo(() => esito = ThrENQ_Exec(out thrEx));

            if (Thr.AttesaCompletamento(ref thread, timeOutQuery) == false)
            { //qua non faccio rollback poichè presumo che la connessione remota sia andata persa, se DB in locale non può andare in timeout
                logMess.testoDaLoggare = "query:<" + cmd.CommandText + "> andata in timeOut:<" + timeOutQuery + ">";
                Log.main.Add(logMess);
                return(false);
            }

            if (esito == false)
            {
                try
                {
                    if (commitRollback == CommitRoll.commitRollback || commitRollback == CommitRoll.soloRollback)
                    {
                        tra.Rollback();
                        this.DisconnettiDB();
                    }
                }
                catch (Exception ex)
                {
                    logMess.testoDaVisual  = ""; //Non visualizzo nulla poichè c'è il l'altro log sotto
                    logMess.testoDaLoggare = "eccezione durante rollback, ex.Mess:<" + ex.Message + ">, query:<" + query + ">";
                    Log.main.Add(logMess);
                }

                if (thrEx != null)
                {
                    if (FiltraEccezioniQuery(thrEx) == true)
                    {
                        logMess.testoDaVisual = "";
                        logMess.tipo          = LogType.Warn;
                    }
                    testoTmp = "ex.mess:<" + thrEx.Message + ">";
                }
                else
                {
                    testoTmp = "il thread ThrENQ_Exec è ritornato false ma senza eccezioni";
                }


                logMess.testoDaLoggare = "query:<" + cmd.CommandText + ">, " + testoTmp;
                Log.main.Add(logMess);
                return(false);
            }

            try
            {
                if (commitRollback == CommitRoll.commitRollback)
                {
                    tra.Commit();
                    this.DisconnettiDB();
                }
            }
            catch (Exception ex)
            {
                if (FiltraEccezioniCommit(ex) == true)
                {
                    logMess.testoDaVisual = "";
                    logMess.tipo          = LogType.Warn;
                }

                logMess.testoDaLoggare = "errore durante 'sqlTra.Commit()', ex.Mess:<" + ex.Message + ">, query:<" + query + ">";
                Log.main.Add(logMess);
                return(false);
            }

            return(true);
        }
Beispiel #9
0
        //ATTENZIONE res se non è un ref non funziona
        public bool ExecQuery <T1>(string query, ref T1 res, QryOut @out = QryOut.dataTable, NuovaConn nuovaConn = NuovaConn.seNecessario, StrConnection strConn = null, int timeOutQuery = 0, Mess logMess = null)
        {   //Attenzione: l'out come Datatable costa di più in termini di cpu, dataReader costa meno
            if (logMess == null)
            {
                logMess = new Mess(LogType.ERR, Log.main.errUserText);
            }
            logMess.testoDaLoggare = "";

            Thread thread; Exception thrEx = null; bool esito; string testoTmp;

            if (PreExec(true, query, ref strConn, nuovaConn, ref timeOutQuery, logMess) == false)
            {
                return(false);
            }

            if (res == null)
            {
                this.@out = @out;
            }
            else
            {
                if (res.GetType() == typeof(DataTable))
                {
                    this.@out = QryOut.dataTable;
                }
                else if (res.GetType() == typeof(OleDbDataReader))
                {
                    this.@out = QryOut.dataReader;
                }
                else
                {
                    logMess.testoDaLoggare = "ricevuto res con tipo disatteso, res.GetType.Name:<" + res.GetType().Name + ">";
                    Log.main.Add(logMess);
                    return(false);
                }
            }

            esito = false;
            //se si perde la connessione prima di eseguire cmd.ExecuteReader() (può succede per DB remoto quando si è già connessi, quindi con nuovaConn=False) passano 47 secondi prima che ritorna l'errore data provider interno 30,
            thread = Thr.AvviaNuovo(() => esito = ThrEQ_Exec(ref thrEx), ApartmentState.MTA); //Attenzione se STA, alla 'resOle.Close()' c'è l'eccezione: Impossibile utilizzare oggetti COM separati dai relativi RCW sottostanti.

            if (Thr.AttesaCompletamento(ref thread, timeOutQuery) == false)
            {
                logMess.testoDaLoggare = "query:<" + cmd.CommandText + "> andata in timeOut:<" + timeOutQuery + ">";
                Log.main.Add(logMess);
                return(false);
            }

            if (esito == false)
            {
                if (thrEx != null)
                {
                    if (FiltraEccezioniQuery(thrEx) == true)
                    {
                        logMess.testoDaVisual = "";
                        logMess.tipo          = LogType.Warn;
                    }
                    testoTmp = "ex.mess:<" + thrEx.Message + ">";
                }
                else
                {
                    testoTmp = "il thread ThrEQ_Exec è ritornato false ma senza eccezioni";
                }

                logMess.testoDaLoggare = "query:<" + cmd.CommandText + ">, " + testoTmp;
                Log.main.Add(logMess);
                return(false);
            }
            //Ho dovuto eseguire la resDt.Load(cmd.ExecuteReader()) nel delegato poichè se esegiuvo la resDt.Load(DataReader) qua da la seguente eccezione
            //Impossibile eseguire il cast di oggetti COM di tipo 'System.__ComObject' in tipi di interfaccia 'IRowset'. L'operazione non è stata completata perché la chiamata QueryInterface sul componente COM per l'interfaccia con IID '{ 0C733A7C - 2A1C - 11CE - ADE5 - 00AA0044773D}
            //non è riuscita a causa del seguente errore: Interfaccia non supportata. (Eccezione da HRESULT: 0x80004002 (E_NOINTERFACE)).

            if (res != null)
            {
                if (this.@out == QryOut.dataTable)
                {
                    res = (T1)(dynamic)ResDt;
                }
                else if (this.@out == QryOut.dataReader)
                {
                    res = (T1)(dynamic)ResOle;
                }
            }

            return(true);
        }
Beispiel #10
0
        protected override void ThrCicloReadInputBufferAndElaborateMainQueue()
        {
            Thr.SbloccaThrPadre();

            Thread   thrAvvioUL; Int32 numElemInUpl;
            DateTime timeoutStart; //UInt64 indiceProssElem;
            IOrderedEnumerable <KeyValuePair <UInt64, UploadItem> > elementiDaUpl;

            //indiceProssElem = 1;
#if DEBUG == false
            try
            {
#endif
            while (true)
            {
                Thread.Sleep(9);

                ControlloElementiEStatistiche();

                numElemInUpl = (from tmp in this.queue where tmp.Value.UploadState == UplItemState.UplAvviato select tmp).Count();

                if (numElemInUpl >= this.config.MaxParallelStreams)
                {
                    continue;
                }

                if (this.raggiuntoMaxKBSec)
                {
                    continue;
                }

                elementiDaUpl = from tmp in this.queue where tmp.Value.UploadState == UplItemState.Iniziale orderby tmp.Value.Priority ascending, tmp.Key ascending select tmp; //ho messo il >= indiceProssElem poichè se dovesse succedere che il metodo Accoda salta una chiave,
                                                                                                                                                                                //questo thread non si incanterà, esiste anche il metodo first e firstOrDefault, il primo da eccezione se la query linq non restituisce elementi, nel secondo per il parametro default non si può usare nothing
                if (elementiDaUpl.Count() == 0)
                {
                    continue;
                }

                thrAvvioUL = Thr.AvviaNuovo(() => ThrAvvioUpload(elementiDaUpl.ElementAt(0).Value));

                timeoutStart = DateTime.Now;
                while (true) //Check operation start on item
                {
                    if (elementiDaUpl.ElementAt(0).Value.UploadState != UplItemState.Iniziale)
                    {
                        break;                                                                        //operation started
                    }
                    if ((DateTime.Now - timeoutStart).TotalSeconds > timeoutToStartSec)
                    {
                        elementiDaUpl.ElementAt(0).Value.DescErr = "TimeoutToStart di " + timeoutToStartSec + " secondi raggiunto, url:<" + elementiDaUpl.ElementAt(0).Value.url + ">";
                        Log.main.Add(new Mess(elementiDaUpl.ElementAt(0).Value.tipoLogTimeout, "", "per l'url:<" + elementiDaUpl.ElementAt(0).Value.url + ">, " + elementiDaUpl.ElementAt(0).Value.DescErr));
                        elementiDaUpl.ElementAt(0).Value.UploadState = UplItemState.TimeoutToStart;
                        break;
                    }
                    Thread.Sleep(1);
                }

                //indiceProssElem = elementiDaUpl.ElementAt(0).Key + 1;
            }
#if DEBUG == false
        }

        catch (Exception ex) {
            Thr.NotificaErrThrCiclo(ex, true);
        }
#endif
        }
Beispiel #11
0
        protected override void ThrCicloReadInputBufferAndElaborateMainQueue()
        {
            Thr.SbloccaThrPadre();
            DateTime timeoutStart;
            //UInt64 indiceProssElem;
            IOrderedEnumerable <KeyValuePair <UInt64, DownloadItem> > elementiDaDwl;
            DownloadItem elemDownload = null;

            //indiceProssElem = 1;

#if DEBUG == false
            try {
#endif
            while (true)
            {
                Thread.Sleep(9);

                while (inputBuffer.Count > 0)
                {
                    if (Concur.Queue_TryDequeue(inputBuffer, ref elemDownload) == false)
                    {
                        break;
                    }
                    idItem += 1;
                    elemDownload.IdItemInList = idItem;
                    Concur.Dictionary_TryAddOrUpdate(queue, new KeyValuePair <UInt64, DownloadItem>(idItem, elemDownload), noUpadate: true);
                }

                ControlloElementiEStatistiche();

                ItemInProcessing = (from tmp in this.queue where tmp.Value.DownloadState == DwlItemState.DwlAvviato select tmp).Count();

                if (ItemInProcessing >= this.config.MaxParallelStreams)
                {
                    continue;
                }

                if (this.raggiuntoMaxKBSec)
                {
                    continue;
                }

                elementiDaDwl = from tmp in this.queue where tmp.Value.DownloadState == DwlItemState.Iniziale orderby tmp.Value.Priority ascending, tmp.Key ascending select tmp; //A parità di priority prendo il più vecchio in coda

                ItemToProcess = elementiDaDwl.Count();

                if (ItemToProcess == 0)
                {
                    continue;
                }

                elemDownload = elementiDaDwl.ElementAt(0).Value; //Serve poichè gli elementi della LinQ si aggiornano all'istante quando un parametro della where o della orderby cambiano

                Thread thrDL = Thr.AvviaNuovo(() => ThrAvvioDownLoad(elementiDaDwl.ElementAt(0).Key));

                timeoutStart = DateTime.Now;

                while (true) //Check operation start on item
                {
                    if (elemDownload.DownloadState != DwlItemState.Iniziale)
                    {
                        break;                                                      //operation started
                    }
                    if ((DateTime.Now - timeoutStart).TotalSeconds > timeoutToStartSec)
                    {
                        elemDownload.DescErr = "TimeoutToStart di " + timeoutToStartSec + " secondi raggiunto, url:<" + elemDownload.url + ">";
                        Log.main.Add(new Mess(elemDownload.tipoLogTimeout, "", "per l'url:<" + elemDownload.url + ">, " + elemDownload.DescErr));
                        elemDownload.DownloadState = DwlItemState.TimeoutToStart;
                        break;
                    }
                    Thread.Sleep(1);
                }

                Thread.Sleep(config.SleepAfterOneOperationMs);

                //while (elemDownload.DownloadState == DwlItemState.DwlAvviato)
                //{
                //    Thread.Sleep(1);
                //}
                //indiceProssElem = elementiDaDwl.ElementAt(0).Key + 1;
            }
#if DEBUG == false
        }

        catch (Exception ex) {
            Thr.NotificaErrThrCiclo(ex, true);
        }
#endif
        }