Beispiel #1
0
 public RestorePoint(RestorePoint previousPoint, Dictionary <string, FileRestoreCopyInfo> info, DateTime creationDate)
 {
     PreviousPoint = previousPoint;
     Id            = _nextId++;
     Info          = info;
     CreationDate  = creationDate;
 }
        public long CountLeftPoints(RestorePoint lastPoint)
        {
            long numberOfLeftPoints = 0;
            var  isNumberSet        = false;

            foreach (var algorithm in Algorithms)
            {
                if (MinimumFlag)
                {
                    // minimum
                    if (algorithm.CountLeftPoints(lastPoint) < numberOfLeftPoints || !isNumberSet)
                    {
                        isNumberSet        = true;
                        numberOfLeftPoints = algorithm.CountLeftPoints(lastPoint);
                    }
                }
                else
                {
                    // maximum
                    if (algorithm.CountLeftPoints(lastPoint) > numberOfLeftPoints || !isNumberSet)
                    {
                        isNumberSet        = true;
                        numberOfLeftPoints = algorithm.CountLeftPoints(lastPoint);
                    }
                }
            }

            return(numberOfLeftPoints);
        }
Beispiel #3
0
        public RestorePoint CreateBackup(RestorePoint lastPoint, List <string> objectsForBackup, BackupStoringAlgorithm storingAlgorithm)
        {
            var list = new Dictionary <string, FileRestoreCopyInfo>();

            foreach (var filePath in objectsForBackup)
            {
                list.Add(filePath, new FileRestoreCopyInfo(filePath, new FileInfo(filePath).Length, DateTimeProvider.Now, storingAlgorithm.BackupPath));
                // storingAlgorithm.CopyFile(filePath);
            }

            return(new FullBackupPoint(lastPoint, list, DateTimeProvider.Now));
        }
Beispiel #4
0
        public long CountLeftPoints(RestorePoint lastPoint)
        {
            long k     = 0;
            var  point = lastPoint;

            while (point != null && (point.CreationDate >= Date || point is IncrementalBackupPoint))
            {
                point = point.PreviousPoint;
                k++;
            }

            return(k);
        }
Beispiel #5
0
        public RestorePoint CreateBackup(RestorePoint lastPoint, List <string> objectsForBackup, BackupStoringAlgorithm storingAlgorithm)
        {
            var lastFullBackupPoint = lastPoint;

            while (lastFullBackupPoint != null && !(lastFullBackupPoint is FullBackupPoint))
            {
                lastFullBackupPoint = lastFullBackupPoint.PreviousPoint;
            }

            if (lastFullBackupPoint == null)
            {
                throw new IncrementalBackupCannotBeFirstException();
            }

            var list = new Dictionary <string, FileRestoreCopyInfo>();

            foreach (var filePath in objectsForBackup)
            {
                // Упрощение: Если нет, или изменился размер файла
                if (!lastPoint.Info.ContainsKey(filePath) ||
                    lastPoint.Info[filePath].BackupSize != new FileInfo(filePath).Length)
                {
                    var point = lastPoint;
                    while (!point.Info.ContainsKey(filePath) && !(point is FullBackupPoint))
                    {
                        point = point.PreviousPoint;
                    }

                    var size = new FileInfo(filePath).Length;
                    if (!point.Info.ContainsKey(filePath))
                    {
                        size = Math.Abs(size - point.Info[filePath].BackupSize);
                    }

                    list.Add(filePath, new FileRestoreCopyInfo(filePath, size, DateTimeProvider.Now, storingAlgorithm.BackupPath));
                    // storingAlgorithm.CopyFile(filePath);
                }
            }

            if (list.Count == 0)
            {
                throw new NoChangesForIncrementalBackupException();
            }

            return(new IncrementalBackupPoint(lastPoint, list, DateTimeProvider.Now));
        }
Beispiel #6
0
        public RestorePoint Clean(RestorePoint lastPoint, out bool areMorePointsLeft)
        {
            areMorePointsLeft = false;
            var          point     = lastPoint;
            RestorePoint prevPoint = null;

            while (point != null && (point.CreationDate >= Date || point is IncrementalBackupPoint))
            {
                prevPoint = point;
                point     = point.PreviousPoint;
            }

            if (prevPoint != null)
            {
                prevPoint.PreviousPoint = null;
            }

            return(lastPoint);
        }
        public RestorePoint Clean(RestorePoint lastPoint, out bool areMorePointsLeft)
        {
            ICleaningAlgorithm selectedAlgorithm = null;
            long numberOfLeftPoints = 0;
            var  isNumberSet        = false;

            foreach (var algorithm in Algorithms)
            {
                if (MinimumFlag)
                {
                    // minimum
                    if (algorithm.CountLeftPoints(lastPoint) < numberOfLeftPoints || !isNumberSet)
                    {
                        isNumberSet        = true;
                        numberOfLeftPoints = algorithm.CountLeftPoints(lastPoint);
                        selectedAlgorithm  = algorithm;
                    }
                }
                else
                {
                    // maximum
                    if (algorithm.CountLeftPoints(lastPoint) > numberOfLeftPoints || !isNumberSet)
                    {
                        isNumberSet        = true;
                        numberOfLeftPoints = algorithm.CountLeftPoints(lastPoint);
                        selectedAlgorithm  = algorithm;
                    }
                }
            }

            if (selectedAlgorithm == null)
            {
                throw new NullReferenceException("Nothing selected for cleaning algorithm");
            }

            return(selectedAlgorithm.Clean(lastPoint, out areMorePointsLeft));
        }
Beispiel #8
0
 public IncrementalBackupPoint(RestorePoint previousPoint, Dictionary <string, FileRestoreCopyInfo> info, DateTime creationDate) : base(previousPoint, info, creationDate)
 {
 }