예제 #1
0
        public async Task RestoreAsync(Regions regions, string TargetPath, string _user, LogOptions _logOptions, LogState _logstate, LogOperation _logoperation, CancellationToken token)
        {
            Logger.assignLogPath(TargetPath, _logstate, _logoperation);
            RestoreCopyHandler objrestorehandler = new RestoreCopyHandler();

            objrestorehandler.OnAtomicCurrent += DataBackup_OnAtomicCurrent;

            var model = FileOperations.Read(TargetPath);

            if (model.CustomPaths != null)
            {
                regions.SetPaths(model.CustomPaths);
            }

            OnDataRestoreStart?.Invoke(this, new StringEventArgs("Data Restore Started"));

            var BackupDirectoriesInfo = (new DirectoryInfo(TargetPath)).GetDirectories();

            foreach (var path in regions.GetPaths(_user))
            {
                PathValidator validator = new PathValidator();
                if (validator.Validate(path))
                {
                    var _path = new DirectoryInfo(path);

                    foreach (var item in BackupDirectoriesInfo.Where(x => x.Name.Equals(_path.Name)))
                    {
                        if (!(new DirectoryInfo(path)).Name.Equals(item.Name))
                        {
                            OnCalculationStart?.Invoke(this, true);
                            EnumData   countModel = new EnumData();
                            CountModel counts     = await countModel.GetCountAsync(new DirectoryInfo(item.FullName));

                            OnAtomicTotalCounts?.Invoke(this, (counts.FileCount + counts.DirCount));
                            new DirectoryInfo($@"{path}\{item.Name}").Create();
                            await objrestorehandler.CopyRecursiveAsync(item, new DirectoryInfo($@"{path}\{item.Name}"), _logOptions, token);
                        }
                        else
                        {
                            OnCalculationStart?.Invoke(this, true);
                            EnumData   countModel = new EnumData();
                            CountModel counts     = await countModel.GetCountAsync(new DirectoryInfo(item.FullName));

                            OnAtomicTotalCounts?.Invoke(this, (counts.FileCount + counts.DirCount));
                            await objrestorehandler.CopyRecursiveAsync(item, new DirectoryInfo(path), _logOptions, token);
                        }
                    }
                }
                else
                {
                    Logger.log(path, "path not found", _logOptions);
                }
            }


            OnDataRestoreComplete?.Invoke(this, new StringEventArgs("Data Restore Completed"));
        }
예제 #2
0
        public async Task BackupPartialParallelAsync(Regions regions, string TargetPath, string source, string _user, LogOptions _logOptions, LogState _logstate, LogOperation _logoperation, CancellationToken token)
        {
            Logger.assignLogPath(TargetPath, _logstate, _logoperation);
            BackupCopyHandler objbackuphandler = new BackupCopyHandler();

            objbackuphandler.OnAtomicCurrent += DataBackup_OnAtomicCurrent;

            OnBackupStart?.Invoke(this, new StringEventArgs("Data Backup Started"));

            if (!string.IsNullOrEmpty(source))
            {
                PathValidator validator = new PathValidator();
                if (validator.Validate(source))
                {
                    OnCalculationStart?.Invoke(this, true);
                    EnumData   countModel = new EnumData();
                    CountModel counts     = await countModel.GetCountAsync(new DirectoryInfo(source));

                    OnAtomicTotalCounts?.Invoke(this, (counts.FileCount + counts.DirCount));
                    await objbackuphandler.CopyPartialParallelAsync(new DirectoryInfo(source), new DirectoryInfo(TargetPath), _logOptions, token);
                }
                else
                {
                    Logger.log(source, "path not found", _logOptions);
                }
            }
            else
            {
                foreach (var path in regions.GetPaths(_user))
                {
                    PathValidator validator = new PathValidator();
                    if (validator.Validate(path))
                    {
                        OnCalculationStart?.Invoke(this, true);
                        EnumData   countModel = new EnumData();
                        CountModel counts     = await countModel.GetCountAsync(new DirectoryInfo(path));

                        OnAtomicTotalCounts?.Invoke(this, (counts.FileCount + counts.DirCount));
                        await objbackuphandler.CopyPartialParallelAsync(new DirectoryInfo(path), new DirectoryInfo(TargetPath), _logOptions, token);
                    }
                    else
                    {
                        Logger.log(path, "path not found", _logOptions);
                    }
                }
            }


            OnBackupComplete?.Invoke(this, new StringEventArgs("Data Backup Completed"));
        }