コード例 #1
0
ファイル: SortBindList.cs プロジェクト: NickHola/Backupper
        private void thrAttesaValidazioneEOrdina(ref object oggT)
        {
            (oggT as ISortBindObj).SincroValidazioneRiordino = SincroValidazioneRiordino.RichiamatoRiordino; //Deve stare
            Thr.SbloccaThrPadre();
            (oggT as ISortBindObj).TimeOutValidazionMs = 1000;                                               //Possibilità poi aggiornarlo da validazione
            DateTime oraAtt = DateTime.Now;

            while ((oggT as ISortBindObj).SincroValidazioneRiordino == SincroValidazioneRiordino.RichiamatoRiordino || (oggT as ISortBindObj).SincroValidazioneRiordino == SincroValidazioneRiordino.InValidazione)
            {
                //DataOra.SleepConDoEvents(1);
                Thread.Sleep(1);
                if (DataOra.AttesaTempo(ref oraAtt, (oggT as ISortBindObj).TimeOutValidazionMs) == true)
                {
                    break;
                }
            }
            if ((oggT as ISortBindObj).SincroValidazioneRiordino != SincroValidazioneRiordino.ValidazioneTerminata)
            {
                Log.main.Add(new Mess(LogType.ERR, Log.main.errUserText, "SincroValidazioneRiordino non è ancora ValidazioneTerminata dopo:<" + (oggT as ISortBindObj).TimeOutValidazionMs + "> ms, valore SincroValidazioneRiordino:<" + (oggT as ISortBindObj).SincroValidazioneRiordino.ToString() + ">"));
            }

            if ((oggT as IValidation).IsValid == false)
            {
                return;
            }
            (oggT as ISortBindObj).SincroValidazioneRiordino = SincroValidazioneRiordino.InRiordino;
            Ordina();
            (oggT as ISortBindObj).SincroValidazioneRiordino = SincroValidazioneRiordino.FineRiordino;
        }
コード例 #2
0
        ///<summary>La si usa al posto di thread.Join poichè quest'ultima blocca l'interfaccia grafica, mentre qua si usa il DoEvents</summary>
        ///<param name="timeOutMs">Se -1 attesa infinita</param>
        public static bool AttesaCompletamento(ref Thread thread, int timeOutMs)
        {
            DateTime oraInizio = DateTime.MinValue; bool esito;

            if (Thread.CurrentThread.ManagedThreadId == 1)
            { //Se il thread è quello dell'ui allora devo per forza fare il DoEvents per non bloccare l'interfaccia ma bloccare l'esecuzione del codice.
                esito = true;
                if (timeOutMs > -1)
                {
                    oraInizio = DateTime.Now;
                }

                while (thread.IsAlive)
                {
                    Util.DoEvents();
                    if (timeOutMs != -1 && DataOra.AttesaTempo(ref oraInizio, (UInt64)timeOutMs) == true)
                    {
                        esito = false;
                    }
                }
            }
            else
            {
                esito = thread.Join(timeOutMs);
            }                                   //thread.Join ritorna true se il thr completa l'esecuzione entro il tempo previsto, se timeout = -1 attesa infinita

            if (thread.IsAlive)
            {
                thread.Abort();
            }

            return(esito);
        }
コード例 #3
0
ファイル: Root.cs プロジェクト: NickHola/Backupper
        internal static void ThrMostraNotificaAccessoRoot()
        {
            UInt16   intervalloVisualMessMs;
            DateTime attesaTempo = DateTime.MinValue;

            ntiRoot                 = new NotifyIcon();
            ntiRoot.Icon            = Main.Properties.Resources.KeyRootIcon;
            ntiRoot.Text            = "Accesso root";
            ntiRoot.BalloonTipTitle = App.SharedCodeApp.GetAppName();

#if DEBUG == true
            intervalloVisualMessMs = 60000;
#else
            intervalloVisualMessMs = 30000;
#endif


#if DEBUG == false
            try
            {
#endif
            while (true)
            {
                Thread.Sleep(500);
                if (AccessoRoot == true)
                {
                    if (ntiRoot.Visible == false)
                    {
                        ntiRoot.Visible        = true;
                        ntiRoot.BalloonTipText = "Accesso root ATTIVO";
                    }
                    if (DataOra.AttesaTempo(ref attesaTempo, intervalloVisualMessMs) == false)
                    {
                        continue;
                    }
                    ntiRoot.ShowBalloonTip(5000);
                }
                else
                {
                    if (ntiRoot.Visible == true)
                    {
                        ntiRoot.BalloonTipText = "Accesso root RIMOSSO";
                        ntiRoot.ShowBalloonTip(5000);
                        ntiRoot.Visible = false;
                        attesaTempo     = DateTime.MinValue;
                    }
                }
            }

#if DEBUG == false
        }

        catch (Exception ex)
        { Thrs.Thr.NotificaErrThrCiclo(ex, true); }
#endif
        }
コード例 #4
0
        public static bool Dictionary_TryGet <T1, T2>(ConcurrentDictionary <T1, T2> dizionario, T1 chiave, ref T2 valore, out bool esiste, UInt32 timeOutMs = 150, Mess logMess = null)
        { //Concurrent.ConcurrentDictionary(Of Object, Object)
            DateTime oraInizio = DateTime.MinValue;

            esiste = false;

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

            if (dizionario == null)
            {
                logMess.testoDaLoggare = "ricevuto dizionario a nothing";
                Log.main.Add(logMess);
                return(false);
            }

            if (chiave == null)
            {
                logMess.testoDaLoggare = "ricevuto chiave a nothing";
                Log.main.Add(logMess);
                return(false);
            }

            if (dizionario.ContainsKey(chiave) == true)
            {
                esiste = true;
                while (dizionario.TryGetValue(chiave, out valore) == false)
                {
                    if (oraInizio == DateTime.MinValue)
                    {
                        oraInizio = DateTime.Now;                                 //Inizializzazione dentro poichè normalmente qui non ci entrerà e quindi vado più veloce
                    }
                    if (DataOra.AttesaTempo(ref oraInizio, timeOutMs) == true)
                    {
                        logMess.testoDaLoggare = "TryGetValue raggiunto timeOutMs:<" + timeOutMs + ">, per la chiave:<" + chiave.ToString() + ">";
                        Log.main.Add(logMess);
                        return(false);
                    }
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
コード例 #5
0
        public static DataRow FindUser(string userName)
        {
            DataRow   row   = null;
            DataTable table = (DataTable)HttpContext.Current.Application["connec"];
            int       num   = LibTable.FindRowByColumn(table, "user", userName);

            if (num >= 0)
            {
                row = table.Rows[num];
            }
            //lưu connecstring
            DataOra _ora = new DataOra();

            _ora.connecString = LibConvert.ObjectToString(row["connec"]);
            return(row);
        }
コード例 #6
0
        public static bool Queue_TryDequeue <T1>(ConcurrentQueue <T1> queue, ref T1 oggetto, UInt32 timeOutMs = 150, Mess logMess = null)
        { //queue As Concurrent.ConcurrentQueue(Of Object)
            DateTime oraInizio = DateTime.MinValue;

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

            if (queue == null)
            {
                logMess.testoDaLoggare = "ricevuto queue a nothing";
                Log.main.Add(logMess);
                return(false);
            }

            if (queue.Count == 0)
            {
                return(false);
            }

            while (queue.TryDequeue(out oggetto) == false)
            {
                if (oraInizio == DateTime.MinValue)
                {
                    oraInizio = DateTime.Now;                                  //Inizializzazione dentro poichè normalmente qui non ci entrerà e quindi vado più veloce
                }
                if (queue.Count == 0)
                {
                    return(false);
                }

                if (DataOra.AttesaTempo(ref oraInizio, timeOutMs) == true)
                {
                    logMess.testoDaLoggare = "TryDequeue raggiunto timeOutMs:<" + timeOutMs + ">";
                    Log.main.Add(logMess);
                    return(false);
                }
            }
            return(true);
        }
コード例 #7
0
ファイル: UpLoad.cs プロジェクト: NickHola/Backupper
        private void ThrUpload(ref UploadItem elemUpload)
        {
            Thr.SbloccaThrPadre();
            WebClient     client; string suffFileCorrotto; Uri fullUrlIniziale; DateTime tmpAttesa;
            FtpWebRequest ftpWebRequest; FtpWebResponse ftpResponse; FtpStatusCode ftpStatusCode;

            suffFileCorrotto = "";
            client           = new WebClient(); //, flusso As New IO.MemoryStream

            try
            {
                client.UploadDataCompleted   += UploadTerminato;
                client.UploadProgressChanged += PercentualeUpload;

                //client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)") 'Aggiungo lo user agent nell'header nel caso la richiesta contiene una query.

                client.Credentials = DammiCredenziali(ref elemUpload);

                elemUpload.OperationStartDate = DateTime.Now;
                elemUpload.UploadState        = UplItemState.UplAvviato;

                if (elemUpload.UploadType == UploadType.Ftp)
                {
                    if (elemUpload.CorruptFileNameSuffix != "")
                    {
                        suffFileCorrotto = elemUpload.CorruptFileNameSuffix;
                    }
                    else
                    {
                        suffFileCorrotto = config.suffFileCorrotto;
                    }
                }

                fullUrlIniziale = new Uri(Path.Combine(elemUpload.url, elemUpload.FileName) + suffFileCorrotto);

                client.UploadDataAsync(fullUrlIniziale, null, elemUpload.Data, elemUpload);
                //client.UploadData(fullUrl, elemUpload.dati)  'Non scatena glie eventi UploadProgressChanged e UploadDataCompleted

                //AttesaBoolean(client.IsBusy, -1) 'Per le proprità(come IsBusy) se cambia di valore sembra che non lo sente quindi non posso utilizzare AttesaBoolean
                while (client.IsBusy)
                {
                    Thread.Sleep(1);
                }

                tmpAttesa = DateTime.Now;

                while (elemUpload.UploadState == UplItemState.UplAvviato)
                {
                    if (DataOra.AttesaTempo(ref tmpAttesa, 1000) == true)
                    {
                        Log.main.Add(new Mess(LogType.ERR, Log.main.errUserText, "Da quando client non è Busy, lo statoUpload non si è aggiornato in tempo utile, fullUrlIniziale:<" + fullUrlIniziale.OriginalString + ">", visualMsgBox: false));
                        elemUpload.UploadState = UplItemState.Eccezione;
                        client.Dispose();
                        break;
                    }
                }

                client.Dispose();

                if (elemUpload.UploadType == UploadType.Ftp)
                {
                    ftpWebRequest             = (FtpWebRequest)System.Net.FtpWebRequest.Create(fullUrlIniziale);
                    ftpWebRequest.Credentials = DammiCredenziali(ref elemUpload);
                    ftpWebRequest.Method      = System.Net.WebRequestMethods.Ftp.GetFileSize;
                    //MyFtpWebRequest.RenameTo() = nomeFile

                    ftpResponse = (FtpWebResponse)ftpWebRequest.GetResponse();

                    if (elemUpload.Data.Length != ftpResponse.ContentLength)
                    {
                        Log.main.Add(new Mess(LogType.Warn, Log.main.warnUserText, "Rilevate dimensioni differenti tra dati da inviare e dati inviati, elemUpload.dati.Length:<" + elemUpload.Data.Length + ">, ftpResponse.ContentLength:<" + ftpResponse.ContentLength + ">, fullUrlIniziale:<" + fullUrlIniziale.OriginalString + ">"));
                        ftpResponse.Close();
                        return;
                    }

                    ftpResponse.Close();

                    ftpWebRequest             = (FtpWebRequest)System.Net.FtpWebRequest.Create(fullUrlIniziale);
                    ftpWebRequest.Credentials = DammiCredenziali(ref elemUpload);
                    ftpWebRequest.Method      = System.Net.WebRequestMethods.Ftp.Rename;
                    ftpWebRequest.RenameTo    = elemUpload.FileName;
                    ftpResponse = (FtpWebResponse)ftpWebRequest.GetResponse();

                    ftpStatusCode = ftpResponse.StatusCode;

                    if (ftpStatusCode != FtpStatusCode.FileActionOK)
                    {
                        Log.main.Add(new Mess(LogType.Warn, Log.main.warnUserText, "Non sono riuscito a rinominare il file, fullUrlIniziale:<" + fullUrlIniziale.OriginalString + "> in elemUpload.nomeFile:<" + elemUpload.FileName + ">"));
                        ftpResponse.Close();
                        return;
                    }
                    ftpResponse.Close();
                }
            }
            catch (ThreadAbortException ex)  //Thread interrupted by abort, do nothing
            { var tmp = ex; }
            catch (Exception ex)
            {
                Log.main.Add(new Mess(elemUpload.tipoLogEccezione, "", "Eccezione per l'url:<" + elemUpload.url + ">, ex.mess:<" + ex.Message + ">"));
                elemUpload.DescErr     = ex.Message;
                elemUpload.UploadState = UplItemState.Eccezione;
            }
            finally
            {
                client.CancelAsync();
            }
        }
コード例 #8
0
 public virtual string GetEntry()
 {
     // formato: DataOra Luogo Username
     return(DataOra.ToString() + " " + Luogo + " " + Username);
 }
コード例 #9
0
        public static bool Dictionary_TryRemove <T1, T2>(ConcurrentDictionary <T1, T2> dizionario, object keyOrKeyValue, UInt32 timeOutMs = 150, Mess logMess = null)
        { //Concurrent.ConcurrentDictionary(Of Object, Object)
            T1 key; DateTime oraInizio = DateTime.MinValue; T2 tmpObj;

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

            if (dizionario == null)
            {
                logMess.testoDaLoggare = "ricevuto dizionario a nothing";
                Log.main.Add(logMess);
                return(false);
            }

            if (keyOrKeyValue == null)
            {
                logMess.testoDaLoggare = "ricevuto keyOrKeyValue a nothing";
                Log.main.Add(logMess);
                return(false);
            }


            if (Util.GetPropertyOrFieldValue(keyOrKeyValue, "Key", out key) == true)
            {
                if (key == null)
                {
                    logMess.testoDaLoggare = "ricevuto keyOrKeyValue.key a null";
                    Log.main.Add(logMess);
                    return(false);
                }
                //if (keyOrKeyValue.GetType().GetProperty("Key") != null || keyOrKeyValue.GetType().GetField("Key") != null)
                //{
                //    if (keyOrKeyValue.key == null)
                //    {
                //        logMess.testoDaLoggare = "ricevuto keyOrKeyValue.key a nothing";
                //        Log.main.Acc(logMess);
                //        return false;
                //    }
                //    key = keyOrKeyValue.key;
                //}
            }
            else
            {
                key = (T1)keyOrKeyValue;
            }


            if (dizionario.ContainsKey(key) == false)
            {
                return(true);
            }

            while (dizionario.TryRemove(key, out tmpObj) == false)
            {
                if (oraInizio == DateTime.MinValue)
                {
                    oraInizio = DateTime.Now;                                 //Inizializzazione dentro poichè normalmente qui non ci entrerà e quindi vado più veloce
                }
                if (DataOra.AttesaTempo(ref oraInizio, timeOutMs) == true)
                {
                    logMess.testoDaLoggare = "TryRemove raggiunto timeOutMs:<" + timeOutMs + ">, per la keyOrKeyValue.key:<" + key.ToString() + ">";
                    Log.main.Add(logMess);
                    return(false);
                }
            }
            return(true);
        }
コード例 #10
0
        public static bool Dictionary_TryAddOrUpdate <T1, T2>(ConcurrentDictionary <T1, T2> dizionario, object keyValue, UInt32 timeOutMs = 150, bool noUpadate = false, Mess logMess = null)
        { //Concurrent.ConcurrentDictionary(Of Object, Object)
            DateTime oraInizio = DateTime.MinValue;
            T1       key; T2 value, currentValue;

            currentValue = default(T2);

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

            if (dizionario == null)
            {
                logMess.testoDaLoggare = "ricevuto dizionario a null";
                Log.main.Add(logMess);
                return(false);
            }

            if (keyValue == null)
            {
                logMess.testoDaLoggare = "ricevuto keyValue a null";
                Log.main.Add(logMess);
                return(false);
            }

            if (Util.GetPropertyOrFieldValue(keyValue, "Key", out key) == false)
            {
                logMess.testoDaLoggare = "ricevuto keyValue senza proprietà o campo key";
                Log.main.Add(logMess);
                return(false);
            }

            if (Util.GetPropertyOrFieldValue(keyValue, "Value", out value) == false)
            {
                logMess.testoDaLoggare = "ricevuto keyValue senza proprietà o campo value";
                Log.main.Add(logMess);
                return(false);
            }


            if (dizionario.ContainsKey(key) == true)
            {
                if (noUpadate == true)
                {
                    logMess.testoDaLoggare = "il dizionario contiene già la chiave:<" + key.ToString() + ">";
                    Log.main.Add(logMess);
                    return(false);
                }

                if (Dictionary_TryGet(dizionario, key, ref currentValue, out _) == false)
                {
                    logMess.testoDaLoggare = "il dizionario contiene la chiave:<" + key.ToString() + ">, ma non riesco a recuperare il valore";
                    Log.main.Add(logMess);
                    return(false);
                }

                while (dizionario.TryUpdate(key, value, currentValue) == false)
                {
                    if (oraInizio == DateTime.MinValue)
                    {
                        oraInizio = DateTime.Now;                                 //Messo dentro il while per eseguire meno istruzioni possibili fuori (che è percorso normale)
                    }
                    if (DataOra.AttesaTempo(ref oraInizio, timeOutMs) == true)
                    {
                        logMess.testoDaLoggare = "TryUpdate raggiunto timeOutMs:<" + timeOutMs + ">, per la chiave:<" + key.ToString() + ">";
                        Log.main.Add(logMess);
                        return(false);
                    }
                }
            }
            else
            {
                while (dizionario.TryAdd(key, value) == false)
                {
                    if (oraInizio == DateTime.MinValue)
                    {
                        oraInizio = DateTime.Now;                                 //Messo dentro il while per eseguire meno istruzioni possibili fuori (che è percorso normale)
                    }
                    if (DataOra.AttesaTempo(ref oraInizio, timeOutMs) == true)
                    {
                        logMess.testoDaLoggare = "TryAdd raggiunto timeOutMs:<" + timeOutMs + ">, per la chiave:<" + key.ToString() + ">";
                        Log.main.Add(logMess);
                        return(false);
                    }
                }
            }

            return(true);
        }
コード例 #11
0
ファイル: DownLoad.cs プロジェクト: NickHola/Backupper
        private void ThrDownload(UInt64 itemKey)
        {
            Thr.SbloccaThrPadre();
            DateTime  tmpAttesa;
            WebClient client = new WebClient();

            //client = new WebClient(); //TODO decommentare //, flusso As New IO.MemoryStream
            DownloadItem elemDownload = null;

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

                client.DownloadDataCompleted   += DownloadTerminato;
                client.DownloadProgressChanged += PercentualeDownload;

                client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"); //Aggiungo lo user agent nell'header nel caso la richiesta contiene una query.
                elemDownload.OperationStartDate = DateTime.Now;
                elemDownload.DownloadState      = DwlItemState.DwlAvviato;

                client.DownloadDataAsync(new Uri(elemDownload.url), elemDownload);
                //client.DownloadData() //Non scatena gli eventi DownloadProgressChanged e DownloadDataCompleted

                //AttesaBoolean(client.IsBusy, -1) //Per le proprità(come IsBusy) se cambia di valore sembra che non lo sente quindi non posso utilizzare AttesaBoolean
                while (client.IsBusy)
                {
                    Thread.Sleep(1);
                }

                tmpAttesa = DateTime.Now;

                while (elemDownload.DownloadState == DwlItemState.DwlAvviato)
                {
                    if (DataOra.AttesaTempo(ref tmpAttesa, 1000) == true)
                    {
                        Log.main.Add(new Mess(LogType.ERR, Log.main.errUserText, "Da quando client non è Busy, lo statoDownload non si è aggiornato in tempo utile, elemDownload.url:<" + elemDownload.url + ">", visualMsgBox: false));
                        elemDownload.DownloadState = DwlItemState.Eccezione;
                        break;
                    }
                }

                //client.Dispose();
            }
            catch (ThreadAbortException ex)  //Thread interrupted by abort, do nothing
            { var tmp = ex; }
            catch (Exception ex)
            {
                Log.main.Add(new Mess(elemDownload.tipoLogEccezione, "", "Eccezione per l'url:<" + elemDownload.url + ">, ex.mess:<" + ex.Message + ">"));
                elemDownload.DescErr       = ex.Message;
                elemDownload.DownloadState = DwlItemState.Eccezione;
            }
            finally
            {
                //client.CancelAsync(); //TODO verificare se è la causa dell'errore  sul sito investing

                client.CancelAsync();
                client.Dispose();
            }
        }