示例#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);
        }
示例#2
0
        public BackupBaseFileSystem(BackupProfileData profile)
        {
            m_Profile  = profile;
            m_IStorage = profile.GetStorageInterface();
            m_Logger   = profile.Logger;

            m_BackupSessionHistory = new BackupSessionHistory(profile.GetStorageInterface());
        }
示例#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());
        }
示例#4
0
        public void RunWatcher(string path)
        {
            m_Path = path;

            var watcher = new FileSystemWatcher();

            if (m_Profile.GetStorageInterface().IsFolder(m_Path))
            {
                watcher.IncludeSubdirectories = true;
                watcher.Path         = m_Path;
                watcher.NotifyFilter =
                    NotifyFilters.LastAccess |
                    NotifyFilters.LastWrite |
                    NotifyFilters.FileName |
                    NotifyFilters.DirectoryName |
                    NotifyFilters.CreationTime;

                watcher.Filter = "*.*";

                // Add event handlers.
                watcher.Changed += new FileSystemEventHandler(OnChanged);
                watcher.Created += new FileSystemEventHandler(OnCreated);
                watcher.Deleted += new FileSystemEventHandler(OnDeleted);
                watcher.Renamed += new RenamedEventHandler(OnRenamed);
            }
            else
            {
                watcher.Path         = m_Profile.GetStorageInterface().GetDirectoryName(m_Path);
                watcher.NotifyFilter =
                    NotifyFilters.LastAccess |
                    NotifyFilters.LastWrite |
                    NotifyFilters.FileName;

                watcher.Filter = $"{m_Profile.GetStorageInterface().GetFileName(m_Path)}";

                // Add event handlers.
                watcher.Changed += new FileSystemEventHandler(OnChanged);
                watcher.Deleted += new FileSystemEventHandler(OnDeleted);
                watcher.Renamed += new RenamedEventHandler(OnRenamed);
            }

            watcher.InternalBufferSize = 6400000;

            // Begin watching.
            watcher.EnableRaisingEvents = true;
        }
示例#5
0
        public static string GetLastBackupSetPath_(BackupProfileData profile)
        {
            var name = GetLastBackupSetName_(profile);

            if (name != null)
            {
                name = profile.GetStorageInterface().Combine(name, BackupProfileData.TargetBackupBaseDirectoryName);
            }

            return(name);
        }
示例#6
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;
        }
示例#7
0
        public static void UpdateAlerts(this BackupProfileData profile)
        {
            var storage = profile.GetStorageInterface();

            if (profile.BackupFolderList.Count() == 0)
            {
                BackupAlertManager.Instance.AddAlert(profile, BackupPerfectAlertTypeEnum.BackupItemListEmpty);
            }
            else
            {
                foreach (var item in profile.BackupFolderList)
                {
                    if (item.IsFolder)
                    {
                        if (storage.DirectoryExists(item.Path))
                        {
                            item.IsAvailable = true;
                        }
                        else
                        {
                            item.IsAvailable = false;
                            BackupAlertManager.Instance.AddAlert(profile, BackupPerfectAlertTypeEnum.BackupItemListFolderNotAvailable, $": {item.Path}");
                        }
                    }
                    else
                    {
                        if (storage.FileExists(item.Path))
                        {
                            item.IsAvailable = true;
                        }
                        else
                        {
                            item.IsAvailable = false;
                            BackupAlertManager.Instance.AddAlert(profile, BackupPerfectAlertTypeEnum.BackupItemListFileNotAvailable, $": {item.Path}");
                        }
                    }
                }
            }


            foreach (var item in profile.TargetBackupFolderList)
            {
                if (profile.IsValidFolderName(item.Path))
                {
                    if (!storage.DirectoryExists(item.Path))
                    {
                        item.IsAvailable = false;
                        BackupAlertManager.Instance.AddAlert(profile, BackupPerfectAlertTypeEnum.BackupDestinationFolderNotAvailable, $": {item.Path}");
                    }
                    else
                    {
                        item.IsAvailable = true;
                    }
                }
                else
                {
                    item.IsAvailable = false;
                    BackupAlertManager.Instance.AddAlert(profile, BackupPerfectAlertTypeEnum.BackupDestinationFolderNotConfigured);
                }
            }

            //Restore
            if (profile.LastBackupDateTime == null)
            {
                BackupAlertManager.Instance.AddAlert(profile, BackupPerfectAlertTypeEnum.Restore_BackupDestinationNotFound);
            }

            List <string> setList = BackupBase.GetBackupSetList_(profile);

            if (setList.Count == 0)
            {
                BackupAlertManager.Instance.AddAlert(profile, BackupPerfectAlertTypeEnum.RestoreSessionListIsEmpty);
            }

            if (profile.RestoreFolderList.Count == 0)
            {
                //BackupAlertManager.Instance.AddAlert(profile, BackupPerfectAlertTypeEnum.RestoreItemListEmpty);
            }
            else
            {
                foreach (var item in profile.RestoreFolderList)
                {
                    if (profile.IsValidFolderName(item.Path))
                    {
                        if (!storage.DirectoryExists(item.Path))
                        {
                            item.IsAvailable = false;
                            BackupAlertManager.Instance.AddAlert(profile, BackupPerfectAlertTypeEnum.RestoreDestinationFolderNotAvailable, $": {profile.GetTargetRestoreFolder()}");
                        }
                        else
                        {
                            item.IsAvailable = true;
                        }
                    }
                    else
                    {
                        item.IsAvailable = false;
                        BackupAlertManager.Instance.AddAlert(profile, BackupPerfectAlertTypeEnum.RestoreDestinationFolderNotConfigured);
                    }
                }
            }
        }
示例#8
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
                {
                }
            };
        }