public void AddAlert(BackupProfileData profile, BackupPerfectAlertTypeEnum alert, string text = null) { var alertData = BackupPerfectAlertValueDictionary[alert](); alertData.AlertTime = DateTime.Now; if (text != null) { alertData.Name += text; } Application.Current.Dispatcher.Invoke(new Action(() => { if (alert.ToString().StartsWith("Restore")) { var foundAlert = profile.RestoreAlertList.FirstOrDefault(e => e.AlertType == alert); if (foundAlert == null) { profile.RestoreAlertList.Add(alertData); } } else { var foundAlert = profile.BackupAlertList.FirstOrDefault(e => e.AlertType == alert); if (foundAlert == null) { profile.BackupAlertList.Add(alertData); } } })); }
//protected void AddFilesToFolderMenuItemBaseXXX(FolderMenuItem item, string itemPath, BackupSessionHistory history) //{ // var fileList = m_IStorage.GetFiles(itemPath); // foreach (var file in fileList.Where(f => !IsPathExistsInPathList(f, item.ChildFolderMenuItems))) // { // //var filePath = m_IStorage.Combine(item.Path, file); // var fileName = m_IStorage.GetFileName(file); // FileAttributes attr = File.GetAttributes(file); // if (!IsHidden(attr)) // { // bool bSelected = false; // var rp = m_IStorage.Combine(item.RelativePath, fileName); // item.ChildFolderMenuItems.Add(CreateMenuItem(m_IStorage.IsFolder(file), bSelected, file, rp, fileName, item, attr)); // } // } //} //---------- protected void UpdateSelectedFolders(BackupProfileData profile, FolderMenuItem item) { SelectItemDown(item); SelectItemUp(item); UpdateSelectedFolderList(profile); }
void StartNextBackupTask(BackupProfileData profile) { BackupProcessWorkerTask task = null; lock (this) { int iBusyTasks = m_BackupWorkerTaskQueue.Where(t => (t.IsBusy == true)).Count(); if (iBusyTasks < MaxConcurrentTasks) { if (IsBackupWorkerBusy(profile) == true) { //Allow only one task to run for each profile at the same time task = m_BackupWorkerTaskQueue.Where(t => (t.IsBusy == false) && t.GetProfile() != profile).FirstOrDefault(); } else { task = m_BackupWorkerTaskQueue.Where(t => t.IsBusy == false).FirstOrDefault(); } } task?.RunWorkerAsync(); profile.IsBackupWorkerPending = true; //just sent onproperty change } if (task != null) { BackupProjectRepository.Instance.SelectedBackupProject.Logger.Writeln($"--> Starting new backup {task.GetProfile().Name}"); } }
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); }
public BackupBaseFileSystem(BackupProfileData profile) { m_Profile = profile; m_IStorage = profile.GetStorageInterface(); m_Logger = profile.Logger; m_BackupSessionHistory = new BackupSessionHistory(profile.GetStorageInterface()); }
public bool?IsBackupWorkerBusy(BackupProfileData profile) { bool?bBusy = null; bBusy = GetRunningBackupWorkerTask(profile) != null; return(bBusy); }
public bool?IsBackupWorkerPending(BackupProfileData profile) { bool?bPending = null; bPending = GetPendingBackupWorkerTask(profile) != null; return(bPending); }
public static FileSystemWatcherWorkerTask StartNewInstance(BackupProfileData profile, long wakeupIntervalSec) { var task = new FileSystemWatcherWorkerTask(profile, wakeupIntervalSec); task.RunWorkerAsync(); return(task); }
public void PauseBackup(BackupProfileData profile) { var task = GetRunningBackupWorkerTask(profile); if (task != null && task.IsPaused == false) { task.IsPaused = true; } }
public bool?IsBackupWorkerPaused(BackupProfileData profile) { bool?bPaused = null; var task = GetPausedBackupWorkerTask(profile); bPaused = (task != null); return(bPaused); }
BackupProcessWorkerTask GetPendingBackupWorkerTask(BackupProfileData profile) { BackupProcessWorkerTask task = null; // lock (this) { task = m_BackupWorkerTaskQueue.FirstOrDefault(w => (w.GetProfile() == profile) && !w.IsBusy); } return(task); }
BackupProcessWorkerTask GetPausedBackupWorkerTask(BackupProfileData profile) { BackupProcessWorkerTask task = null; // lock (this) { task = m_BackupWorkerTaskQueue.FirstOrDefault(w => (w.GetProfile() == profile) && w.IsBusy && (w.IsPaused == true)); } return(task); }
public static string GetLastBackupSetPath_(BackupProfileData profile) { var name = GetLastBackupSetName_(profile); if (name != null) { name = profile.GetStorageInterface().Combine(name, BackupProfileData.TargetBackupBaseDirectoryName); } return(name); }
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; }
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()); }
void SaveRestoreFolder(BackupProfileData profile, string path) { //TODO - only one destination folder is supported right now profile.TargetRestoreFolderList.Clear(); var folderData = new FolderData() { IsFolder = true, IsAvailable = true, Path = path }; profile.TargetRestoreFolderList.Add(folderData); BackupProjectRepository.Instance.SaveProject(); }
public void CancelPendingBackupTask(BackupProfileData profile) { lock (this) { var task = m_BackupWorkerTaskQueue.FirstOrDefault(w => w.GetProfile() == profile); //Since this is an uncommon opertation and the queue is very small we will rebuild the queue if (task != null) { m_BackupWorkerTaskQueue.Remove(task); profile.IsBackupWorkerPending = true; } } }
public static string GetLastBackupSetName_(BackupProfileData profile) { string lastSet = null; try { var setList = GetBackupSetList_(profile); lastSet = setList.LastOrDefault(); } catch (DirectoryNotFoundException) { } return(lastSet); }
public void UpdateSelectedFolderList(BackupProfileData profile = null) { if (profile == null) { profile = ProjectData.CurrentBackupProfile; } //Update source folder selection list ClearSelectedFolderList(); UpdateSelectedFolderListStep(profile, FolderMenuItemTree); //update folder properties/size in UI window //profile.UpdateProfileProperties(); }
FileSystemWatcherWorkerTask(BackupProfileData profile, long wakeupIntervalSec) { m_Profile = profile; m_Logger = profile.Logger; WorkerReportsProgress = true; WorkerSupportsCancellation = true; DoWork += (sender, e) => { //var watchList = profile.BackupWatcherItemList; try { //watchList.Clear(); foreach (var backupItem in profile.BackupFolderList) { m_Logger.Writeln($"Starting File System Watcher: {backupItem.Path}"); try { new FileSystemWatcerItemManager(m_Profile).RunWatcher(backupItem.Path); } catch (FileNotFoundException) { m_Logger.Writeln($"***Warning: Backup item not available: {backupItem.Path}"); } } } catch (TaskCanceledException ex) { m_Logger.Writeln($"File System Watcher exception: {ex.Message}"); Trace.WriteLine($"File System Watcher exception: {ex.Message}"); e.Result = $"Full Backup exception: {ex.Message}"; throw (ex); } finally { } }; m_FileSystemWatcherBackupTimer = new FileSystemProfileBackupWatcherTimer() { Profile = profile, Interval = wakeupIntervalSec, AutoReset = true, Enabled = profile.IsWatchFileSystem, }; m_FileSystemWatcherBackupTimer.Elapsed += BackupTaskManager.OnFileSystemWatcherBackupTimerStartBackup; }
void UpdateSelectedFolderListStep(BackupProfileData profile, ObservableCollection <FolderMenuItem> folderList) { foreach (var item in folderList.Where(i => (i.IsSelectable))) { if (item.Selected == true) { SelectedItemList.Add(new FolderData { Path = item.Path, RelativePath = item.RelativePath, Name = item.Name, IsFolder = item.IsFolder }); } else if (item.Selected == null) { UpdateSelectedFolderListStep(profile, item.ChildFolderMenuItems); } } }
public void StopBackupTask(BackupProfileData profile) { lock (this) { var task = GetRunningBackupWorkerTask(profile); if (task != null) { if (task.IsPaused == true) { task.IsPaused = false; } task.CancelAsync(); } } }
public void RemoveAlert(BackupProfileData profile, BackupPerfectAlertTypeEnum alert) { // var foundAlert = profile.BackupAlertList.FirstOrDefault(e => e.IsDeletable && e.AlertType == alert); var foundAlert = profile.BackupAlertList.FirstOrDefault(e => e.AlertType == alert); if (foundAlert != null) { Application.Current.Dispatcher.Invoke(new Action(() => { profile.BackupAlertList.Remove(foundAlert); })); } foundAlert = profile.RestoreAlertList.FirstOrDefault(e => e.IsDeletable && e.AlertType == alert); if (foundAlert != null) { Application.Current.Dispatcher.Invoke(new Action(() => { profile.RestoreAlertList.Remove(foundAlert); })); } }
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); }
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); } } } }
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 { } }; }
public IncrementalFullBackup(BackupProfileData profile, GenericStatusBarView progressBar = null) : base(profile, progressBar) { }
public BackupAlertManager(BackupProfileData profile) { m_Profile = profile; m_Logger = profile.Logger; }
public FileSystemWatcerItemManager(BackupProfileData profile) { m_Profile = profile; m_Logger = profile.Logger; }
public void SleepBackup(BackupProfileData profile, int hours) { }