Skip to content

Commit

Permalink
more Results instead of Exceptions;
Browse files Browse the repository at this point in the history
  • Loading branch information
eisbaer66 committed Mar 30, 2017
1 parent c9d32dc commit cf97759
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions PurgeDemoCommands/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public void SetCommands(string[] value)

public async Task<IEnumerable<Result>> ExecuteThrottled()
{
GuardArguments();
Result result = GuardArguments();
if (result != null)
return new[] { result };

TransformBlock<string, Result> purges = new TransformBlock<string, Result>(file => Purge(file), new ExecutionDataflowBlockOptions {MaxDegreeOfParallelism = Environment.ProcessorCount });
BufferBlock<Result> buffer = new BufferBlock<Result>();
Expand All @@ -59,19 +61,23 @@ public async Task<IEnumerable<Result>> ExecuteThrottled()

public IEnumerable<Task<Result>> Execute()
{
GuardArguments();
Result result = GuardArguments();
if (result != null)
return new[] {Task.FromResult(result) };

return Filenames.Select(Purge);
}

private void GuardArguments()
private Result GuardArguments()
{
if (Filenames == null)
throw new ArgumentNullException(nameof(Filenames));
return new Result("unknown") {ErrorText = "no files specified"};
if (NewFilePattern == null)
throw new ArgumentNullException(nameof(NewFilePattern));
return new Result("unknown") { ErrorText = "no filepattern for new files specified" };
if (Filenames.Count == 0)
throw new ArgumentException("no file specified", nameof(NewFilePattern));
return new Result("unknown") { ErrorText = "no files specified" };

return null;
}

private async Task<Result> Purge(string filename)
Expand Down

0 comments on commit cf97759

Please sign in to comment.