コード例 #1
0
        private async Task AddDirectory(Vault vault, IProgress <ProgressReport> progress)
        {
            var allFiles = NDirectory.GetAllFilesRecursive(ToAddPath);

            var report = new ProgressReport(allFiles.Count);

            await allFiles.ParallelForEachAsync(async file =>
            {
                var pathToFile = NPath.GetRelativePathToFile(ToAddPath, file);

                try
                {
                    await vault.AddFileAsync(file, pathToFile);
                }
                catch (Exception e)
                {
                    report.IncrementFailedFiles();
                    Log.Error(string.Format(Strings.AddCommandAsync_AddDirectory_Error_with_file__0____1_, file, e));
                }
                finally
                {
                    report.IncrementModifiedFiles();
                    progress.Report(report);
                }
            }, 0);

            Console.WriteLine();
            Notifier.Success(string.Format(Strings.AddCommandAsync_AddDirectory_Added_directory__0__to_vault, ToAddPath));
        }
コード例 #2
0
        private static async Task <List <UserDataFile> > ExtractAllFiles(Vault vlt, IProgress <ProgressReport> progress)
        {
            var manipulatedFiles = new List <UserDataFile>();

            var report = new ProgressReport(vlt.UserDataFiles.Count);

            await vlt.UserDataFiles.ParallelForEachAsync(async file =>
            {
                try
                {
                    var status = await vlt.ExtractFile(file);

                    if (status == ExtractStatus.HashNoMatch)
                    {
                        manipulatedFiles.Add(file);
                    }
                }
                catch (Exception e)
                {
                    report.IncrementFailedFiles();
                    Log.Error(string.Format(Strings.UnlockCommandAsync_ExtractAllFiles_Error_unlocking_file__0____1_, file.Header.SecuredPlainName.PlainName, e));
                }
                finally
                {
                    report.IncrementModifiedFiles();
                    progress.Report(report);
                }
            }, 0);

            return(manipulatedFiles);
        }