public async Task RestorePartialParallelAsync(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));
                            int counts = await SafeNativeMethods.FilesAndDirectoryListCountAsync(item.FullName);

                            OnAtomicTotalCounts?.Invoke(this, counts);
                            new DirectoryInfo($@"{path}\{item.Name}").Create();
                            await objrestorehandler.CopyPartialParallelAsync(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));
                            int counts = await SafeNativeMethods.FilesAndDirectoryListCountAsync(item.FullName);

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


            OnDataRestoreComplete?.Invoke(this, new StringEventArgs("Data Restore Completed"));
        }
Exemple #2
0
        public async Task BackupAsync(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));
                    int counts = await countModel.TotalCountsAsync(source);

                    //OnAtomicTotalCounts?.Invoke(this, (counts.FileCount + counts.DirCount));
                    OnAtomicTotalCounts?.Invoke(this, counts);
                    await objbackuphandler.CopyRecursiveAsync(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));
                        int counts = await countModel.TotalCountsAsync(source);

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

            OnBackupComplete?.Invoke(this, new StringEventArgs("Data Backup Completed"));
        }
Exemple #3
0
        public async Task DifferenceBackupPartialParallelAsync(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);
                    int counts = await SafeNativeMethods.FilesAndDirectoryListCountAsync(source);

                    OnAtomicTotalCounts?.Invoke(this, counts);
                    await objbackuphandler.DifferenceCopyPartialParallelAsync(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);
                        int counts = await SafeNativeMethods.FilesAndDirectoryListCountAsync(path);

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

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