From 6bc37e1afd3305ef43d9c0f6e17a8e7ce52ca94a Mon Sep 17 00:00:00 2001 From: Alexei Zubanov Date: Fri, 28 Jun 2013 09:50:38 +0400 Subject: [PATCH 1/3] fix and expand getChanges functionality by proper filter support --- DreamSeat.IntegrationTest/CouchClientTest.cs | 26 +++++++++++++++++++- DreamSeat/ChangeOptions.cs | 9 ++++++- DreamSeat/Constants.cs | 1 + DreamSeat/CouchDesignDocument.cs | 4 +++ DreamSeat/Support/PlugExtensions.cs | 9 ++++++- 5 files changed, 46 insertions(+), 3 deletions(-) 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..e9ccf60 100644 --- a/DreamSeat/ChangeOptions.cs +++ b/DreamSeat/ChangeOptions.cs @@ -1,4 +1,6 @@ -namespace DreamSeat +using System.Collections.Generic; + +namespace DreamSeat { internal enum ChangeFeed { @@ -51,5 +53,10 @@ public class ChangeOptions /// 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/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; } From d8c2f5f013ee2b1b3608a27c0334a99f759a84cc Mon Sep 17 00:00:00 2001 From: Alexei Zubanov Date: Mon, 1 Jul 2013 18:21:07 +0400 Subject: [PATCH 2/3] ignore NuGet packeges libs in pending changes list --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 From 14f122888df0afba5ce4a71c8a72d0fb9a64e88a Mon Sep 17 00:00:00 2001 From: Alexei Zubanov Date: Wed, 3 Jul 2013 12:37:19 +0400 Subject: [PATCH 3/3] change sequence type from int to long --- DreamSeat/ChangeOptions.cs | 2 +- DreamSeat/CouchChanges.cs | 2 +- Samples/ContactManager/ChangesListBox.cs | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/DreamSeat/ChangeOptions.cs b/DreamSeat/ChangeOptions.cs index e9ccf60..a537127 100644 --- a/DreamSeat/ChangeOptions.cs +++ b/DreamSeat/ChangeOptions.cs @@ -47,7 +47,7 @@ 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 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/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 {