diff --git a/README.md b/README.md index af6b9e1..5b93f35 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,7 @@ Sphinx.Client Open source .NET library which provides advanced client API to use Sphinx search server services, using Sphinx native binary protocol. This repository contains public fork of original Sphinx.Client project located at Google Code (https://code.google.com/p/sphinx-dotnet-client/) + +## Download + + PM> Install-Package Sphinx.Client diff --git a/Sphinx.Client/Commands/Search/SearchQuery.cs b/Sphinx.Client/Commands/Search/SearchQuery.cs index df5658b..f0f60cc 100644 --- a/Sphinx.Client/Commands/Search/SearchQuery.cs +++ b/Sphinx.Client/Commands/Search/SearchQuery.cs @@ -446,8 +446,8 @@ internal void ValidateParameters() { ArgumentAssert.IsNotNull(Query, "Query"); ArgumentAssert.IsInRange(Offset, 0, int.MaxValue, "Offset"); - ArgumentAssert.IsInRange(Limit, 1, int.MaxValue, "Limit"); - ArgumentAssert.IsInRange(MaxMatches, 1, int.MaxValue, "MaxMatches"); + ArgumentAssert.IsInRange(Limit, 0, int.MaxValue, "Limit"); + ArgumentAssert.IsInRange(MaxMatches, 0, int.MaxValue, "MaxMatches"); ArgumentAssert.IsInRange(Cutoff, 0, int.MaxValue, "Cutoff"); ArgumentAssert.IsDefinedInEnum(typeof(MatchMode), MatchMode, "MatchMode"); ArgumentAssert.IsDefinedInEnum(typeof(ResultsSortMode), SortMode, "SortMode"); diff --git a/Sphinx.Client/Network/TcpStreamAdapter.cs b/Sphinx.Client/Network/TcpStreamAdapter.cs index 403a3bd..0e13005 100644 --- a/Sphinx.Client/Network/TcpStreamAdapter.cs +++ b/Sphinx.Client/Network/TcpStreamAdapter.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using System.IO; -using System.Text; using System.Threading; using Sphinx.Client.Helpers; using Sphinx.Client.Resources; @@ -44,6 +42,11 @@ public override int ReadBytes(byte[] buffer, int length) _resetEvent.Reset(); Stream.BeginRead(buffer, length - state.BytesLeft, state.BytesLeft, ReadDataCallback, state); WaitForNetworkData(); + + if (!string.IsNullOrEmpty(state.ErrorMessage)) + { + throw new IOException(state.ErrorMessage); + } } return length; } @@ -66,19 +69,41 @@ private void WaitForNetworkData() private void ReadDataCallback(IAsyncResult asyncResult) { NetworkReadState state = ((NetworkReadState)asyncResult.AsyncState); - if (!state.DataStream.CanRead) - throw new IOException(String.Format(Messages.Exception_CouldNotReadFromStream, state.BytesLeft, 0)); - int actualBytes = state.DataStream.EndRead(asyncResult); - if (actualBytes == 0) - throw new IOException(String.Format(Messages.Exception_CouldNotReadFromStream, state.BytesLeft, actualBytes)); - state.BytesLeft -= actualBytes; - _resetEvent.Set(); + try + { + if (!state.DataStream.CanRead) + { + state.ErrorMessage = String.Format(Messages.Exception_CouldNotReadFromStream, state.BytesLeft, 0); + } + else + { + + int actualBytes = state.DataStream.EndRead(asyncResult); + if (actualBytes == 0) + { + state.ErrorMessage = String.Format(Messages.Exception_CouldNotReadFromStream, state.BytesLeft, actualBytes); + } + else + { + state.BytesLeft -= actualBytes; + } + } + } + catch (Exception ex) + { + state.ErrorMessage = ex.ToString(); + } + finally + { + _resetEvent.Set(); + } } private class NetworkReadState { public Stream DataStream; public int BytesLeft; + public string ErrorMessage; } #endregion diff --git a/Sphinx.Client/NugetPack.bat b/Sphinx.Client/NugetPack.bat new file mode 100644 index 0000000..0702796 --- /dev/null +++ b/Sphinx.Client/NugetPack.bat @@ -0,0 +1 @@ +nuget pack Sphinx.Client.csproj -properties Configuration=Release \ No newline at end of file diff --git a/Sphinx.Client/Sphinx.Client.csproj b/Sphinx.Client/Sphinx.Client.csproj index fa25f18..53cafec 100644 --- a/Sphinx.Client/Sphinx.Client.csproj +++ b/Sphinx.Client/Sphinx.Client.csproj @@ -46,7 +46,7 @@ pdbonly true - ..\..\bin\ + bin\Release\ TRACE prompt 4 @@ -206,6 +206,9 @@ true + + +