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 #2
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 #4
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;
            }
        }