mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 10:16:24 +02:00
Merge pull request #70 from microsoft/indexerException
Fix for Indexer exceptions
This commit is contained in:
@@ -87,11 +87,15 @@ namespace Wox.Plugin.Indexer
|
||||
results.Add(r);
|
||||
}
|
||||
}
|
||||
catch(InvalidOperationException)
|
||||
{
|
||||
//The connection has closed, internal error of ExecuteReader()
|
||||
//Not showing this exception to the users
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
results.Add(new Result
|
||||
{
|
||||
// TODO: Localize the string
|
||||
Title = ex.ToString(),
|
||||
IcoPath = "Images\\WindowsIndexerImg.bmp"
|
||||
});
|
||||
|
||||
@@ -10,9 +10,12 @@ namespace Wox.Plugin.Indexer.SearchHelper
|
||||
public OleDbConnection conn;
|
||||
public OleDbCommand command;
|
||||
public OleDbDataReader WDSResults;
|
||||
private readonly object _lock = new object();
|
||||
|
||||
|
||||
public IEnumerable<SearchResult> ExecuteQuery(ISearchQueryHelper queryHelper, string keyword)
|
||||
public List<SearchResult> ExecuteQuery(ISearchQueryHelper queryHelper, string keyword)
|
||||
{
|
||||
List<SearchResult> _Result = new List<SearchResult>();
|
||||
// Generate SQL from our parameters, converting the userQuery from AQS->WHERE clause
|
||||
string sqlQuery = queryHelper.GenerateSQLFromUserQuery(keyword);
|
||||
|
||||
@@ -29,19 +32,19 @@ namespace Wox.Plugin.Indexer.SearchHelper
|
||||
// execute the command, which returns the results as an OleDbDataReader.
|
||||
using (WDSResults = command.ExecuteReader())
|
||||
{
|
||||
while (WDSResults.Read())
|
||||
if(WDSResults.HasRows)
|
||||
{
|
||||
// col 0 is our path in display format
|
||||
if (WDSResults.GetString(0) != null)
|
||||
while (WDSResults.Read() && WDSResults.GetValue(0) != DBNull.Value)
|
||||
{
|
||||
var result = new SearchResult { Path = WDSResults.GetString(0) };
|
||||
yield return result;
|
||||
_Result.Add(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return _Result;
|
||||
}
|
||||
|
||||
|
||||
@@ -91,10 +94,12 @@ namespace Wox.Plugin.Indexer.SearchHelper
|
||||
|
||||
public IEnumerable<SearchResult> Search(string keyword, string pattern = "*", int maxCount = 100)
|
||||
{
|
||||
ISearchQueryHelper queryHelper;
|
||||
InitQueryHelper(out queryHelper, maxCount);
|
||||
ModifyQueryHelper(ref queryHelper, pattern);
|
||||
return ExecuteQuery(queryHelper, keyword);
|
||||
lock(_lock){
|
||||
ISearchQueryHelper queryHelper;
|
||||
InitQueryHelper(out queryHelper, maxCount);
|
||||
ModifyQueryHelper(ref queryHelper, pattern);
|
||||
return ExecuteQuery(queryHelper, keyword);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,14 +132,33 @@ namespace Wox.Test.Plugins
|
||||
_api.InitQueryHelper(out queryHelper, 10);
|
||||
_api.ModifyQueryHelper(ref queryHelper, "*");
|
||||
string keyword = "test";
|
||||
bool commandDisposed = false;
|
||||
bool resultDisposed = false;
|
||||
|
||||
// Act
|
||||
_api.ExecuteQuery(queryHelper, keyword);
|
||||
try
|
||||
{
|
||||
_api.command.ExecuteReader();
|
||||
}
|
||||
catch(InvalidOperationException)
|
||||
{
|
||||
commandDisposed = true;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_api.WDSResults.Read();
|
||||
}
|
||||
catch(InvalidOperationException)
|
||||
{
|
||||
resultDisposed = true;
|
||||
}
|
||||
|
||||
// Assert
|
||||
Assert.IsNull(_api.conn);
|
||||
Assert.IsNull(_api.command);
|
||||
Assert.IsNull(_api.WDSResults);
|
||||
Assert.IsTrue(_api.conn.State == System.Data.ConnectionState.Closed);
|
||||
Assert.IsTrue(commandDisposed);
|
||||
Assert.IsTrue(resultDisposed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,11 +66,12 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
||||
<PackageReference Include="System.Data.OleDb" Version="4.7.0" />
|
||||
<PackageReference Include="PropertyChanged.Fody" Version="3.2.7" />
|
||||
<PackageReference Include="System.Data.SQLite" Version="1.0.112" />
|
||||
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.112" />
|
||||
<PackageReference Include="System.Runtime" Version="4.3.1" />
|
||||
<PackageReference Include="System.Data.OleDb" Version="5.0.0-preview.2.20160.6" />
|
||||
<PackageReference Include="tlbimp-Microsoft.Search.Interop" Version="1.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user