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)); int counts = await SafeNativeMethods.FilesAndDirectoryListCountAsync(item.FullName); OnAtomicTotalCounts?.Invoke(this, counts); 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)); int counts = await SafeNativeMethods.FilesAndDirectoryListCountAsync(item.FullName); OnAtomicTotalCounts?.Invoke(this, counts); 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")); }