diff --git a/DicomGrepCli/Program.cs b/DicomGrepCli/Program.cs index 2749480..ebf47c6 100644 --- a/DicomGrepCli/Program.cs +++ b/DicomGrepCli/Program.cs @@ -1,4 +1,5 @@ -using DicomGrepCore.Enums; +using DicomGrepCore.Entities; +using DicomGrepCore.Enums; using DicomGrepCore.Services; using FellowOakDicom; using System.CommandLine; @@ -103,20 +104,34 @@ static async Task 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(); diff --git a/DicomGrepCli/SearchCriteriaBinder.cs b/DicomGrepCli/SearchCriteriaBinder.cs new file mode 100644 index 0000000..2fe06fe --- /dev/null +++ b/DicomGrepCli/SearchCriteriaBinder.cs @@ -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 + { + + private readonly Option _folderOption; + private readonly Option _fileTypeOption; + private readonly Option _recursiveOption; + private readonly Option _sopClassOption; + private readonly Option _tagOption; + private readonly Option _valueOption; + private readonly Option _caseSensitiveOption; + private readonly Option _wholeWordOption; + private readonly Option _threadsOption; + private readonly Option _patternOption; + + + public SearchCriteriaBinder(Option folderOption, Option fileTypeOption, + Option recursiveOption, Option sopClassOption, Option tagOption, + Option valueOption, Option caseSensitiveOption, Option wholeWordOption, + Option threadsOption, Option 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) + }; + } + } +}