Permalink
Browse files

Replaced some CouchDatabase and CouchServer references with their int…

…erface counterparts.
  • Loading branch information...
1 parent 87f011d commit e72d69b73900f24a7726134acb623d6696b338c0 Sebastian Negomireanu committed Dec 10, 2009
@@ -63,7 +63,7 @@ public override void ReadJson(JObject obj)
HorsePowers = obj["Hps"].Value<int>();
}
- public override IReconcilingDocument GetDatabaseCopy(CouchDatabase db)
+ public override IReconcilingDocument GetDatabaseCopy(ICouchDatabase db)
{
return db.GetDocument<Car>(Id);
}
View
@@ -25,13 +25,13 @@ public CouchDatabase()
Name = "default";
}
- public CouchDatabase(CouchServer server)
+ public CouchDatabase(ICouchServer server)
: this()
{
Server = server;
}
- public CouchDatabase(string name, CouchServer server)
+ public CouchDatabase(string name, ICouchServer server)
{
Name = name;
Server = server;
@@ -51,7 +51,7 @@ public string Name
}
}
- public CouchServer Server { get; set; }
+ public ICouchServer Server { get; set; }
public bool RunningOnMono()
{
View
@@ -198,7 +198,7 @@ public virtual void Reconcile(ICouchDocument databaseCopy)
Rev = databaseCopy.Rev;
}
- public virtual IReconcilingDocument GetDatabaseCopy(CouchDatabase db)
+ public virtual IReconcilingDocument GetDatabaseCopy(ICouchDatabase db)
{
return db.GetDocument<CouchDocument>(Id);
}
View
@@ -17,9 +17,9 @@ namespace Divan
public class CouchRequest
{
private const int UploadBufferSize = 100000;
- private readonly CouchDatabase db;
+ private readonly ICouchDatabase db;
private Stream postStream;
- private readonly CouchServer server;
+ private readonly ICouchServer server;
private string etag, etagToCheck;
public Dictionary<string, string> headers = new Dictionary<string, string>();
@@ -31,12 +31,12 @@ public class CouchRequest
public JToken result;
- public CouchRequest(CouchServer server)
+ public CouchRequest(ICouchServer server)
{
this.server = server;
}
- public CouchRequest(CouchDatabase db)
+ public CouchRequest(ICouchDatabase db)
{
server = db.Server;
this.db = db;
View
@@ -17,30 +17,79 @@ namespace Divan
/// </summary>
public class CouchServer : Divan.ICouchServer
{
- public bool RunningOnMono = Type.GetType("Mono.Runtime") != null;
+ private bool runningOnMono = Type.GetType("Mono.Runtime") != null;
private const string DefaultHost = "localhost";
private const int DefaultPort = 5984;
private readonly JsonSerializer serializer = new JsonSerializer();
- public readonly string Host;
- public readonly int Port;
+ private readonly string host;
+ private readonly int port;
- public readonly string UserName;
- public readonly string Password;
- public readonly string EncodedCredentials;
+ private readonly string userName;
+ private readonly string password;
+ private readonly string encodedCredentials;
- public string DatabasePrefix = ""; // Used by databases to prefix their names
+ private string databasePrefix = ""; // Used by databases to prefix their names
+ public string EncodedCredentials
+ {
+ get
+ {
+ return encodedCredentials;
+ }
+ }
+ public string Password
+ {
+ get
+ {
+ return password;
+ }
+ }
+ public string UserName
+ {
+ get
+ {
+ return userName;
+ }
+ }
+ public int Port
+ {
+ get
+ {
+ return port;
+ }
+ }
+ public string Host
+ {
+ get
+ {
+ return host;
+ }
+ }
+
+ public bool RunningOnMono
+ {
+ get
+ {
+ return runningOnMono;
+ }
+ }
+
+ public string DatabasePrefix
+ {
+ get { return databasePrefix; }
+ set { databasePrefix = value; }
+ }
public CouchServer(string host, int port, string user, string pass)
{
- Host = host;
- Port = port;
- UserName = user;
- Password = pass;
+ this.host = host;
+ this.port = port;
+ this.userName = user;
+ this.password = pass;
if (!String.IsNullOrEmpty(UserName))
- EncodedCredentials = "Basic " +
+ encodedCredentials = "Basic " +
Convert.ToBase64String(Encoding.ASCII.GetBytes(UserName + ":" + Password));
Debug(string.Format("CouchServer({0}:{1})", host, port));
View
@@ -62,7 +62,7 @@ public interface ICouchDatabase
void SaveDocuments(System.Collections.Generic.IEnumerable<ICouchDocument> documents, int chunkCount, IEnumerable<ICouchViewDefinition> views, bool allOrNothing);
void SaveDocuments(System.Collections.Generic.IEnumerable<ICouchDocument> documents, bool allOrNothing);
void SaveDocuments(System.Collections.Generic.IEnumerable<ICouchDocument> documents, int chunkCount, bool allOrNothing);
- CouchServer Server { get; set; }
+ ICouchServer Server { get; set; }
void SynchDesignDocuments();
void TouchView(string designDocumentId, string viewName);
void TouchViews(IEnumerable<ICouchViewDefinition> views);
View
@@ -19,5 +19,12 @@ public interface ICouchServer
bool HasDatabase(string name);
CouchRequest Request();
string ServerName { get; }
+ string DatabasePrefix { get; set; }
+ bool RunningOnMono { get; }
+ string Host { get; }
+ int Port { get; }
+ string UserName { get; }
+ string Password { get; }
+ string EncodedCredentials { get; }
}
}
@@ -12,6 +12,6 @@ public interface IReconcilingDocument: ICouchDocument
/// <param name="databaseCopy"></param>
void Reconcile(ICouchDocument databaseCopy);
- IReconcilingDocument GetDatabaseCopy(CouchDatabase db);
+ IReconcilingDocument GetDatabaseCopy(ICouchDatabase db);
}
}

0 comments on commit e72d69b

Please sign in to comment.