Skip to content

Commit

Permalink
[WIP] Working prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
celeron533 committed Jul 22, 2024
1 parent 6cae271 commit b37be53
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 22 deletions.
41 changes: 32 additions & 9 deletions DicomGrepCli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,8 @@ private static void DoRootCommand(LookupType? lookupOptionValue, SearchCriteria
}
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);
Console.WriteLine(criteria.ToString("n1"));
DoSearch(criteria);
}
}

Expand Down Expand Up @@ -163,6 +156,36 @@ private static void PrintLookup(LookupType lookupType)
break;
}
}

private static void DoSearch(SearchCriteria criteria)
{
if (string.IsNullOrEmpty(criteria.SearchPath))
{
Console.WriteLine("Please specify the directory.");
return;
}

var tokenSource = new CancellationTokenSource();//dummy
SearchService searchService = new SearchService();
searchService.FileListCompleted += (sender, e) =>
{
Console.WriteLine($"> Search in {e.Count} files...");
};
searchService.OnCompletDicomFile += (sender, e) =>
{
if (e.IsMatch)
{
Console.WriteLine(e.Filename);
}
};
searchService.OnSearchComplete += (sender, e) =>
{
Console.WriteLine($"> Search completed.");
};


searchService.Search(criteria, tokenSource);
}
}

enum LookupType
Expand Down
54 changes: 41 additions & 13 deletions DicomGrepCore/Entities/SearchCriteria.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public string SearchTag
{
_dicomSearchTag = ParseDicomTag(value);
}
catch
catch
{
// unable to parse the string
}
Expand All @@ -51,20 +51,48 @@ public string SearchTag

public override string ToString()
{
return
$"SearchPath = '{SearchPath}', " +
$"SearchSopClassUid = '{SearchSopClassUid}', " +
$"SearchTag = '{SearchTag}', " +
$"FileTypes = '{FileTypes}', " +
$"SearchText = '{SearchText}', " +
$"MatchPattern = {MatchPattern}, " +
$"CaseSensitive = {CaseSensitive}, " +
$"WholeWord = {WholeWord}, " +
$"IncludeSubfolders = {IncludeSubfolders}, " +
$"SearchInResults = {SearchInResults}, " +
$"SearchThreads = {SearchThreads}";
return ToString("c");
}

/// <summary>
/// Format the search criteria.
/// </summary>
/// <param name="format"></param>
/// <returns></returns>
public string ToString(string format)
{
switch (format)
{
case "c":
default:
return string.Join(", ", CriteriaSummary().Select(x => $"{x.Key}={x.Value}"));
case "n":
return string.Join(Environment.NewLine, CriteriaSummary().Select(x => $"{x.Key}={x.Value}"));
case "n1":
return string.Join(Environment.NewLine, CriteriaSummary().Select(x => $"> {x.Key}={x.Value}"));

}
}

private List<KeyValuePair<string,string>> CriteriaSummary()
{
List<KeyValuePair<string, string>> summary= new List<KeyValuePair<string, string>>();
summary.Add(new KeyValuePair<string, string>("SearchPath", Quote(SearchPath)));
summary.Add(new KeyValuePair<string, string>("FileTypes", Quote(FileTypes)));
summary.Add(new KeyValuePair<string, string>("IncludeSubfolders", IncludeSubfolders.ToString()));
summary.Add(new KeyValuePair<string, string>("SearchSopClassUid", Quote(SearchSopClassUid)));
summary.Add(new KeyValuePair<string, string>("SearchTag", Quote(SearchTag)));
summary.Add(new KeyValuePair<string, string>("SearchText", Quote(SearchText)));
summary.Add(new KeyValuePair<string, string>("MatchPattern", MatchPattern.ToString()));
summary.Add(new KeyValuePair<string, string>("CaseSensitive", CaseSensitive.ToString()));
summary.Add(new KeyValuePair<string, string>("WholeWord", WholeWord.ToString()));
summary.Add(new KeyValuePair<string, string>("SearchInResults", SearchInResults.ToString()));
summary.Add(new KeyValuePair<string, string>("SearchThreads", SearchThreads.ToString()));
return summary;
}

private string Quote(string value) => $"\"{value}\"";

private DicomTag ParseDicomTag(string value)
{
// escape the "xx" in private tag string. No worries, it will apply the 0xFF mask again during the search.
Expand Down

0 comments on commit b37be53

Please sign in to comment.