mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-10 05:06:36 +02:00
Remove hidden files from indexer results (#4325)
* Added functionality to not display hidden files * Added interfaces for seperating db layer * Updated variable naming and refactored Database connection class * Added tests for WindowsSearchAPI class * Fixed nit with braces * Added function to test that all connections from database are closed
This commit is contained in:
committed by
GitHub
parent
7ed03c8b90
commit
a21a3827fd
@@ -0,0 +1,80 @@
|
||||
using Microsoft.Plugin.Indexer.Interface;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.OleDb;
|
||||
|
||||
namespace Microsoft.Plugin.Indexer.SearchHelper
|
||||
{
|
||||
public class OleDBSearch : ISearch
|
||||
{
|
||||
private OleDbCommand command;
|
||||
private OleDbConnection conn;
|
||||
private OleDbDataReader WDSResults;
|
||||
|
||||
public List<OleDBResult> Query(string connectionString, string sqlQuery)
|
||||
{
|
||||
List<OleDBResult> result = new List<OleDBResult>();
|
||||
|
||||
using (conn = new OleDbConnection(connectionString))
|
||||
{
|
||||
// open the connection
|
||||
conn.Open();
|
||||
|
||||
// now create an OleDB command object with the query we built above and the connection we just opened.
|
||||
using (command = new OleDbCommand(sqlQuery, conn))
|
||||
{
|
||||
using (WDSResults = command.ExecuteReader())
|
||||
{
|
||||
if (WDSResults.HasRows)
|
||||
{
|
||||
while (WDSResults.Read())
|
||||
{
|
||||
List<Object> fieldData = new List<object>();
|
||||
for (int i = 0; i < WDSResults.FieldCount; i++)
|
||||
{
|
||||
fieldData.Add(WDSResults.GetValue(i));
|
||||
}
|
||||
result.Add(new OleDBResult(fieldData));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Checks if all the variables related to database connection have been properly disposed
|
||||
public bool HaveAllDisposableItemsBeenDisposed()
|
||||
{
|
||||
bool commandDisposed = false;
|
||||
bool connDisposed = false;
|
||||
bool resultDisposed = false;
|
||||
|
||||
try
|
||||
{
|
||||
command.ExecuteReader();
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
commandDisposed = true;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
WDSResults.Read();
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
resultDisposed = true;
|
||||
}
|
||||
|
||||
if(conn.State == System.Data.ConnectionState.Closed)
|
||||
{
|
||||
connDisposed = true;
|
||||
}
|
||||
|
||||
return commandDisposed && resultDisposed && connDisposed;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user