Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix search everywhere #2190

Merged
merged 4 commits into from
Dec 14, 2024
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
24 changes: 11 additions & 13 deletions Analogy.Common/DataTypes/FilterCriteriaObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class FilterCriteriaObject
public string[] ExcludedSources;
public string[] Modules;
public string[] ExcludedModules;
public bool SearchEveryWhere { get; set; }
public bool SearchEverywhere { get; set; }
public List<(string Field, bool Numerical)> Columns { get; set; }
public string TextInclude { get; set; }
public string TextExclude { get; set; }
Expand Down Expand Up @@ -187,7 +187,7 @@ public string GetSqlExpression(bool orLogLevel)

sqlString.Append(dateFilter);

if (includeTexts.Any() && !SearchEveryWhere)
if (includeTexts.Any() && !SearchEverywhere)
{
var includeColumns = IncludeFilterCriteriaUIOptions.Where(f => f.CheckMember);
foreach (FilterCriteriaUIOption include in includeColumns)
Expand Down Expand Up @@ -228,32 +228,30 @@ IEnumerable<string> GenerateSingleCombinationPerColumn(string field, bool numeri
{
if (!string.IsNullOrEmpty(text) && int.TryParse(text, out var number))
{
yield return $" {field} = {number}";
yield return $" [{field}] = {number}";
}
}
else
{
yield return $" {field} like '%{text}%'";
yield return $" [{field}] like '%{text}%'";
}
}
}

if (SearchEveryWhere)
if (SearchEverywhere)
{
var allValidCombinations =
Columns.Select(c => GenerateSingleCombinationPerColumn(c.Field, c.Numerical).ToList());
var entries = allValidCombinations.Where(c => c.Any()).Select(c =>
var entries = allValidCombinations.Where(c => c.Count > 0 && c.TrueForAll(item => !string.IsNullOrEmpty(item))).Select(c =>
string.Join(orOperationInInclude ? " Or " : " and ", c));
var combined = string.Join(" Or ", entries);
return combined;
}
else
{
var includeTextFinal = orOperationInInclude
? string.Join(" Or ", GenerateSingleCombinationPerColumn("Text", false))
: string.Join(" and ", GenerateSingleCombinationPerColumn("Text", false));
return includeTextFinal;
}

var includeTextFinal = orOperationInInclude
? string.Join(" Or ", GenerateSingleCombinationPerColumn("Text", false))
: string.Join(" and ", GenerateSingleCombinationPerColumn("Text", false));
return includeTextFinal;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool Match(string rowLine, string criteria, PreDefinedQueryType type)
Expand Down
1 change: 1 addition & 0 deletions Analogy.Common/Interfaces/IUserSettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public interface IUserSettingsManager
string LogsLayoutFileName { get; }
bool UseCustomLogsLayout { get; set; }
bool ViewDetailedMessageWithHTML { get; set; }
bool CollapseFolderAndFilesPanel { get; set; }
TimeSpan TimeOffset { get; set; }
TimeOffsetType TimeOffsetType { get; set; }

Expand Down
1 change: 1 addition & 0 deletions Analogy.Common/Managers/DefaultUserSettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
{
public event EventHandler<bool>? OnInlineJsonViewerChanged;
public bool SaveSearchFilters { get; set; }
public string IncludeText { get; set; }

Check warning on line 14 in Analogy.Common/Managers/DefaultUserSettingsManager.cs

View workflow job for this annotation

GitHub Actions / build (Debug)

Non-nullable property 'IncludeText' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 14 in Analogy.Common/Managers/DefaultUserSettingsManager.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Non-nullable property 'IncludeText' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string ExcludeText { get; set; }

Check warning on line 15 in Analogy.Common/Managers/DefaultUserSettingsManager.cs

View workflow job for this annotation

GitHub Actions / build (Debug)

Non-nullable property 'ExcludeText' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 15 in Analogy.Common/Managers/DefaultUserSettingsManager.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Non-nullable property 'ExcludeText' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string SourceText { get; set; }
public string ModuleText { get; set; }
public bool EnableFileCaching { get; set; }
Expand Down Expand Up @@ -54,6 +54,7 @@
public bool SupportLinuxFormatting { get; set; }
public bool HideUnknownLogLevel { get; set; }

public bool CollapseFolderAndFilesPanel { get; set; }
public void Save(string version)
{
}
Expand Down
39 changes: 28 additions & 11 deletions Analogy.CommonControls/UserControls/LogMessagesUC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ private bool ChangeRawSQLMode(bool enable)
private List<FilterCriteriaUIOption> IncludeFilterCriteriaUIOptions { get; set; }
private List<FilterCriteriaUIOption> ExcludeFilterCriteriaUIOptions { get; set; }
private bool FullModeEnabled { get; set; }
private bool CollapseFolderAndFilesPanel { get; set; }
private bool LoadingInProgress => fileLoadingCount > 0;
private IUserSettingsManager Settings { get; set; }
private IExtensionsManager ExtensionManager { get; set; }
Expand Down Expand Up @@ -513,8 +512,8 @@ private void SetupEventsHandlers()
{
bbiCollapseFolderPanel.ItemClick += (sBtnLastPage, e) =>
{
CollapseFolderAndFilesPanel = !CollapseFolderAndFilesPanel;
CollapseFileAndFolderPanel?.Invoke(this, CollapseFolderAndFilesPanel);
Settings.CollapseFolderAndFilesPanel = !Settings.CollapseFolderAndFilesPanel;
CollapseFileAndFolderPanel?.Invoke(this, Settings.CollapseFolderAndFilesPanel);
};
sbtnServerSide.Click += async (s, e) =>
{
Expand Down Expand Up @@ -549,7 +548,7 @@ private void SetupEventsHandlers()
};
ceSearchEverywhere.CheckedChanged += async (s, e) =>
{
_filterCriteria.SearchEveryWhere = ceSearchEverywhere.Checked;
_filterCriteria.SearchEverywhere = ceSearchEverywhere.Checked;
await FilterHasChanged();
};
ddbGoTo.ArrowButtonClick += (s, e) =>
Expand Down Expand Up @@ -1072,16 +1071,23 @@ private void LogGrid_ColumnPositionChanged(object? sender, EventArgs e)

private void UpdateSearchColumn()
{
bool GetNumericalValue(GridColumn column) => column == gridColumnLineNumber || column == gridColumnProcessID || column == gridColumnThread;
bool GetNumericalValue(GridColumn column)
{
return Type.GetTypeCode(column.ColumnType) switch
{
TypeCode.Byte or TypeCode.SByte or TypeCode.UInt16 or TypeCode.UInt32 or TypeCode.UInt64
or TypeCode.Int16 or TypeCode.Int32 or TypeCode.Int64 or TypeCode.Decimal or TypeCode.Double
or TypeCode.Single => true,
_ => false,
};
}
_filterCriteria.Columns = logGrid.Columns.Where(c => c.Visible)
.Except(new List<GridColumn>()
{
gridColumnDate,
gridColumnTimeDiff,
gridColumnObject,
gridColumnRawText,
gridColumnDate, gridColumnTimeDiff, gridColumnObject, gridColumnRawText,
})
.Select(c => (c.FieldName, GetNumericalValue(c))).ToList();
.Select(c => (c.FieldName, GetNumericalValue(c)))
.ToList();
}
private void GridView_ShownEditor(object sender, System.EventArgs e)
{
Expand Down Expand Up @@ -1982,10 +1988,12 @@ private void AddExtraColumnsToLogGrid(GridView gridView, IAnalogyLogMessage mess
if (message.AdditionalProperties != null && message.AdditionalProperties.Any() &&
Settings.CheckAdditionalInformation)
{
var newFieldCreated = false;
foreach (KeyValuePair<string, string> info in message.AdditionalProperties)
{
if (!CurrentColumnsFields.Exists(c => c.Field == info.Key))
{
newFieldCreated = true;
if (InvokeRequired)
{
BeginInvoke(new MethodInvoker(() =>
Expand Down Expand Up @@ -2017,6 +2025,11 @@ private void AddExtraColumnsToLogGrid(GridView gridView, IAnalogyLogMessage mess
}
}
}

if (newFieldCreated)
{
UpdateSearchColumn();
}
}
}
}
Expand Down Expand Up @@ -2323,7 +2336,7 @@ private void FilterResults()
meRawSQL.Text = filter;
OnSetRawSQLFilter?.Invoke(this, filter);
_messageData.DefaultView.RowFilter = filter;
if (!Settings.AutoScrollToLastMessage && Settings.TrackActiveMessage)
if (Settings is { AutoScrollToLastMessage: false, TrackActiveMessage: true })
{
var location = LocateByValue(0, gridColumnObject, SelectedMassage);
if (location >= 0)
Expand Down Expand Up @@ -3778,5 +3791,9 @@ public void HideSecondaryWindow()
dockPanel.Visibility = DockVisibility.Hidden;
}
}
public void ApplyCollapseFileAndFolderSettings()
{
CollapseFileAndFolderPanel?.Invoke(this, Settings.CollapseFolderAndFilesPanel);
}
}
}
3 changes: 3 additions & 0 deletions Analogy/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@
<setting name="HideUnknownLogLevel" serializeAs="String">
<value>False</value>
</setting>
<setting name="CollapseFolderAndFilesPanel" serializeAs="String">
<value>False</value>
</setting>
</Analogy.Properties.Settings>
</userSettings>
</configuration>
4 changes: 3 additions & 1 deletion Analogy/CommonChangeLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ public static IEnumerable<AnalogyChangeLog> GetChangeLog()
{
return new List<AnalogyChangeLog>
{
new ("V7.1.1 - Add option to filter out Unknown log level #2118", AnalogChangeLogType.Feature, "Lior Banai", new DateTime(2024, 12, 07), "7.1.1"),
new ("V7.1.1 - Remember CollapseFolderAndFilesPanel Settings #2198", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2024, 12, 14), "7.1.1"),
new ("V7.1.1 - Add option to filter out Unknown log level #2118", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2024, 12, 07), "7.1.1"),
new ("V7.1.0 - Add NET9 #2163", AnalogChangeLogType.Improvement, "Lior Banai", new DateTime(2024, 12, 03), "7.1.0"),
new ("V7.1.0 - Remove NET6 as it is near end of life #2095", AnalogChangeLogType.Feature, "Lior Banai", new DateTime(2024, 09, 27), "7.1.0"),
new ("V7.0.0 - Split Interface nuget to Non Windows Types #2094", AnalogChangeLogType.Feature, "Lior Banai", new DateTime(2024, 09, 07), "7.0.0"),
new ("V6.0.2 - DevExpress 24.1 #2055", AnalogChangeLogType.Feature, "Lior Banai", new DateTime(2024, 06, 28), "6.0.2"),
Expand Down
1 change: 1 addition & 0 deletions Analogy/DataTypes/UserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public class UserSettings
public bool CombineOfflineProviders { get; set; }
public bool CombineOnlineProviders { get; set; }
public Dictionary<Guid, AnalogyPositionState> WindowPositions { get; set; }
public bool CollapseFolderAndFilesPanel { get; set; }

public UserSettings()
{
Expand Down
5 changes: 5 additions & 0 deletions Analogy/Managers/UserSettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public bool InlineJsonViewer
public bool SupportLinuxFormatting { get; set; }
public bool HideUnknownLogLevel { get; set; }

public bool CollapseFolderAndFilesPanel { get; set; }
private Dictionary<Guid, AnalogyPositionState> WindowPositions { get; set; }

public UserSettingsManager(FolderAccessManager folderAccessManager)
Expand Down Expand Up @@ -354,6 +355,7 @@ private void LoadPerUserSettings()
CombineOnlineProviders = Settings.Default.CombineOnlineProviders;
SupportLinuxFormatting = Settings.Default.SupportLinuxFormatting;
HideUnknownLogLevel = Settings.Default.HideUnknownLogLevel;
CollapseFolderAndFilesPanel = Settings.Default.CollapseFolderAndFilesPanel;
WindowPositions = !string.IsNullOrEmpty(Settings.Default.WindowPositions)
? ParseSettings<Dictionary<Guid, AnalogyPositionState>>(Settings.Default.WindowPositions)
: new Dictionary<Guid, AnalogyPositionState>();
Expand Down Expand Up @@ -447,6 +449,7 @@ private void ApplyLocalSettings(UserSettings settings)
WindowPositions = settings.WindowPositions;
SupportLinuxFormatting = settings.SupportLinuxFormatting;
HideUnknownLogLevel = settings.HideUnknownLogLevel;
CollapseFolderAndFilesPanel = settings.CollapseFolderAndFilesPanel;
}
private UserSettings CreateUserSettings()
{
Expand Down Expand Up @@ -536,6 +539,7 @@ private UserSettings CreateUserSettings()
CombineOnlineProviders = CombineOnlineProviders,
WindowPositions = WindowPositions,
SupportLinuxFormatting = SupportLinuxFormatting,
CollapseFolderAndFilesPanel = CollapseFolderAndFilesPanel,
};
return userSettings;
}
Expand Down Expand Up @@ -714,6 +718,7 @@ private void SavePerUserSettings()
Settings.Default.CombineOnlineProviders = CombineOnlineProviders;
Settings.Default.WindowPositions = JsonConvert.SerializeObject(WindowPositions);
Settings.Default.SupportLinuxFormatting = SupportLinuxFormatting;
Settings.Default.CollapseFolderAndFilesPanel = CollapseFolderAndFilesPanel;
Settings.Default.Save();
}

Expand Down
14 changes: 13 additions & 1 deletion Analogy/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Analogy/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -266,5 +266,8 @@
<Setting Name="HideUnknownLogLevel" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="CollapseFolderAndFilesPanel" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>
1 change: 1 addition & 0 deletions Analogy/UserControls/LocalLogFilesUC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ private void SetupEventHandlers()
spltMain.CollapsePanel = collapsed ? SplitCollapsePanel.Panel1 : SplitCollapsePanel.None;
spltMain.PanelVisibility = collapsed ? SplitPanelVisibility.Panel2 : SplitPanelVisibility.Both;
};
ucLogs1.ApplyCollapseFileAndFolderSettings();
}
private void UcLogs1_OnFocusedRowChanged(object sender, (string File, AnalogyLogMessage Arg) data)
{
Expand Down
Loading