protected override void AddRootItemsToTree()
        {
            var profile = ProjectData.CurrentBackupProfile;

            ClearItemList();
            //m_BackupSetPathCacheList.Clear();

            m_LastSetPathCache = BackupBase.GetLastBackupSetPath_(profile);
            if (m_LastSetPathCache == null)
            {
                return;
            }

            //var lastSetARchivePath = m_IStorage.Combine(lastSetPath, BackupProfileData.TargetBackupBaseDirectoryName);

            var historyItem = SelectedHistoryItem;

            if (historyItem == null)
            {
                return;
            }

            var lastSetPath = m_IStorage.Combine(profile.GetTargetBackupFolder(), m_LastSetPathCache);

            string targetPath = null;

            if (historyItem.HistoryData?.HistoryItemList.Count() > 0)
            {
                string path     = historyItem.HistoryData?.HistoryItemList[0].TargetPath;
                string lastPath = path;
                while ((path != null) && (path != string.Empty) && (path != historyItem.HistoryData?.TargetPath))
                {
                    lastPath = path;
                    path     = m_IStorage.GetDirectoryName(path);
                }

                if ((path != null) && (path != string.Empty))
                {
                    targetPath = m_IStorage.Combine(lastPath, BackupProfileData.TargetBackupBaseDirectoryName);
                }
            }


            foreach (var item in profile.BackupFolderList.Where(i => i.IsAvailable))
            {
                var directoryName = m_IStorage.GetFileName(item.Path);
                var restorePath   = m_IStorage.Combine(lastSetPath, item.Name);

                var rootItem = CreateMenuItem(m_IStorage.IsFolder(restorePath), false, restorePath, directoryName, directoryName, null, 0);

                UpdateChildItemsInMenuItem(rootItem);

                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    FolderMenuItemTree.Add(rootItem);
                }));
            }
        }
        public SelectRestoreItemsByDateViewModel()
        {
            var           profile             = BackupProjectRepository.Instance.SelectedBackupProject?.CurrentBackupProfile;
            List <string> setList             = BackupBase.GetBackupSetList_(profile);
            var           firstSet            = setList.FirstOrDefault();
            var           firstSessionHistory = BackupSessionHistory.LoadHistory(profile.GetTargetBackupFolder(), firstSet);

            m_DisplayDateStart = firstSessionHistory.HistoryData.TimeStamp;

            var lastSet            = setList.LastOrDefault();
            var lastSessionHistory = BackupSessionHistory.LoadHistory(profile.GetTargetBackupFolder(), lastSet);

            m_DisplayDateEnd = lastSessionHistory.HistoryData.TimeStamp;

            m_SelectedDate = m_DisplayDateEnd;
        }
Beispiel #3
0
        public override void UpdateCurrentProfileChange()
        {
            base.UpdateCurrentProfileChange();

            var           profile = BackupProjectRepository.Instance.SelectedBackupProject.CurrentBackupProfile;
            List <string> setList = BackupBase.GetBackupSetList_(profile);

            BackupSessionHistoryList.Clear();
            foreach (var setPath in setList)
            {
                var sessionHistory = BackupSessionHistory.LoadHistory(profile.GetTargetBackupFolder(), setPath);
                if (sessionHistory != null)
                {
                    BackupSessionHistoryList.Add(sessionHistory);
                }
            }
        }
        public override void ExpandFolder(ItemCollection itemList)
        {
            if (RestoreActionType == RestoreActionTypeEnum.LatestVersion)
            {
                base.ExpandFolder(itemList);
            }
            else
            {
                var profile     = ProjectData.CurrentBackupProfile;
                var backSetList = BackupBase.GetBackupSetList_(profile);

                //xxxxx
                foreach (var item in itemList)
                {
                    int iSessionIndex = 1;
                    foreach (var setPath in backSetList)
                    {
                        var sessionHistory = BackupSessionHistory.LoadHistory(profile.GetTargetBackupFolder(), setPath);
                        if (sessionHistory != null)
                        {
                            sessionHistory.HistoryData.SessionHistoryIndex = iSessionIndex;
                            iSessionIndex++;

                            var folderItem = item as FolderMenuItem;

                            var lastSetPath  = m_IStorage.Combine(profile.GetTargetBackupFolder(), m_IStorage.Combine(setPath, BackupProfileData.TargetBackupBaseDirectoryName));
                            var lastSetPath2 = m_IStorage.Combine(lastSetPath, folderItem.RelativePath);

                            //if (folderItem.ChildFolderMenuItems.Count() == 0)
                            {
                                UpdateChildItemsInMenuItem(folderItem, lastSetPath2, sessionHistory);
                            }
                        }
                    }
                }
            }
        }
Beispiel #5
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);
                    }
                }
            }
        }
Beispiel #6
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
                {
                }
            };
        }
        protected override void AddRootItemsToTree()
        {
            var profile = ProjectData.CurrentBackupProfile;

            ClearItemList();
            //m_BackupSetPathCacheList.Clear();

            m_LastSetPathCache = BackupBase.GetLastBackupSetPath_(profile);

            if (m_LastSetPathCache == null)
            {
                return;
            }

            switch (profile.BackupType)
            {
            case BackupTypeEnum.Snapshot:
            case BackupTypeEnum.Incremental:
            {
                var lastSetPath = m_IStorage.Combine(profile.GetTargetBackupFolder(), m_LastSetPathCache);

                foreach (var item in profile.BackupFolderList.Where(i => i.IsAvailable))
                {
                    var directoryName = m_IStorage.GetFileName(item.Path);
                    var restorePath   = m_IStorage.Combine(lastSetPath, item.Name);

                    if (m_IStorage.DirectoryExists(restorePath) || m_IStorage.FileExists(restorePath))
                    {
                        var rootItem = CreateMenuItem(m_IStorage.IsFolder(restorePath), false, restorePath, directoryName, directoryName, null, 0);

                        UpdateChildItemsInMenuItem(rootItem);

                        Application.Current.Dispatcher.Invoke(new Action(() =>
                            {
                                FolderMenuItemTree.Add(rootItem);
                            }));
                    }
                    else
                    {
                        profile.Logger.Writeln($"Skipping restore item, Item not found: {restorePath}");
                    }
                }
            }

            break;

            case BackupTypeEnum.Differential:
            {
                var backSetList = BackupBase.GetBackupSetList_(profile);
                //var lastSetName = BackupBase.GetLastBackupSetPath_(profile);

                //foreach (var setPath in backSetList.Where(p => p != m_LastSetPathCache))
                //{
                //    m_BackupSetPathCacheList.Add(m_IStorage.Combine(profile.GetTargetBackupFolder(), setPath));
                //}

                m_RootFolderMenuItemTree.ParentItem   = null;
                m_RootFolderMenuItemTree.IsFolder     = true;
                m_RootFolderMenuItemTree.Path         = profile.GetTargetBackupFolder();
                m_RootFolderMenuItemTree.RelativePath = string.Empty;
                m_RootFolderMenuItemTree.Name         = "BACKUP";

                int iSessionIndex = 0;
                foreach (var setPath in backSetList)
                {
                    iSessionIndex++;
                    var sessionHistory = BackupSessionHistory.LoadHistory(profile.GetTargetBackupFolder(), setPath);
                    if (sessionHistory == null)
                    {
                        Trace.WriteLine("Error, Select Restore Differential Items, History is null");
                    }
                    else
                    {
                        sessionHistory.HistoryData.SessionHistoryIndex = iSessionIndex;

                        var lastSetPath = m_IStorage.Combine(m_IStorage.Combine(profile.GetTargetBackupFolder(), setPath), BackupProfileData.TargetBackupBaseDirectoryName);

                        m_RootFolderMenuItemTree.Path = lastSetPath;

                        //update add root items
                        UpdateChildItemsInMenuItem(m_RootFolderMenuItemTree, lastSetPath, sessionHistory);

                        foreach (var subItem in m_RootFolderMenuItemTree.ChildFolderMenuItems)
                        {
                            var newPath = m_IStorage.Combine(lastSetPath, subItem.RelativePath);
                            UpdateChildItemsInMenuItem(subItem, newPath, sessionHistory);
                        }
                    }
                }
            }
            break;

            default:
                break;
            }
        }
Beispiel #8
0
        public BackupProcessWorkerTask(BackupProfileData profile, bool bFullBackupScan)
        {
            m_Profile         = profile;
            m_Logger          = profile.Logger;
            m_bFullBackupScan = bFullBackupScan;

            WorkerReportsProgress      = true;
            WorkerSupportsCancellation = true;

            DoWork += (sender, e) =>
            {
                m_MaxActiveCPU = Properties.General.Default.MaxCPUOnBusy;
                m_MaxIdleCPU   = Properties.General.Default.MaxCPUOnAway;

                m_ProgressBar = GenericStatusBarView.NewInstance;
                profile.IsBackupWorkerBusy = true;
                //                RunWorkerCompleted += new RunWorkerCompletedEventHandler(BackupTaskRunWorkerCompletedEvent);
                ProgressChanged    += BackupTaskRunWorkerProgressChangedEvent;
                RunWorkerCompleted += BackupTaskRunWorkerCompletedEvent;

                //profile.IsBackupWorkerBusy = true;
                m_ProgressBar.UpdateProgressBar("Backup starting...", 0);
                var startTime = DateTime.Now;

                m_Logger.Writeln($"-------------------------------------------------");
                try
                {
                    switch (profile.BackupType)
                    {
                    case BackupTypeEnum.Differential:
                        if (bFullBackupScan)
                        {
                            m_Logger.Writeln($"Starting a Full Deep Differential backup");
                            m_BackupManager = new DifferentialBackup(profile, m_ProgressBar);
                        }
                        else
                        {
                            m_Logger.Writeln($"Starting a Differential watcher backup");
                            m_BackupManager = new DifferentialWatcherBackup(profile, m_ProgressBar);
                        }
                        break;

                    case BackupTypeEnum.Incremental:
                        if (bFullBackupScan)
                        {
                            m_Logger.Writeln($"Starting a Full Deep Incremental backup");
                            m_BackupManager = new IncrementalFullBackup(profile, m_ProgressBar);
                        }
                        else
                        {
                            m_Logger.Writeln($"Starting Incremental watcher backup");
                            m_BackupManager = new IncrementalFullWatcherBackup(profile, m_ProgressBar);
                        }
                        break;

                    case BackupTypeEnum.Snapshot:
                        m_Logger.Writeln($"Starting a Snapshot backup");
                        m_BackupManager = new SnapshotBackup(profile, m_ProgressBar);
                        break;

                    default:
                        throw new ArgumentNullException("Unknown backup type in BackupWorker");
                    }

                    m_BackupManager.Init();
                    m_BackupManager.ProcessBackup();
                    m_BackupManager.Done();

                    m_Profile.RefreshProfileProperties();
                }
                catch (TaskCanceledException ex)
                {
                    m_Logger.Writeln($"Backup exception: {ex.Message}");
                    m_ProgressBar.UpdateProgressBar("Completed with Errors");
                    Trace.WriteLine($"Full Backup exception: {ex.Message}");
                    e.Result = $"Full Backup exception: {ex.Message}";
                    throw (ex);
                }
                finally
                {
                    if (CancellationPending)
                    {
                        e.Cancel = true;
                    }

                    m_Logger.Writeln($"Backup completed, execution time: {DateTime.Now - startTime}");
                    m_ProgressBar.Release();
                    m_ProgressBar   = null;
                    m_BackupManager = null;
                }
            };
        }