Merge pull request #70 from microsoft/indexerException

Fix for Indexer exceptions
This commit is contained in:
Alekhya
2020-04-08 09:26:18 -07:00
committed by GitHub
4 changed files with 44 additions and 15 deletions

View File

@@ -87,11 +87,15 @@ namespace Wox.Plugin.Indexer
results.Add(r); results.Add(r);
} }
} }
catch(InvalidOperationException)
{
//The connection has closed, internal error of ExecuteReader()
//Not showing this exception to the users
}
catch (Exception ex) catch (Exception ex)
{ {
results.Add(new Result results.Add(new Result
{ {
// TODO: Localize the string
Title = ex.ToString(), Title = ex.ToString(),
IcoPath = "Images\\WindowsIndexerImg.bmp" IcoPath = "Images\\WindowsIndexerImg.bmp"
}); });

View File

@@ -10,9 +10,12 @@ namespace Wox.Plugin.Indexer.SearchHelper
public OleDbConnection conn; public OleDbConnection conn;
public OleDbCommand command; public OleDbCommand command;
public OleDbDataReader WDSResults; 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 // Generate SQL from our parameters, converting the userQuery from AQS->WHERE clause
string sqlQuery = queryHelper.GenerateSQLFromUserQuery(keyword); string sqlQuery = queryHelper.GenerateSQLFromUserQuery(keyword);
@@ -29,19 +32,19 @@ namespace Wox.Plugin.Indexer.SearchHelper
// execute the command, which returns the results as an OleDbDataReader. // execute the command, which returns the results as an OleDbDataReader.
using (WDSResults = command.ExecuteReader()) using (WDSResults = command.ExecuteReader())
{ {
while (WDSResults.Read()) if(WDSResults.HasRows)
{ {
// col 0 is our path in display format while (WDSResults.Read() && WDSResults.GetValue(0) != DBNull.Value)
if (WDSResults.GetString(0) != null)
{ {
var result = new SearchResult { Path = WDSResults.GetString(0) }; 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) public IEnumerable<SearchResult> Search(string keyword, string pattern = "*", int maxCount = 100)
{ {
ISearchQueryHelper queryHelper; lock(_lock){
InitQueryHelper(out queryHelper, maxCount); ISearchQueryHelper queryHelper;
ModifyQueryHelper(ref queryHelper, pattern); InitQueryHelper(out queryHelper, maxCount);
return ExecuteQuery(queryHelper, keyword); ModifyQueryHelper(ref queryHelper, pattern);
return ExecuteQuery(queryHelper, keyword);
}
} }
} }
} }

View File

@@ -132,14 +132,33 @@ namespace Wox.Test.Plugins
_api.InitQueryHelper(out queryHelper, 10); _api.InitQueryHelper(out queryHelper, 10);
_api.ModifyQueryHelper(ref queryHelper, "*"); _api.ModifyQueryHelper(ref queryHelper, "*");
string keyword = "test"; string keyword = "test";
bool commandDisposed = false;
bool resultDisposed = false;
// Act // Act
_api.ExecuteQuery(queryHelper, keyword); _api.ExecuteQuery(queryHelper, keyword);
try
{
_api.command.ExecuteReader();
}
catch(InvalidOperationException)
{
commandDisposed = true;
}
try
{
_api.WDSResults.Read();
}
catch(InvalidOperationException)
{
resultDisposed = true;
}
// Assert // Assert
Assert.IsNull(_api.conn); Assert.IsTrue(_api.conn.State == System.Data.ConnectionState.Closed);
Assert.IsNull(_api.command); Assert.IsTrue(commandDisposed);
Assert.IsNull(_api.WDSResults); Assert.IsTrue(resultDisposed);
} }
} }
} }

View File

@@ -66,11 +66,12 @@
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="System.Data.OleDb" Version="4.7.0" />
<PackageReference Include="PropertyChanged.Fody" Version="3.2.7" /> <PackageReference Include="PropertyChanged.Fody" Version="3.2.7" />
<PackageReference Include="System.Data.SQLite" Version="1.0.112" /> <PackageReference Include="System.Data.SQLite" Version="1.0.112" />
<PackageReference Include="System.Data.SQLite.Core" 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.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" /> <PackageReference Include="tlbimp-Microsoft.Search.Interop" Version="1.0.0" />
</ItemGroup> </ItemGroup>