Esempio n. 1
0
        public static List <string> GetBackupSetList_(BackupProfileData profile)
        {
            var backupProfileList = new List <string>();

            try
            {
                var setEntries = profile?.GetStorageInterface().GetDirectories(profile.GetTargetBackupFolder())?.OrderBy(set => set);
                if (setEntries != null)
                {
                    if (profile.FileSystemWatcherEnabled)
                    {
                        foreach (var entry in setEntries)
                        {
                            backupProfileList.Add(profile.GetStorageInterface().GetFileName(entry));
                        }
                    }
                    else
                    {
                        var entry = setEntries.LastOrDefault();
                        if (entry != null)
                        {
                            backupProfileList.Add(profile.GetStorageInterface().GetFileName(entry));
                        }
                    }
                }
            }
            catch (DirectoryNotFoundException) { }

            return(backupProfileList);
        }
Esempio n. 2
0
        public BackupBase(BackupProfileData profile, GenericStatusBarView progressBar) : base(profile)
        {
            m_TimeStamp = DateTime.Now;
            m_Profile   = profile;
            m_IStorage  = profile.GetStorageInterface();
            m_Logger    = profile.Logger;

            m_SourceBackupPathList = profile.BackupFolderList.ToList();//.Where(i => i.IsAvailable).ToList();
            m_TargetBackupPath     = profile.GetTargetBackupFolder();

            m_ProgressBar = progressBar;
        }
Esempio n. 3
0
        public static List <string> GetBackupSetPathWithTimeList_(BackupProfileData profile)
        {
            var backupProfileList = new List <string>();
            var storage           = profile.GetStorageInterface();

            string[] setEntries = storage.GetDirectories(profile.GetTargetBackupFolder());
            foreach (var entry in setEntries.Where(s => storage.GetFileName(s).StartsWith(profile.BackupSignature)))
            {
                backupProfileList.Add(profile.GetStorageInterface().Combine(storage.GetFileName(entry), BackupProfileData.TargetBackupBaseDirectoryName));
            }

            return(backupProfileList.OrderByDescending(set => set).ToList());
        }
Esempio n. 4
0
        public void StartBackup(BackupProfileData profile, bool bFullBackupScan)
        {
            if (profile.IsBackupSleep)
            {
                profile.Logger.Writeln($"***Back up in sleep mode until {profile.WateUpFromSleepTime}, skipping this backup task [Full backup = {bFullBackupScan}]");

                return;
            }

            if (!profile.IsValidFolderName(profile.GetTargetBackupFolder()))
            {
                Debug.Assert(profile.IsValidFolderName(profile.GetTargetBackupFolder()), "Assert - Target backup destination is not valid");

                return;
            }

            lock (this)
            {
                m_BackupWorkerTaskQueue.Add(new BackupProcessWorkerTask(profile, bFullBackupScan));
            }

            StartNextBackupTask(profile);
        }
Esempio n. 5
0
        public ProfileDataRefreshWorkerTask(BackupProfileData profile)
        {
            //m_Profile = profile;

            WorkerReportsProgress      = true;
            WorkerSupportsCancellation = true;

            DoWork += (sender, e) =>
            {
                var storage = profile.GetStorageInterface();
                try
                {
                    profile.UpdateAlerts();

                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        //profile.BackupTargetDiskSize = "n/a";
                        //profile.BackupTargetUsedSize = "n/a";
                        //profile.BackupTargetFreeSize = "n/a";

                        profile.BackupSourceFilesNumber = 0;
                        profile.BackupSourceFoldersSize = 0;

                        profile.RestoreSourceFilesNumber = 0;
                        profile.RestoreSourceFoldersSize = 0;

                        profile.BackupTargetDiskSizeNumber = 0;
                        profile.BackupTargetUsedSizeNumber = 0;
                        profile.BackupTargetFreeSizeNumber = 0;
                    }));


                    //Backup Items
                    foreach (var item in profile.BackupFolderList.Where(i => i.IsAvailable))
                    {
                        if (item.IsFolder)
                        {
                            item.NumberOfFiles = storage.GetNumberOfFiles(item.Path);
                            item.TotalSize     = storage.GetSizeOfFiles(item.Path);
                            Application.Current.Dispatcher.Invoke(new Action(() =>
                            {
                                profile.BackupSourceFilesNumber += item.NumberOfFiles;
                                profile.BackupSourceFoldersSize += item.TotalSize;
                            }));
                        }
                        else
                        {
                            Application.Current.Dispatcher.Invoke(new Action(() =>
                            {
                                profile.BackupSourceFilesNumber++;
                            }));
                        }
                    }

                    //Restore Items
                    foreach (var item in profile.RestoreFolderList)
                    {
                        if (item.IsFolder)
                        {
                            item.NumberOfFiles = storage.GetNumberOfFiles(item.Path);
                            item.TotalSize     = storage.GetSizeOfFiles(item.Path);
                            Application.Current.Dispatcher.Invoke(new Action(() =>
                            {
                                profile.RestoreSourceFilesNumber += item.NumberOfFiles;
                                profile.RestoreSourceFoldersSize += item.TotalSize;
                            }));
                        }
                        else
                        {
                            Application.Current.Dispatcher.Invoke(new Action(() =>
                            {
                                profile.RestoreSourceFilesNumber++;
                            }));
                        }
                    }


                    //Target Backup Folder
                    if (profile.IsValidFolderName(profile.GetTargetBackupFolder()))
                    {
                        //Get last backup time
                        DateTime?lastTime = null;
                        var      lastSet  = BackupBase.GetLastBackupSetName_(profile);
                        if (lastSet != null)
                        {
                            var sessionHistory = BackupSessionHistory.LoadHistory(profile.GetTargetBackupFolder(), lastSet);
                            lastTime = sessionHistory?.HistoryData?.TimeStamp;
                            Application.Current.Dispatcher.Invoke(new Action(() =>
                            {
                                profile.LastBackupDateTime = lastTime;
                            }));
                        }
                    }

                    if (profile.IsValidFolderName(profile.GetTargetBackupFolder()))
                    {
                        //Target backup storage, total disk size
                        string rootDrive = System.IO.Path.GetPathRoot(profile.GetTargetBackupFolder());
                        foreach (System.IO.DriveInfo drive in System.IO.DriveInfo.GetDrives().Where(d => d.ToString().Contains(rootDrive)))
                        {
                            if (drive.IsReady)
                            {
                                Application.Current.Dispatcher.Invoke(new Action(() =>
                                {
                                    profile.BackupTargetDiskSizeNumber = drive.TotalSize;
                                    profile.BackupTargetFreeSizeNumber = drive.AvailableFreeSpace;

                                    //profile.BackupTargetDiskSize = FileFolderSizeHelper.GetNumberSizeString(profile.BackupTargetDiskSizeNumber);
                                }));

                                break;
                            }
                        }

                        //Target backup folder used Space
                        var totaltargetUseSize = storage.GetSizeOfFiles(profile.GetTargetBackupFolder());
                        Application.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            profile.BackupTargetUsedSizeNumber = totaltargetUseSize;
                            //profile.BackupTargetUsedSize = FileFolderSizeHelper.GetNumberSizeString(profile.BackupTargetUsedSizeNumber);
                        }));

                        //Target backup storage free space
                        //Application.Current.Dispatcher.Invoke(new Action(() =>
                        //{
                        //    profile.BackupTargetFreeSizeNumber = profile.BackupTargetDiskSizeNumber - profile.BackupTargetUsedSizeNumber;
                        //}));
                        //rootDrive = Path.GetPathRoot(profile.TargetBackupFolder);
                        //foreach (DriveInfo drive in DriveInfo.GetDrives().Where(d => d.ToString().Contains(rootDrive)))
                        //{
                        //    if (drive.IsReady)
                        //    {
                        //        profile.BackupTargetFreeSizeNumber = drive.AvailableFreeSpace;
                        //        //m_BackupTargetFreeSizeNumber = drive.TotalFreeSpace;
                        //        Application.Current.Dispatcher.Invoke(new Action(() =>
                        //        {
                        //            profile.BackupTargetFreeSize = FileFolderSizeHelper.GetNumberSizeString(profile.BackupTargetFreeSizeNumber);
                        //        }));

                        //        break;
                        //    }
                        //}
                    }

                    ////Source Foldes Size
                    //m_BackupSourceFoldersSizeNumber = 0;
                    //foreach (var item in FolderList)
                    //{
                    //    m_BackupSourceFoldersSizeNumber += new DirectoryInfo(item.Path).GetFiles("*.*", SearchOption.AllDirectories).Sum(file => file.Length);
                    //    Application.Current.Dispatcher.Invoke(new Action(() =>
                    //    {
                    //        BackupSourceFoldersSize = FileFolderSizeHelper.GetNumberSizeString(m_BackupSourceFoldersSizeNumber);
                    //    }));
                    //}

                    if (m_ProfileDataUpdateEventCallback != null)
                    {
                        m_ProfileDataUpdateEventCallback(profile);
                    }

                    //update data to persistent storage
                    DataRepository.BackupProjectRepository.Instance.SaveProject();
                }
                catch (TaskCanceledException ex)
                {
                    Trace.WriteLine($"Profile Data Update exception: {ex.Message}");
                    e.Result = $"Profile Data Update exception: {ex.Message}";
                    throw (ex);
                }
                finally
                {
                }
            };
        }