Skip to content
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ obj/
_ReSharper*/
[Tt]est[Rr]esult*
*.orig
LoveSeat.IntegrationTest/LoveSeat.IntegrationTest.pidb
LoveSeat.IntegrationTest/LoveSeat.IntegrationTest.pidb
packages/
5 changes: 3 additions & 2 deletions LoveSeat.IntegrationTest/LoveSeat.IntegrationTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
<Reference Include="Moq">
<HintPath>..\Libraries\Moq\Moq.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=3.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libraries\Newtonsoft.Json.dll</HintPath>
<HintPath>..\packages\Newtonsoft.Json.6.0.1\lib\net35\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand Down Expand Up @@ -73,6 +73,7 @@
<None Include="App.config">
<SubType>Designer</SubType>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="Files\martin.jpg" />
Expand Down
4 changes: 4 additions & 0 deletions LoveSeat.IntegrationTest/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="6.0.1" targetFramework="net35" />
</packages>
7 changes: 5 additions & 2 deletions LoveSeat.Interfaces/LoveSeat.Interfaces.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=4.0.3.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libraries\Newtonsoft.Json.dll</HintPath>
<HintPath>..\packages\Newtonsoft.Json.6.0.1\lib\net35\Newtonsoft.Json.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
4 changes: 4 additions & 0 deletions LoveSeat.Interfaces/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="6.0.1" targetFramework="net35" />
</packages>
8 changes: 6 additions & 2 deletions LoveSeat.Repository/LoveSeat.Repositories.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\Libraries\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.6.0.1\lib\net35\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -54,6 +55,9 @@
<Name>LoveSeat</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
4 changes: 4 additions & 0 deletions LoveSeat.Repository/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="6.0.1" targetFramework="net35" />
</packages>
10 changes: 6 additions & 4 deletions LoveSeat/CouchClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace LoveSeat
{
using LoveSeat.Interfaces;

// type of authentication used in request to CouchDB
public enum AuthenticationType
{ Basic, Cookie };
Expand Down Expand Up @@ -43,8 +45,8 @@ public CouchClient(string username, string password)
/// <param name="port">The port of the CouchDB instance</param>
/// <param name="username">The username of the CouchDB instance</param>Cou
/// <param name="password">The password of the CouchDB instance</param>
public CouchClient(string host, int port, string username, string password, bool isHttps, AuthenticationType aT)
: base(username, password, aT)
public CouchClient(string host, int port, string username, string password, bool isHttps, AuthenticationType aT, IConfigWebRequest configWebRequest = null)
: base(username, password, aT, configWebRequest)
{
if (isHttps == false)
{
Expand Down Expand Up @@ -119,7 +121,7 @@ public CouchResponseObject DeleteDatabase(string databaseName)
/// <returns></returns>
public CouchDatabase GetDatabase(string databaseName)
{
return new CouchDatabase(baseUri, databaseName, username, password, this.authType);
return new CouchDatabase(baseUri, databaseName, username, password, this.authType, configWebRequest);
}

/// <summary>
Expand Down Expand Up @@ -198,7 +200,7 @@ public bool HasUser(string userId)
/// <returns></returns>
public Document GetUser(string userId)
{
var db = new CouchDatabase(baseUri, "_users", username, password, this.authType);
var db = new CouchDatabase(baseUri, "_users", username, password, this.authType, configWebRequest);
userId = "org.couchdb.user:" + HttpUtility.UrlEncode(userId);
return db.GetDocument(userId);
}
Expand Down
2 changes: 2 additions & 0 deletions LoveSeat/CouchConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace LoveSeat
{
using LoveSeat.Interfaces;

public class CouchConfiguration
{
public CouchConfiguration()
Expand Down
8 changes: 4 additions & 4 deletions LoveSeat/CouchDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class CouchDatabase : CouchBase, IDocumentDatabase

private readonly string databaseBaseUri;
private string defaultDesignDoc = null;
internal CouchDatabase(string baseUri, string databaseName, string username, string password, AuthenticationType aT)
: base(username, password, aT)
internal CouchDatabase(string baseUri, string databaseName, string username, string password, AuthenticationType aT, IConfigWebRequest configWebRequest)
: base(username, password, aT, configWebRequest)
{
this.baseUri = baseUri;
this.databaseBaseUri = baseUri + databaseName;
Expand All @@ -37,7 +37,7 @@ public CouchResponseObject CreateDocument(string id, string jsonForDocument)
if (jobj.Value<object>("_rev") == null)
jobj.Remove("_rev");
var resp = GetRequest(databaseBaseUri + "/" + id)
.Put().Form()
.Put().Json()
.Data(jobj.ToString(Formatting.None))
.GetCouchResponse();
return
Expand Down Expand Up @@ -446,7 +446,7 @@ private CouchRequest GetRequest(ViewOptions options, string uri)
if (options != null)
uri += options.ToString();
CouchRequest request = GetRequest(uri, options == null ? null : options.Etag).Get().Json();
if (options.isAtKeysSizeLimit)
if (options != null && options.isAtKeysSizeLimit)
{
// Encode the keys parameter in the request body and turn it into a POST request.
string keys = "{\"keys\": [" + String.Join(",", options.Keys.Select(k => k.ToRawString()).ToArray()) + "]}";
Expand Down
5 changes: 5 additions & 0 deletions LoveSeat/CouchResponseObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ namespace LoveSeat
/// </summary>
public class CouchResponseObject : JObject
{
public CouchResponseObject()
: base()
{
}

public CouchResponseObject(JObject obj)
: base(obj)
{
Expand Down
14 changes: 14 additions & 0 deletions LoveSeat/Interfaces/IConfigWebRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace LoveSeat.Interfaces
{
using System.Net;

public interface IConfigWebRequest
{
/// <summary>
/// Used to configure the web request created by LoveSeat. For example, to set things like
/// SSL settings.
/// </summary>
/// <param name="webRequest"></param>
void ConfigWebRequest(HttpWebRequest webRequest);
}
}
8 changes: 6 additions & 2 deletions LoveSeat/LoveSeat.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=3.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libraries\Newtonsoft.Json.dll</HintPath>
<HintPath>..\packages\Newtonsoft.Json.6.0.1\lib\net35\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
Expand All @@ -70,6 +70,7 @@
<Compile Include="CouchResponseObject.cs" />
<Compile Include="Document.cs" />
<Compile Include="CouchUser.cs" />
<Compile Include="Interfaces\IConfigWebRequest.cs" />
<Compile Include="Interfaces\IDocumentDatabase.cs" />
<Compile Include="Interfaces\IKeyOptions.cs" />
<Compile Include="Interfaces\IListResult.cs" />
Expand Down Expand Up @@ -119,6 +120,9 @@
<Name>LoveSeat.Interfaces</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
14 changes: 10 additions & 4 deletions LoveSeat/Support/CouchBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@

namespace LoveSeat.Support
{
using LoveSeat.Interfaces;

public abstract class CouchBase
{
protected readonly string username;
protected readonly string password;
protected readonly AuthenticationType authType;

protected readonly IConfigWebRequest configWebRequest;

protected string baseUri;
private TtlDictionary<string, Cookie> cookiestore = new TtlDictionary<string, Cookie>();
private int? timeout;
Expand All @@ -16,11 +21,12 @@ protected CouchBase()
{
throw new Exception("Should not be used.");
}
protected CouchBase(string username, string password, AuthenticationType aT)
protected CouchBase(string username, string password, AuthenticationType aT, IConfigWebRequest configWebRequest = null)
{
this.username = username;
this.password = password;
this.authType = aT;
this.configWebRequest = configWebRequest;
}
public static bool Authenticate(string baseUri, string userName, string password)
{
Expand Down Expand Up @@ -76,15 +82,15 @@ protected CouchRequest GetRequest(string uri, string etag)
CouchRequest request;
if (AuthenticationType.Cookie == this.authType)
{
request = new CouchRequest(uri, GetSession(), etag);
request = new CouchRequest(uri, GetSession(), etag, configWebRequest);
}
else if (AuthenticationType.Basic == this.authType) //Basic Authentication
{
request = new CouchRequest(uri, username, password);
request = new CouchRequest(uri, username, password, configWebRequest);
}
else //default Cookie
{
request = new CouchRequest(uri, GetSession(), etag);
request = new CouchRequest(uri, GetSession(), etag, configWebRequest);
}
if (timeout.HasValue) request.Timeout(timeout.Value);
return request;
Expand Down
15 changes: 13 additions & 2 deletions LoveSeat/Support/CouchRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace LoveSeat.Support
{
using LoveSeat.Interfaces;

/// <summary>
/// Repersent a web request for CouchDB database.
/// </summary>
Expand All @@ -21,13 +23,14 @@ public CouchRequest(string uri)
{
}


/// <summary>
/// Request with Cookie authentication
/// </summary>
/// <param name="uri"></param>
/// <param name="authCookie"></param>
/// <param name="eTag"></param>
public CouchRequest(string uri, Cookie authCookie, string eTag)
public CouchRequest(string uri, Cookie authCookie, string eTag, IConfigWebRequest configWebRequest = null)
{
request = (HttpWebRequest)WebRequest.Create(uri);
request.Headers.Clear(); //important
Expand All @@ -42,6 +45,10 @@ public CouchRequest(string uri, Cookie authCookie, string eTag)
if (authCookie != null)
request.Headers.Add("Cookie", "AuthSession=" + authCookie.Value);
request.Timeout = 10000;
if (configWebRequest != null)
{
configWebRequest.ConfigWebRequest(request);
}
}

/// <summary>
Expand All @@ -50,7 +57,7 @@ public CouchRequest(string uri, Cookie authCookie, string eTag)
/// <param name="uri"></param>
/// <param name="username"></param>
/// <param name="password"></param>
public CouchRequest(string uri, string username, string password)
public CouchRequest(string uri, string username, string password, IConfigWebRequest configWebRequest = null)
{

request = (HttpWebRequest)WebRequest.Create(uri);
Expand All @@ -75,6 +82,10 @@ public CouchRequest(string uri, string username, string password)
request.ContentType = "application/json";
request.KeepAlive = true;
request.Timeout = 10000;
if (configWebRequest != null)
{
configWebRequest.ConfigWebRequest(request);
}
}


Expand Down
2 changes: 1 addition & 1 deletion LoveSeat/Support/CouchResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public CouchResponse(HttpWebResponse response)
/// <returns></returns>
public CouchResponseObject GetJObject()
{
var resp = new CouchResponseObject(JObject.Parse(responseString));
var resp = string.IsNullOrEmpty(responseString) ? new CouchResponseObject() : new CouchResponseObject(JObject.Parse(responseString));
resp.StatusCode = (int)statusCode;
return resp;
}
Expand Down
4 changes: 4 additions & 0 deletions LoveSeat/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="6.0.1" targetFramework="net35" />
</packages>