Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions Dashboard/Helpers/NumericFilterHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@ public static bool MatchesFilter(object? value, string? filterText)
if (!TryConvertToDecimal(value, out decimal numericValue))
return true; // If can't convert, don't filter out

// Check for range: "100-200" or "100..200"
if (filterText.Contains('-', StringComparison.Ordinal) && !filterText.StartsWith('-'))
// Check for range: "100-200", "-100-200", "-100--50", or "100..200"
if (TryParseRange(filterText, out decimal rangeMin, out decimal rangeMax))
{
return EvaluateRange(numericValue, filterText);
}
else if (filterText.Contains("..", StringComparison.Ordinal))
{
return EvaluateRange(numericValue, filterText.Replace("..", "-", StringComparison.Ordinal));
return numericValue >= rangeMin && numericValue <= rangeMax;
}
// Check for >=
else if (filterText.StartsWith(">=", StringComparison.Ordinal))
Expand Down Expand Up @@ -84,28 +80,33 @@ private static bool TryConvertToDecimal(object value, out decimal result)
}
}

private static bool EvaluateRange(decimal value, string rangeText)
private static bool TryParseRange(string text, out decimal min, out decimal max)
{
var parts = rangeText.Split('-');
if (parts.Length == 2)
min = max = 0;

// Try ".." separator first (unambiguous)
int dotIdx = text.IndexOf("..", StringComparison.Ordinal);
if (dotIdx >= 0)
{
if (decimal.TryParse(parts[0].Trim(), NumberStyles.Any, CultureInfo.InvariantCulture, out decimal min) &&
decimal.TryParse(parts[1].Trim(), NumberStyles.Any, CultureInfo.InvariantCulture, out decimal max))
{
return value >= min && value <= max;
}
return decimal.TryParse(text.Substring(0, dotIdx).Trim(), NumberStyles.Any, CultureInfo.InvariantCulture, out min) &&
decimal.TryParse(text.Substring(dotIdx + 2).Trim(), NumberStyles.Any, CultureInfo.InvariantCulture, out max);
}
// Handle negative numbers in range: e.g., "-100-200" means -100 to 200
else if (parts.Length == 3 && string.IsNullOrEmpty(parts[0]))

// For "-" separator, find the dash that separates two values (not a negative sign).
// A separator dash has a digit before it: "100-200", "-100-200", "-100--50"
for (int i = 1; i < text.Length; i++)
{
if (decimal.TryParse("-" + parts[1].Trim(), NumberStyles.Any, CultureInfo.InvariantCulture, out decimal min) &&
decimal.TryParse(parts[2].Trim(), NumberStyles.Any, CultureInfo.InvariantCulture, out decimal max))
if (text[i] == '-' && char.IsDigit(text[i - 1]))
{
return value >= min && value <= max;
if (decimal.TryParse(text.Substring(0, i).Trim(), NumberStyles.Any, CultureInfo.InvariantCulture, out min) &&
decimal.TryParse(text.Substring(i + 1).Trim(), NumberStyles.Any, CultureInfo.InvariantCulture, out max))
{
return true;
}
}
}

return true; // Invalid range, don't filter
return false;
}
}
}
2 changes: 1 addition & 1 deletion Dashboard/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private void MainWindow_Closing(object? sender, System.ComponentModel.CancelEven
try
{
_mcpCts?.Cancel();
_mcpHostService.StopAsync(CancellationToken.None).Wait(TimeSpan.FromSeconds(5));
Task.Run(() => _mcpHostService.StopAsync(CancellationToken.None)).Wait(TimeSpan.FromSeconds(5));
}
catch (Exception ex)
{
Expand Down
Loading