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); }
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); }
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(); } }
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(); } }