예제 #1
0
        public RestorePoint Create(string backupPath, List <FileInformation> files, List <RestorePoint> restorePoints,
                                   IDateTimeProvider dateTimeProvider, IStorageAlgorithm storageAlgorithm, RestoreType restoreType)
        {
            if (restoreType == RestoreType.Increment)
            {
                RestorePoint        lastFullRestorePoint = restorePoints.Last(x => x.RestoreType == RestoreType.Full);
                List <RestorePoint> lastRestorePoints    = restorePoints.AsEnumerable().Reverse()
                                                           .TakeWhile(x => x.RestoreType == RestoreType.Increment).ToList();
                lastRestorePoints.Add(lastFullRestorePoint);

                List <FileInformation> incrementedFiles = new List <FileInformation>();

                foreach (var file in files)
                {
                    List <FileInformation> fileUpdates = lastRestorePoints
                                                         .Select(x => x.GetFile(file.Path))
                                                         .Where(x => x != null)
                                                         .Cast <FileInformation>()
                                                         .ToList();
                    FileInformation diff = file.GetDiff(fileUpdates);
                    if (diff.Size > 0)
                    {
                        incrementedFiles.Add(diff);
                    }
                }

                files = incrementedFiles;
            }

            RestorePoint restorePoint = storageAlgorithm.Storage(backupPath, dateTimeProvider.GetCurrentTime(),
                                                                 restoreType, files);

            return(restorePoint);
        }
예제 #2
0
        public void CreateRestorePoint(RestoreType restoreType)
        {
            List <FileInformation> files        = _watchedFilePaths.Select(x => _fileSystem.Read(x)).ToList();
            RestorePoint           restorePoint = _restorePointCreator.Create(_backupPath, files, _restorePoints,
                                                                              _dateTimeProvider, _storageAlgorithm, restoreType);

            _restorePoints.Add(restorePoint);
            WriteRestorePoint(restorePoint);
        }
예제 #3
0
        private void RemoveRestorePoint(RestorePoint restorePoint)
        {
            switch (restorePoint.StorageType)
            {
            case StorageType.Separate:
                foreach (var file in restorePoint.RestoreFiles)
                {
                    _fileSystem.Remove(file.Path);
                }
                break;

            case StorageType.Shared:
                _fileSystem.Remove(restorePoint.Path);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
예제 #4
0
        private void WriteRestorePoint(RestorePoint restorePoint)
        {
            switch (restorePoint.StorageType)
            {
            case StorageType.Separate:
                foreach (RestoreFileInformation file in restorePoint.RestoreFiles)
                {
                    _fileSystem.Write(file);
                }
                break;

            case StorageType.Shared:
                _fileSystem.Write(new ArchiveFileInformation(restorePoint.Path, restorePoint.RestoreFiles.Cast <FileInformation>().ToList()));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }