Example #1
0
        public BackupBaseFileSystem(BackupProfileData profile)
        {
            m_Profile  = profile;
            m_IStorage = profile.GetStorageInterface();
            m_Logger   = profile.Logger;

            m_BackupSessionHistory = new BackupSessionHistory(profile.GetStorageInterface());
        }
        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;
        }
Example #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);
                            }
                        }
                    }
                }
            }
        }
Example #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
                {
                }
            };
        }
        protected override void AddFilesToFolderMenuItem(FolderMenuItem item, string itemPath, BackupSessionHistory history)
        {
            //            AddFilesToFolderMenuItemBaseXXX(item, itemPath, 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 override void AddFilesToFolderMenuItem(FolderMenuItem item, string itemPath, BackupSessionHistory history)
        {
            var profile = ProjectData.CurrentBackupProfile;

            if ((profile.BackupType != BackupTypeEnum.Differential) || (RestoreActionType == RestoreActionTypeEnum.LatestVersion))
            {
                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));
                    }
                }
            }
            else
            {
                ////History Items
                if (history != null)
                {
                    foreach (var historyItem in history.HistoryData?.HistoryItemList)
                    {
                        //var filePath = m_IStorage.Combine(item.Path, file);

                        if ((m_IStorage.GetDirectoryName(historyItem.TargetPath) == itemPath) ||
                            (historyItem.HistoryType == HistoryTypeEnum.Deleted && (m_IStorage.GetDirectoryName(historyItem.SourcePath) == itemPath)))
                        {
                            var fileName = m_IStorage.GetFileName(historyItem.TargetPath);
                            {
                                bool bSelected = false;
                                var  rp        = m_IStorage.Combine(item.RelativePath, fileName);

                                var             foundItem   = item.ChildFolderMenuItems.Where(i => i.Name == fileName).FirstOrDefault();
                                var             timeDate    = history?.HistoryData?.TimeStamp;
                                HistoryTypeEnum historyType = historyItem.HistoryType;

                                if (foundItem == null)
                                {
                                    var newItem = CreateMenuItem(historyItem.HistoryItemType == HistoryItemTypeEnum.Directory, bSelected, historyItem.TargetPath, rp, fileName, item, 0, historyType);
                                    Application.Current.Dispatcher.Invoke(new Action(() =>
                                    {
                                        item.ChildFolderMenuItems.Add(newItem);
                                    }));

                                    foundItem = newItem;
                                }

                                var newMenuItem = CreateMenuItem(historyItem.HistoryItemType == HistoryItemTypeEnum.Directory, bSelected, historyItem.TargetPath, rp, timeDate.ToString(), foundItem, 0, historyType);

                                Application.Current.Dispatcher.Invoke(new Action(() =>
                                {
                                    foundItem.ChildFolderMenuItems.Add(newMenuItem);
                                }));
                            }
                        }
                    }
                }

                //Latest items
                if (m_IStorage.DirectoryExists(itemPath))
                {
                    var fileList = m_IStorage.GetFiles(itemPath);
                    foreach (var file in fileList)
                    {
                        //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);

                            var             foundItem    = item.ChildFolderMenuItems.Where(i => i.Name == fileName).FirstOrDefault();
                            bool            bDeletedItem = false;
                            HistoryTypeEnum historyType  = HistoryTypeEnum.NoChange;
                            bool            bCreatedNew  = false;
                            if (foundItem == null)
                            {
                                if (history?.HistoryData?.SessionHistoryIndex > 1)
                                {
                                    bDeletedItem = true;
                                    historyType  = HistoryTypeEnum.Deleted;
                                }

                                var newItem = CreateMenuItem(m_IStorage.IsFolder(file), bSelected, file, rp, fileName, item, attr, historyType);
                                Application.Current.Dispatcher.Invoke(new Action(() =>
                                {
                                    item.ChildFolderMenuItems.Add(newItem);
                                }));

                                foundItem   = newItem;
                                bCreatedNew = true;
                            }

                            if (bCreatedNew || foundItem.ChildFolderMenuItems.Where(i => i.Path == file).FirstOrDefault() == null)
                            {
                                if (bDeletedItem)
                                {
                                    historyType = HistoryTypeEnum.Deleted;
                                }
                                else
                                {
                                    historyType = HistoryTypeEnum.Changed;
                                }

                                var timeDate    = history?.HistoryData?.TimeStamp;
                                var newMenuItem = CreateMenuItem(m_IStorage.IsFolder(file), bSelected, file, rp, timeDate.ToString(), foundItem, attr, historyType);

                                Application.Current.Dispatcher.Invoke(new Action(() =>
                                {
                                    foundItem.ChildFolderMenuItems.Add(newMenuItem);
                                }));
                            }
                        }
                    }
                }
            }
        }
        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;
            }
        }
Example #9
0
 protected abstract void AddFilesToFolderMenuItem(FolderMenuItem item, string itemPath, BackupSessionHistory history);
Example #10
0
        void AddFoldersToFolderMenuItem(FolderMenuItem item, string overridePath = null, BackupSessionHistory history = null)
        {
            var path = overridePath == null ? item.Path : overridePath;

            if (!m_IStorage.DirectoryExists(path))
            {
                return;
            }

            var subdirectoryList = m_IStorage.GetDirectoriesNames(path);

            foreach (string subdirectory in subdirectoryList)
            {
                string         newPath = m_IStorage.Combine(path, subdirectory);
                FileAttributes attr    = m_IStorage.GetFileAttributes(newPath);
                if (!IsHidden(attr) && !IsNameExistsInNameList(subdirectory, item.ChildFolderMenuItems))
                {
                    HistoryTypeEnum?historyType = GetFolderHistoryType(m_IStorage.Combine(item.RelativePath, subdirectory));
                    //if (history == null)// || history.SessionHistoryIndex == 1 || historyType == HistoryTypeEnum.Deleted)
                    {
                        bool bSelected = item.Selected == true;

                        var rp = m_IStorage.Combine(item.RelativePath, subdirectory);
                        Application.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            item.ChildFolderMenuItems.Add(CreateMenuItem(m_IStorage.IsFolder(newPath), bSelected, newPath, rp, subdirectory, item, attr, historyType));
                        }));
                    }
                }
            }
        }
Example #11
0
        //Add and update all subitems
        protected void UpdateChildItemsInMenuItem(FolderMenuItem item, string overridePath = null, BackupSessionHistory history = null)
        {
            var path = overridePath == null ? item.Path : overridePath;

            //Add all folders under item.Path
            if (item.IsFolder)// && (m_IStorage.DirectoryExists(path) || )
            {
                //Add folders
                AddFoldersToFolderMenuItem(item, overridePath, history);

                //Add files
                AddFilesToFolderMenuItem(item, path, history);
            }
        }