Skip to content

Commit

Permalink
NCBC-399: Standardize to SPACES for indenting in source files
Browse files Browse the repository at this point in the history
Replaced all tabs \t with four spaces per the VS standard

Change-Id: I8049ff3e2d3c7da33c6209c9183c0836afa95e67
Reviewed-on: http://review.couchbase.org/34397
Reviewed-by: Brett Lawson <brett19@gmail.com>
Tested-by: Jeffry Morris <jeffrymorris@gmail.com>
  • Loading branch information
jeffrymorris committed Mar 19, 2014
1 parent d233a5e commit 6003c26
Show file tree
Hide file tree
Showing 357 changed files with 25,209 additions and 24,372 deletions.
10 changes: 4 additions & 6 deletions src/Couchbase.HttpClients.Net35/Properties/AssemblyInfo.cs
Expand Up @@ -2,17 +2,15 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyCompany("Couchbase, Inc.")]
[assembly: AssemblyProduct("Couchbase .NET Client Library Http Clients")]
[assembly: AssemblyCopyright("Copyright 2013 Couchbase, Inc.")]

[assembly: AssemblyConfiguration("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: ComVisible(true)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
Expand All @@ -21,12 +19,12 @@
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
296 changes: 148 additions & 148 deletions src/Couchbase.HttpClients/HammockHttpClient.cs
Expand Up @@ -9,162 +9,162 @@

namespace Couchbase.HttpClients
{
/// <summary>
/// Default implementation of the <see cref="IHttpClient"/> using the Hammock REST library.
/// </summary>
internal class HammockHttpClient : IHttpClient
{
private static readonly Enyim.Caching.ILog log = Enyim.Caching.LogManager.GetLogger(typeof(HammockHttpClient));
/// <summary>
/// Default implementation of the <see cref="IHttpClient"/> using the Hammock REST library.
/// </summary>
internal class HammockHttpClient : IHttpClient
{
private static readonly Enyim.Caching.ILog log = Enyim.Caching.LogManager.GetLogger(typeof(HammockHttpClient));

private RestClient client;
private RestClient client;

public HammockHttpClient(Uri baseUri, string username, string password, TimeSpan timeout, bool shouldInitConnection)
{
this.client = new RestClient { Authority = baseUri.ToString() };
public HammockHttpClient(Uri baseUri, string username, string password, TimeSpan timeout, bool shouldInitConnection)
{
this.client = new RestClient { Authority = baseUri.ToString() };

client.AddHeader("Accept", "application/json");
client.AddHeader("Content-Type", "application/json; charset=utf-8");
client.AddHeader("Accept", "application/json");
client.AddHeader("Content-Type", "application/json; charset=utf-8");

client.ServicePoint = System.Net.ServicePointManager.FindServicePoint(baseUri);
client.ServicePoint = System.Net.ServicePointManager.FindServicePoint(baseUri);
#if ! MONO
client.ServicePoint.SetTcpKeepAlive(true, 300, 30);
client.ServicePoint.SetTcpKeepAlive(true, 300, 30);
#endif
if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
{
var credentials = username + ":" + password;
var base64Credentials = Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials));
client.AddHeader("Authorization", "Basic " + base64Credentials);
}

client.Timeout = timeout;
client.RetryPolicy = new RetryPolicy
{
RetryConditions =
{
new Hammock.Retries.NetworkError(),
new Hammock.Retries.Timeout(),
new Hammock.Retries.ConnectionClosed()
},
RetryCount = 3
};

client.BeforeRetry += new EventHandler<RetryEventArgs>(client_BeforeRetry);

//The first time a request is made to a URI, the ServicePointManager
//will create a ServicePoint to manage connections to a particular host
//This process is expensive and slows down the first created view.
//The call to BeginRequest is basically an async, no-op HTTP request to
//initialize the ServicePoint before the first view request is made.
if (shouldInitConnection) client.BeginRequest();
}

void client_BeforeRetry(object sender, RetryEventArgs e)
{
if (log.IsWarnEnabled)
log.Warn("Retrying " + e.Request.Path);
}

IHttpRequest IHttpClient.CreateRequest(string path)
{
return new HammockRequestWrapper(this.client, path);
}

int IHttpClient.RetryCount
{
get { return this.client.RetryPolicy.RetryCount; }
set { this.client.RetryPolicy.RetryCount = value; }
}

#region [ HammockRequestWrapper ]

private class HammockRequestWrapper : IHttpRequest
{
private RestRequest request;
private RestClient client;
private HttpMethod method;

public HammockRequestWrapper(RestClient client, string path)
{
this.client = client;
this.method = HttpMethod.Get;
this.request = new RestRequest { Path = path };
}

void IHttpRequest.AddParameter(string name, string value)
{
this.request.AddParameter(name, value);
}

IHttpResponse IHttpRequest.GetResponse()
{
switch (this.method)
{
case HttpMethod.Delete: this.request.Method = Hammock.Web.WebMethod.Delete; break;
case HttpMethod.Get: this.request.Method = Hammock.Web.WebMethod.Get; break;
case HttpMethod.Head: this.request.Method = Hammock.Web.WebMethod.Head; break;
case HttpMethod.Options: this.request.Method = Hammock.Web.WebMethod.Options; break;
case HttpMethod.Post: this.request.Method = Hammock.Web.WebMethod.Post; break;
case HttpMethod.Put: this.request.Method = Hammock.Web.WebMethod.Put; break;
default: throw new ArgumentOutOfRangeException("method: " + this.method);
}

var r = new HammockResponseWrapper(request);
r.ExecuteWith(this.client);

return r;
}

HttpMethod IHttpRequest.Method
{
get { return this.method; }
set { this.method = value; }
}
}

#endregion
#region [ HammockResponseWrapper ]

private class HammockResponseWrapper : IHttpResponse
{
private RestRequest request;
private RestResponse response;

public HammockResponseWrapper(RestRequest request)
{
this.request = request;
}

public void ExecuteWith(RestClient client)
{
this.response = client.Request(this.request);
StatusCode = response.StatusCode;
if (response.InnerException != null) throw response.InnerException;
if (response.StatusCode != System.Net.HttpStatusCode.OK)
throw new InvalidOperationException(String.Format("Server returned {0}: {1}, {2}", response.StatusCode, response.StatusDescription, response.Content));
}

Stream IHttpResponse.GetResponseStream()
{
return this.response.ContentStream;
}
if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
{
var credentials = username + ":" + password;
var base64Credentials = Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials));
client.AddHeader("Authorization", "Basic " + base64Credentials);
}

client.Timeout = timeout;
client.RetryPolicy = new RetryPolicy
{
RetryConditions =
{
new Hammock.Retries.NetworkError(),
new Hammock.Retries.Timeout(),
new Hammock.Retries.ConnectionClosed()
},
RetryCount = 3
};

client.BeforeRetry += new EventHandler<RetryEventArgs>(client_BeforeRetry);

//The first time a request is made to a URI, the ServicePointManager
//will create a ServicePoint to manage connections to a particular host
//This process is expensive and slows down the first created view.
//The call to BeginRequest is basically an async, no-op HTTP request to
//initialize the ServicePoint before the first view request is made.
if (shouldInitConnection) client.BeginRequest();
}

private void client_BeforeRetry(object sender, RetryEventArgs e)
{
if (log.IsWarnEnabled)
log.Warn("Retrying " + e.Request.Path);
}

IHttpRequest IHttpClient.CreateRequest(string path)
{
return new HammockRequestWrapper(this.client, path);
}

int IHttpClient.RetryCount
{
get { return this.client.RetryPolicy.RetryCount; }
set { this.client.RetryPolicy.RetryCount = value; }
}

#region [ HammockRequestWrapper ]

private class HammockRequestWrapper : IHttpRequest
{
private RestRequest request;
private RestClient client;
private HttpMethod method;

public HammockRequestWrapper(RestClient client, string path)
{
this.client = client;
this.method = HttpMethod.Get;
this.request = new RestRequest { Path = path };
}

void IHttpRequest.AddParameter(string name, string value)
{
this.request.AddParameter(name, value);
}

IHttpResponse IHttpRequest.GetResponse()
{
switch (this.method)
{
case HttpMethod.Delete: this.request.Method = Hammock.Web.WebMethod.Delete; break;
case HttpMethod.Get: this.request.Method = Hammock.Web.WebMethod.Get; break;
case HttpMethod.Head: this.request.Method = Hammock.Web.WebMethod.Head; break;
case HttpMethod.Options: this.request.Method = Hammock.Web.WebMethod.Options; break;
case HttpMethod.Post: this.request.Method = Hammock.Web.WebMethod.Post; break;
case HttpMethod.Put: this.request.Method = Hammock.Web.WebMethod.Put; break;
default: throw new ArgumentOutOfRangeException("method: " + this.method);
}

var r = new HammockResponseWrapper(request);
r.ExecuteWith(this.client);

return r;
}

HttpMethod IHttpRequest.Method
{
get { return this.method; }
set { this.method = value; }
}
}

#endregion

#region [ HammockResponseWrapper ]

private class HammockResponseWrapper : IHttpResponse
{
private RestRequest request;
private RestResponse response;

public HammockResponseWrapper(RestRequest request)
{
this.request = request;
}

public void ExecuteWith(RestClient client)
{
this.response = client.Request(this.request);
StatusCode = response.StatusCode;
if (response.InnerException != null) throw response.InnerException;
if (response.StatusCode != System.Net.HttpStatusCode.OK)
throw new InvalidOperationException(String.Format("Server returned {0}: {1}, {2}", response.StatusCode, response.StatusDescription, response.Content));
}

Stream IHttpResponse.GetResponseStream()
{
return this.response.ContentStream;
}

public HttpStatusCode StatusCode { get; private set; }
}

#endregion
}

/// <summary>
/// Creates instances of the Hammock implementation of <see cref="IHttpClient"/>.
/// </summary>
public class HammockHttpClientFactory : IHttpClientFactory
{
public static readonly IHttpClientFactory Instance = new HammockHttpClientFactory();

IHttpClient IHttpClientFactory.Create(Uri baseUri, string username, string password, TimeSpan timeout, bool shouldInitializeConnection)
{
return new HammockHttpClient(baseUri, username, password, timeout, shouldInitializeConnection);
}
}
}
#endregion
}

/// <summary>
/// Creates instances of the Hammock implementation of <see cref="IHttpClient"/>.
/// </summary>
public class HammockHttpClientFactory : IHttpClientFactory
{
public static readonly IHttpClientFactory Instance = new HammockHttpClientFactory();

IHttpClient IHttpClientFactory.Create(Uri baseUri, string username, string password, TimeSpan timeout, bool shouldInitializeConnection)
{
return new HammockHttpClient(baseUri, username, password, timeout, shouldInitializeConnection);
}
}
}
11 changes: 5 additions & 6 deletions src/Couchbase.HttpClients/Properties/AssemblyInfo.cs
Expand Up @@ -5,13 +5,12 @@
[assembly: AssemblyCompany("Couchbase, Inc.")]
[assembly: AssemblyProduct("Couchbase .NET Client Library Http Clients")]
[assembly: AssemblyCopyright("Copyright 2013 Couchbase, Inc.")]

[assembly: AssemblyConfiguration("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(true)]

Expand All @@ -21,12 +20,12 @@
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

0 comments on commit 6003c26

Please sign in to comment.