diff --git a/.gitignore b/.gitignore index de74d4b..55f73c5 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,7 @@ _ReSharper*/ /LoveSeat.IntegrationTest/test-results *.testsettings -LoveSeat.vsmdi \ No newline at end of file +LoveSeat.vsmdi + +#NuGet +packages/ \ No newline at end of file diff --git a/DreamSeat.IntegrationTest/CouchClientTest.cs b/DreamSeat.IntegrationTest/CouchClientTest.cs index 7801747..7873945 100644 --- a/DreamSeat.IntegrationTest/CouchClientTest.cs +++ b/DreamSeat.IntegrationTest/CouchClientTest.cs @@ -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 @@ -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()).Wait(); + db.CreateDocument(null, "{type:2}", new Result()).Wait(); + + CouchChanges changes = db.GetChanges(new ChangeOptions() + { + Filter = @"showdoc/bytype", + AdditionalParams = new Dictionary() { { "type", "1" } } + }, new Result()).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() { diff --git a/DreamSeat/ChangeOptions.cs b/DreamSeat/ChangeOptions.cs index efdda62..a537127 100644 --- a/DreamSeat/ChangeOptions.cs +++ b/DreamSeat/ChangeOptions.cs @@ -1,4 +1,6 @@ -namespace DreamSeat +using System.Collections.Generic; + +namespace DreamSeat { internal enum ChangeFeed { @@ -45,11 +47,16 @@ public class ChangeOptions /// /// Start the results from the specified sequence number /// - public int? Since { get; set; } + public long? Since { get; set; } /// /// Maximum period to wait before the response is sent /// public int? Timeout { get; set; } + + /// + /// Additional request params + /// + public Dictionary AdditionalParams { get; set; } } } diff --git a/DreamSeat/Constants.cs b/DreamSeat/Constants.cs index a08dff5..7014b6b 100644 --- a/DreamSeat/Constants.cs +++ b/DreamSeat/Constants.cs @@ -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"; diff --git a/DreamSeat/CouchChanges.cs b/DreamSeat/CouchChanges.cs index b69d7e8..94b20ce 100644 --- a/DreamSeat/CouchChanges.cs +++ b/DreamSeat/CouchChanges.cs @@ -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)] diff --git a/DreamSeat/CouchDesignDocument.cs b/DreamSeat/CouchDesignDocument.cs index de8c53d..0a6e28b 100644 --- a/DreamSeat/CouchDesignDocument.cs +++ b/DreamSeat/CouchDesignDocument.cs @@ -9,6 +9,7 @@ public CouchDesignDocument() { Language = Constants.JAVASCRIPT; Views = new Dictionary(); + Filters = new Dictionary(); Shows = new Dictionary(); Lists = new Dictionary(); } @@ -24,6 +25,9 @@ public CouchDesignDocument(string aDesignDocId) [JsonProperty(Constants.VIEWS)] public Dictionary Views { get; internal set; } + [JsonProperty(Constants.FILTERS)] + public Dictionary Filters { get; internal set; } + [JsonProperty(Constants.SHOWS)] public Dictionary Shows { get; private set; } diff --git a/DreamSeat/Support/PlugExtensions.cs b/DreamSeat/Support/PlugExtensions.cs index 835d41d..08cdbed 100644 --- a/DreamSeat/Support/PlugExtensions.cs +++ b/DreamSeat/Support/PlugExtensions.cs @@ -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)); @@ -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; } diff --git a/Samples/ContactManager/ChangesListBox.cs b/Samples/ContactManager/ChangesListBox.cs index 9dd5116..4ad3110 100644 --- a/Samples/ContactManager/ChangesListBox.cs +++ b/Samples/ContactManager/ChangesListBox.cs @@ -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; } } @@ -75,7 +75,7 @@ private int GetSequence() } return seqNumber; } - private void SetSequence(int seq) + private void SetSequence(long seq) { try {