Esempio n. 1
0
        private BackupCompressionResult StartCompression()
        {
            BackupCompressionResult args;
            bool filesAreChanged = false;

            try
            {
                string fullPath;

                this.State = BackupStates.FilesToBackupCalculation;
                FilesSelectorM.CalculateFileList();

                if (FilesSelectorM.FilesSelected.Count == 0)
                {
                    args = new BackupCompressionResult(compressionResult: true, filesAreChanged: filesAreChanged, filesToBackup: 0);
                    this.CompressionEnd?.Invoke(this, args);
                    return(args);
                }

                do
                {
                    string prefix = DateTime.Now.ToString("yy-MM-dd_HH.mm.ss_");
                    fullPath = System.IO.Path.Combine(this.DestinationFolder, prefix + this.Name);
                } while (System.IO.File.Exists(fullPath));

                this.State = BackupStates.Compressing;

                if (Zip.Comprimi(FilesSelectorM.FilesSelected.ToList(), fullPath, out this.thrCompression, progressione: this.Progress) == true)
                {
                    args = new BackupCompressionResult(compressionResult: true, filesAreChanged: filesAreChanged, filesToBackup: FilesSelectorM.FilesSelected.Count);
                }
                else
                {
                    args = new BackupCompressionResult(compressionResult: false, filesAreChanged: filesAreChanged, filesToBackup: FilesSelectorM.FilesSelected.Count);
                }
                this.CompressionEnd?.Invoke(this, args);
                return(args);
            }
            catch
            {
                args = new BackupCompressionResult(compressionResult: false, filesAreChanged: filesAreChanged, filesToBackup: FilesSelectorM.FilesSelected.Count);
                this.CompressionEnd?.Invoke(this, args);
                return(args);
            }
            finally
            {
                this.State = BackupStates.Idle;
                this.Progress.Percentage = 0;
            }
        }
Esempio n. 2
0
        private BackupCompressionResult StartCompression()
        {
            BackupCompressionResult args;
            bool filesAreChanged = false;
            bool compressResult;
            Dictionary <string, byte[]> newMD5Files = new Dictionary <string, byte[]>();

            try
            {
                string fullPath;

                this.State = BackupStates.FilesToBackupCalculation;
                FilesSelectorM.CalculateFileList();

                if (checkMD5Files == true)
                {
                    this.State = BackupStates.MD5Calculation;
                    CalcMD5Files(out filesAreChanged, out newMD5Files);
                    if (filesAreChanged == false)
                    {
                        //outParam["filesAreChanged"] = filesAreChanged;
                        args = new BackupCompressionResult(compressionResult: true, filesAreChanged: filesAreChanged);
                        this.CompressionEnd?.Invoke(this, args);
                        return(args);
                    }
                }

                if (FilesSelectorM.FilesSelected.Count == 0)
                {
                    args = new BackupCompressionResult(compressionResult: true, filesAreChanged: filesAreChanged, filesToBackup: 0);
                    this.CompressionEnd?.Invoke(this, args);
                    return(args);
                }

                do
                {
                    string prefix = DateTime.Now.ToString("yy-MM-dd_HH.mm.ss_");
                    fullPath = System.IO.Path.Combine(this.DestinationFolder, prefix + this.Name);
                } while (System.IO.File.Exists(fullPath));

                this.State = BackupStates.Compressing;

                compressResult = Zip.Comprimi(FilesSelectorM.FilesSelected.ToList(), fullPath, out this.thrCompression, progressione: this.Progress);

                args = new BackupCompressionResult(compressionResult: compressResult, filesAreChanged: filesAreChanged, filesToBackup: FilesSelectorM.FilesSelected.Count);

                if (compressResult == true && checkMD5Files == true && filesAreChanged == true)
                {
                    this.MD5Files = newMD5Files;
                }

                this.CompressionEnd?.Invoke(this, args);
                return(args);
            }
            catch
            {
                args = new BackupCompressionResult(compressionResult: false, filesAreChanged: filesAreChanged, filesToBackup: FilesSelectorM.FilesSelected.Count);
                this.CompressionEnd?.Invoke(this, args);
                return(args);
            }
            finally
            {
                this.State = BackupStates.Idle;
                this.Progress.Percentage = 0;
            }
        }