コード例 #1
0
        protected override async Task <string> ExecuteInternal()
        {
            var filePaths = new Queue <string>(FileRetriever.GetSortedFilePathsRecursively(PathService.Source));
            var copyTasks = CreateFixedBatchOfCopyTasks(filePaths);

            var finishedTask = Task.FromResult(string.Empty);

            while (copyTasks.Any())
            {
                finishedTask = await Task.WhenAny(copyTasks);

                if (CancellationTokenSource.IsCancellationRequested)
                {
                    break;
                }

                copyTasks.Remove(finishedTask);

                if (filePaths.Any())
                {
                    copyTasks.Add(BuildNextTask(filePaths.Dequeue()));
                }
            }

            //Return the result of the last task to finish.
            //NB: awaiting does not wrap the OperationCanceledException in an AggreagateException,
            //while calling finishedTask.Result does so, and prevents the error handling on OCE in the base class from running
            return(await finishedTask);
        }
コード例 #2
0
        protected override async Task <string> ExecuteInternal()
        {
            var filePaths = new Queue <string>(FileRetriever.GetSortedFilePathsRecursively(PathService.Source)
                                               .Where(fp => fp.Contains("Silents - Demo - 02") && !fp.EndsWith(".md5")));
            var copyTasks = CreateFixedBatchOfCopyTasks(filePaths);

            var firstTaskToFinish = Task.FromResult(string.Empty);

            while (copyTasks.Any())
            {
                firstTaskToFinish = await Task.WhenAny(copyTasks);

                CancellationTokenSource.Cancel();
                break;
            }

            //Return the result of the last task to finish.
            //NB: awaiting does not wrap the OperationCanceledException in an AggreagateException,
            //while calling finishedTask.Result does so, and prevents the error handling on OCE in the base class from running
            return(await firstTaskToFinish);
        }
コード例 #3
0
        protected override async Task <string> ExecuteInternal()
        {
            var filePaths = new Queue <string>(FileRetriever.GetSortedFilePathsRecursively(PathService.Source)
                                               .Where(fp => fp.Contains(".m4a"))
                                               .OrderBy(fp => fp.Contains(".md5") ? 0 : 1));
            var copyTasks = CreateFixedBatchOfCopyTasks(filePaths);

            var path = string.Empty;

            while (copyTasks.Any())
            {
                var finishedTask = await Task.WhenAny(copyTasks);

                if (CancellationTokenSource.IsCancellationRequested)
                {
                    break;
                }

                path = await finishedTask;
                if (!IsValidMd5(path))
                {
                    CancellationTokenSource.Cancel();
                    throw new FileFormatException($"Invalid MD5 for {path}");
                }

                copyTasks.Remove(finishedTask);

                if (filePaths.Any())
                {
                    copyTasks.Add(BuildNextTask(filePaths.Dequeue()));
                }
            }

            //Return the result of the last task to finish.
            //NB: awaiting does not wrap the OperationCanceledException in an AggreagateException,
            //while calling finishedTask.Result does so, and prevents the error handling on OCE in the base class from running
            return(path);
        }