Skip to content
This repository was archived by the owner on Jul 13, 2020. It is now read-only.
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ _ReSharper*/

/LoveSeat.IntegrationTest/test-results
*.testsettings
LoveSeat.vsmdi
LoveSeat.vsmdi

#NuGet
packages/
26 changes: 25 additions & 1 deletion DreamSeat.IntegrationTest/CouchClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class TestSubClass : CouchDocument
private static CouchClient client;
private const string baseDatabase = "dream-seat-test-base";
private const string replicateDatabase = "dream-seat-test-repli";
private const string couchdbHostName = "192.168.56.1";
private const string couchdbHostName = "localhost";

[TestFixtureSetUp]
#if NUNIT
Expand Down Expand Up @@ -461,6 +461,30 @@ public void GetChanges()
Assert.IsNotNull(changes.Results[0].Id);
Assert.IsNotNull(changes.Results[0].Sequence);
}
[Test]
public void GetChangesByType()
{
if (client.HasDatabase("test_changes"))
client.DeleteDatabase("test_changes");

var db = client.GetDatabase("test_changes");
CouchDesignDocument doc = new CouchDesignDocument("showdoc");
doc.Filters.Add("bytype", "function(doc, req) { if(doc.type == req.query.type) { return true; } else { return false; }}");
db.CreateDocument(doc);

db.CreateDocument(null, "{type:1}", new Result<string>()).Wait();
db.CreateDocument(null, "{type:2}", new Result<string>()).Wait();

CouchChanges changes = db.GetChanges(new ChangeOptions()
{
Filter = @"showdoc/bytype",
AdditionalParams = new Dictionary<string, string>() { { "type", "1" } }
}, new Result<CouchChanges>()).Wait();
Assert.AreEqual(1, changes.Results.Length);
Assert.IsNotNull(changes.Results[0].Changes);
Assert.IsNotNull(changes.Results[0].Id);
Assert.IsNotNull(changes.Results[0].Sequence);
}
[Test]
public void GetContinuousChanges()
{
Expand Down
11 changes: 9 additions & 2 deletions DreamSeat/ChangeOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace DreamSeat
using System.Collections.Generic;

namespace DreamSeat
{
internal enum ChangeFeed
{
Expand Down Expand Up @@ -45,11 +47,16 @@ public class ChangeOptions
/// <summary>
/// Start the results from the specified sequence number
/// </summary>
public int? Since { get; set; }
public long? Since { get; set; }

/// <summary>
/// Maximum period to wait before the response is sent
/// </summary>
public int? Timeout { get; set; }

/// <summary>
/// Additional request params
/// </summary>
public Dictionary<string, string> AdditionalParams { get; set; }
}
}
1 change: 1 addition & 0 deletions DreamSeat/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Constants
public const string JAVASCRIPT = "javascript";
public const string LANGUAGE = "language";
public const string VIEWS = "views";
public const string FILTERS = "filters";
public const string SHOWS = "shows";
public const string LISTS = "lists";
public const string VALIDATE_DOC_UPDATE = "validate_doc_update";
Expand Down
2 changes: 1 addition & 1 deletion DreamSeat/CouchChanges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class CouchChangeResult
[JsonProperty(Constants.ID)]
public string Id { get; protected set; }
[JsonProperty(Constants.SEQUENCE)]
public int Sequence { get; protected set; }
public long Sequence { get; protected set; }
[JsonProperty(Constants.CHANGES)]
public JObject[] Changes { get; protected set; }
[JsonProperty(Constants.DELETED)]
Expand Down
4 changes: 4 additions & 0 deletions DreamSeat/CouchDesignDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public CouchDesignDocument()
{
Language = Constants.JAVASCRIPT;
Views = new Dictionary<string, CouchView>();
Filters = new Dictionary<string, string>();
Shows = new Dictionary<string, string>();
Lists = new Dictionary<string, string>();
}
Expand All @@ -24,6 +25,9 @@ public CouchDesignDocument(string aDesignDocId)
[JsonProperty(Constants.VIEWS)]
public Dictionary<string, CouchView> Views { get; internal set; }

[JsonProperty(Constants.FILTERS)]
public Dictionary<string, string> Filters { get; internal set; }

[JsonProperty(Constants.SHOWS)]
public Dictionary<string,string> Shows { get; private set; }

Expand Down
9 changes: 8 additions & 1 deletion DreamSeat/Support/PlugExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static Plug With(this Plug aPlug, ChangeOptions aChangeOptions)

if (!String.IsNullOrEmpty(aChangeOptions.Filter))
{
aPlug = aPlug.With(Constants.FILTER, XUri.Encode(aChangeOptions.Filter));
aPlug = aPlug.With(Constants.FILTER, aChangeOptions.Filter);
}
if (!String.IsNullOrEmpty (aChangeOptions.View)) {
aPlug = aPlug.With(Constants.FILTER, XUri.Encode (Constants.VIEW));
Expand All @@ -98,6 +98,13 @@ public static Plug With(this Plug aPlug, ChangeOptions aChangeOptions)
{
aPlug = aPlug.With(Constants.TIMEOUT, aChangeOptions.Timeout.Value);
}
if (aChangeOptions.AdditionalParams != null)
{
foreach (var pair in aChangeOptions.AdditionalParams)
{
aPlug = aPlug.With(pair.Key, pair.Value);
}
}

return aPlug;
}
Expand Down
8 changes: 4 additions & 4 deletions Samples/ContactManager/ChangesListBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ private static void ChangesListBoxFormat(object sender, ListControlConvertEventA
}
}

private int GetSequence()
private long GetSequence()
{
int seqNumber = 1;
long seqNumber = 1;
try
{
if (File.Exists("sequence.txt"))
{
seqNumber = Int32.Parse(File.ReadAllText("sequence.txt"));
seqNumber = long.Parse(File.ReadAllText("sequence.txt"));
return seqNumber;
}
}
Expand All @@ -75,7 +75,7 @@ private int GetSequence()
}
return seqNumber;
}
private void SetSequence(int seq)
private void SetSequence(long seq)
{
try
{
Expand Down