Example #1
0
 public BackupBaseM(string name = null)
 {
     this.IsEnabled         = true;
     this.Name              = name ?? BackupsM.Instance.GetAvailableBackupName();
     this.progress          = new Progressione();
     this.DestinationFolder = @"C:\";
 }
Example #2
0
        public static bool Comprimi(object oggDaCompr, string percNomeFileCompr, TipiArchivio formatoArchivio = TipiArchivio.sevenZip, CompressionLevels livelloCompr = CompressionLevels.Ultra,
                                    string password = null, int timeOutMs = -1, Progressione progressione = null, Mess logMess = null)
        {
            Thread thrZip = null;

            return(Comprimi(oggDaCompr, percNomeFileCompr, out thrZip, formatoArchivio: formatoArchivio, livelloCompr: livelloCompr, password: password, timeOutMs: timeOutMs, progressione: progressione
                            , logMess: logMess));
        }
Example #3
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);
            }
        }
Example #4
0
 /// <param name="idSubsetOperaz">Serve per far scatenare l'evento SubsetOperationEnded, quando tutti gli elementi di download con un certo id sono terminati</param>
 /// <param name="timeoutSec">Se omesso o 0 si prende il valore defaultTimeoutSec dell'oggetto di tipo ConfigDownload, non può essere infinito</param>
 public ItemBase(string url, byte priority = 128, string idSubsetOperaz = "", int timeoutSec = 0, Progressione progressione = null, LogType tipoLogTimeout = LogType.Warn, LogType tipoLogEccezione = LogType.ERR)
 {
     this.url              = url;
     this.Priority         = priority;
     this.idSubsetInList   = idSubsetOperaz;
     this.TimeoutSec       = timeoutSec;
     this.progressione     = progressione == null ? new Progressione() : progressione;
     this.tipoLogTimeout   = tipoLogTimeout;
     this.tipoLogEccezione = tipoLogEccezione;
     idItemInList          = 0;
 }
Example #5
0
        private static bool ThrDeComprimi(string percNomeFileZip, string percorsoEstrazione, string passsword, Progressione progressione = null)
        {
            Thr.SbloccaThrPadre();

            SevenZipExtractor zipExtractor;

            try
            {
                if (passsword == null)
                {
                    zipExtractor = new SevenZipExtractor(percNomeFileZip);
                }
                else
                {
                    zipExtractor = new SevenZipExtractor(percNomeFileZip, passsword);
                }


                if (progressione != null)
                {
                    progressioniAttuali.Add(zipExtractor.UniqueID, progressione);
                }

                zipExtractor.Extracting         += PercentualeEstratta;
                zipExtractor.ExtractionFinished += EstrazioneTerminata;

                zipExtractor.ExtractArchive(percorsoEstrazione);

                return(true);
            } catch (Exception ex) {
                if (progressione != null)
                {
                    progressione.ScatenaEventoTerminataConErrori(ex.Message);
                }
                //If progressioniAttuali.ContainsKey(zipExtractor.UniqueID) Then progressioniAttuali(zipExtractor.UniqueID).ScatenaEventoTerminataConErrori(ex.Message)
                return(false);
            }
        }
Example #6
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);
        }
Example #7
0
        public static bool DeComprimi(string percNomeFileZip, string percorsoEstrazione, string password = null, int timeOutMs = -1, Progressione progressione = null)
        {
            Thread thrZip = null;

            return(DeComprimi(percNomeFileZip, percorsoEstrazione, ref thrZip, password: password, timeOutMs: timeOutMs, progressione: progressione));
        }
Example #8
0
        private static bool ThrComprimi(Dictionary <string, string> dizionarioDaCompr, string percNomeFileCompr, TipiArchivio formatoArchivio, CompressionLevels livelloCompr, string passsword, Progressione Progressione)
        {
            Thr.SbloccaThrPadre();
            SevenZipCompressor zipCompressor;

            try {
                zipCompressor = new SevenZipCompressor();

                if (Progressione != null)
                {
                    progressioniAttuali.Add(zipCompressor.UniqueID, Progressione);
                }

                zipCompressor.CompressionMode   = CompressionMode.Create;
                zipCompressor.TempFolderPath    = Path.GetTempPath();
                zipCompressor.ArchiveFormat     = (OutArchiveFormat)(int)formatoArchivio;
                zipCompressor.CompressionMethod = CompressionMethod.Lzma; //ATTENZIONE: la libreria 16.04 con Lzma2 in alcuni casi va in errore
                if (passsword != null)
                {
                    zipCompressor.EncryptHeaders      = true;
                    zipCompressor.ZipEncryptionMethod = ZipEncryptionMethod.Aes256;
                }

                //il formato 7zip se la dll viene eseguita a 32bit non accetta un livello di compressione superiore a Normal
                if (formatoArchivio == TipiArchivio.sevenZip && livelloCompr > CompressionLevels.Normal && Environment.Is64BitProcess == false)
                {
                    livelloCompr = CompressionLevels.Normal;
                }
                zipCompressor.CompressionLevel = (SevenZip.CompressionLevel)(int) livelloCompr;

                zipCompressor.Compressing         += PercentualeCompressa;
                zipCompressor.CompressionFinished += CompressioneTerminata;

                zipCompressor.CompressFileDictionary(dizionarioDaCompr, percNomeFileCompr, passsword);

                return(true);
            } catch (Exception ex) {
                if (Progressione != null)
                {
                    Progressione.ScatenaEventoTerminataConErrori(ex.Message);
                }
                //If progressioniAttuali.ContainsKey(zipCompressor.UniqueID) Then progressioniAttuali(zipCompressor.UniqueID).ScatenaEventoTerminataConErrori(ex.Message)
                return(false);
            }
        }
Example #9
0
 /// <param name="idSubsetOperaz">Serve per far scatenare l'evento downloadListaTerminato, quando tutti gli elementi di download con un certo id sono terminati</param>
 /// <param name="timeoutSec">Se omesso o 0 si prende il valore defaultTimeoutSec dell'oggetto di tipo ConfigDownload, non può essere infinito</param>
 public DownloadItem(string url, byte priority = 128, string idSubsetOperaz             = "", int timeoutSec = 0, bool convertiInTesto = true, LogType tipoLogTimeout = LogType.Warn,
                     LogType tipoLogEccezione  = LogType.ERR, Progressione progressione = null) : base(url, priority, idSubsetOperaz, timeoutSec, progressione, tipoLogTimeout, tipoLogEccezione)
 {
     this.translateDataInText = convertiInTesto;
 }
Example #10
0
        /// <param name="timeoutSec">Se omesso o 0 si prende il valore defaultTimeoutSec dell'oggetto di tipo ConfigDownload, non può essere infinito</param>
        public UploadItem(string urlFolder, object oggettoUpload, byte priority = 128, string nomeFile = "", string suffFileCorrotto = "", string idSubsetOperaz = "", UploadType tipoUpload = UploadType.Ftp, string utente = "", string password = "",
                          int timeoutSec = 0, LogType tipoLogTimeout = LogType.Warn, LogType tipoLogEccezione = LogType.ERR, Progressione progressione           = null) : base(urlFolder, priority, idSubsetOperaz, timeoutSec, progressione, tipoLogTimeout, tipoLogEccezione)
        {
            if (oggettoUpload.GetType() == typeof(byte))
            {
                Data = (byte[])oggettoUpload;
            }
            else if (oggettoUpload.GetType() == typeof(String))
            {
                if (File.Exists((string)oggettoUpload) == false)
                {
                    throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "ricevuto oggettoUpload di tipo con tipo String ma il file non esiste, oggettoUpload:<" + oggettoUpload + ">")));
                }
                Data = File.ReadAllBytes((string)oggettoUpload);
            }
            else
            {
                throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "ricevuto oggettoUpload di tipo disatteso, oggettoUpload.GetType:<" + oggettoUpload.GetType().ToString() + ">")));
            }

            if (nomeFile != "")
            {
                this.FileName = nomeFile;
            }
            else
            {
                if (oggettoUpload.GetType() == typeof(string))
                {
                    this.FileName = Path.GetFileName((string)oggettoUpload);
                }
                else
                {
                    throw new Exception(Excep.ScriviLogInEx(new Mess(LogType.ERR, Log.main.errUserText, "ricevuto nomeFile vuoto e oggettoUpload non è una stringa, impossibile ricavare nome file, oggettoUpload.GetType:<" + oggettoUpload.GetType().ToString() + ">")));
                }
            }

            this.CorruptFileNameSuffix = suffFileCorrotto;
            this.User       = utente;
            this.Password   = password;
            this.UploadType = tipoUpload;
        }