Skip to content

Commit

Permalink
[WIP] Parse the arguments to the search service
Browse files Browse the repository at this point in the history
  • Loading branch information
celeron533 committed Jul 21, 2024
1 parent feebaa9 commit 6cae271
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 9 deletions.
33 changes: 24 additions & 9 deletions DicomGrepCli/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DicomGrepCore.Enums;
using DicomGrepCore.Entities;
using DicomGrepCore.Enums;
using DicomGrepCore.Services;
using FellowOakDicom;
using System.CommandLine;
Expand Down Expand Up @@ -103,20 +104,34 @@ static async Task<int> Main(string[] args)


rootCommand.SetHandler(
(lookupOptionValue, folderOptionValue, recursiveOptionValue, ignoreCaseOptionValue, tagOptionValue, valueOptionValue) =>
{
if (lookupOptionValue.HasValue)
{
PrintLookup(lookupOptionValue.Value);
}
},
lookupOption, folderOption, recursiveOption, caseSensitiveOption, tagOption, valueOption
DoRootCommand,
lookupOption, new SearchCriteriaBinder(folderOption, fileTypeOption, recursiveOption, sopClassOption, tagOption, valueOption, caseSensitiveOption, wholdWordOption, threadsOption, patternOption)
);


return await rootCommand.InvokeAsync(args);
}

private static void DoRootCommand(LookupType? lookupOptionValue, SearchCriteria criteria)
{
if (lookupOptionValue.HasValue)
{
PrintLookup(lookupOptionValue.Value);
}
else
{
if (string.IsNullOrEmpty(criteria.SearchPath))
{
Console.WriteLine("Please specify the directory.");
return;
}

var tokenSource = new CancellationTokenSource();//dummy
SearchService searchService = new SearchService();
searchService.Search(criteria, tokenSource);
}
}

private static void PrintLookup(LookupType lookupType)
{
DictionaryService dictionaryService = new DictionaryService();
Expand Down
62 changes: 62 additions & 0 deletions DicomGrepCli/SearchCriteriaBinder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using DicomGrepCore.Entities;
using DicomGrepCore.Enums;
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Binding;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DicomGrepCli
{
internal class SearchCriteriaBinder : BinderBase<SearchCriteria>
{

private readonly Option<string> _folderOption;
private readonly Option<string> _fileTypeOption;
private readonly Option<bool> _recursiveOption;
private readonly Option<string> _sopClassOption;
private readonly Option<string> _tagOption;
private readonly Option<string> _valueOption;
private readonly Option<bool> _caseSensitiveOption;
private readonly Option<bool> _wholeWordOption;
private readonly Option<int> _threadsOption;
private readonly Option<MatchPatternEnum> _patternOption;


public SearchCriteriaBinder(Option<string> folderOption, Option<string> fileTypeOption,
Option<bool> recursiveOption, Option<string> sopClassOption, Option<string> tagOption,
Option<string> valueOption, Option<bool> caseSensitiveOption, Option<bool> wholeWordOption,
Option<int> threadsOption, Option<MatchPatternEnum> patternOption)
{
_folderOption = folderOption;
_fileTypeOption = fileTypeOption;
_recursiveOption = recursiveOption;
_sopClassOption = sopClassOption;
_tagOption = tagOption;
_valueOption = valueOption;
_caseSensitiveOption = caseSensitiveOption;
_wholeWordOption = wholeWordOption;
_threadsOption = threadsOption;
_patternOption = patternOption;
}

protected override SearchCriteria GetBoundValue(BindingContext bindingContext)
{
return new SearchCriteria
{
SearchPath = bindingContext.ParseResult.GetValueForOption(_folderOption),
FileTypes = bindingContext.ParseResult.GetValueForOption(_fileTypeOption),
IncludeSubfolders = bindingContext.ParseResult.GetValueForOption(_recursiveOption),
SearchSopClassUid = bindingContext.ParseResult.GetValueForOption(_sopClassOption),
SearchTag = bindingContext.ParseResult.GetValueForOption(_tagOption),
SearchText = bindingContext.ParseResult.GetValueForOption(_valueOption),
CaseSensitive = bindingContext.ParseResult.GetValueForOption(_caseSensitiveOption),
WholeWord = bindingContext.ParseResult.GetValueForOption(_wholeWordOption),
SearchThreads = bindingContext.ParseResult.GetValueForOption(_threadsOption),
MatchPattern = bindingContext.ParseResult.GetValueForOption(_patternOption)
};
}
}
}

0 comments on commit 6cae271

Please sign in to comment.