PDA

View Full Version : Using Dream to Access CouchDB



vdaron
01-21-2011, 09:48 PM
Hi all, I sent this email to Steve directly, without answers, I try on the forum...

I'm currently working on a library to access CouchDB using Dream (I've forked Loveaseat as a startup) [1].
The objective is to use Plug/XUri/Result/... classes to be able to execute asynchronous call on couchdb.

I have 3 questions about Dream :

1) XUri containing ':' character

XUri.cs (1917): // NOTE (steveb): we double-encode ':' and trailing '.' characters, because IIS doesn't like them otherwise

Does it mean that any url containing ':' will be double encoded and therefore will only be able to access a web site behind a reverse proxy ?
IIS seems to allow accessing url with special ':' character (http://mindtouch/User:vdaron) what's the problem ?

In CouchDB, I need to access pages like "http://localhost:5984/_users/org.couchdb.user:MyUser". Is it possible with Dream ?

2) Continuous updates
How can I open a stream on a web page and receive content continuously using Plug ? If I remember well, it seems that you use a mechanism like that to send log4net entries continuously through a web page. Right ?

3) Github
I saw that you have an account on github, did you plan to make dream and mindtouch repositories available on github ?

Kind Regards,

Vincent

[1] https://github.com/vdaron/LoveSeat it's still work in progress, be kind :-)

arnec
01-25-2011, 03:40 PM
1) XUri containing ':' character
I'll look into this and figure out how you can access those Uri's.


2) Continuous updates
How can I open a stream on a web page and receive content continuously using Plug ? If I remember well, it seems that you use a mechanism like that to send log4net entries continuously through a web page. Right ?

Have you tried DreamMessage.ToStream(). That should give you a stream for response without content length that you can continue reading from.


3) Github
I saw that you have an account on github, did you plan to make dream and mindtouch repositories available on github ?


I'm currently cleaning up some additions and the samples for 2.2, which will be the first version to switch to github. Once on github, i'll be creating the Dream 3.0 (http://developer.mindtouch.com/User:arnec/Dream_3.0) branch. All this should happen within the next month.

The Deki repository will likely follow at some future point.

vdaron
01-25-2011, 09:25 PM
Thanks Arnec,

Thanks for all these infos.

DreamMessage.ToStream() does not works. Even the the "WhenDone" Result method is not called.

Here is a sample of code that I want to write using Dream.
Keep in mind that the page is potentially infinite in size. The Stream will never ends.
In this example, the "mustRead" bool is set to false from another thread.



public static void GetStreamLines(string uri, int since, Action<string> callback)
{
var request = (HttpWebRequest)WebRequest.Create(uri);
request.Timeout = int.MaxValue;
mustRead = true;

using (var reader = new StreamReader(request.GetResponse().GetResponseStre am()))
{
while (mustRead)
{
callback.BeginInvoke(reader.ReadLine(), null, null);
}
request.Abort();// Required or reader.Dispose will hang
}
Console.WriteLine("end");
}


Here is the documentation of the call I want to access : http://guide.couchdb.org/draft/notifications.html

Thanks for help

vdaron
01-27-2011, 01:47 PM
By looking at the last official Release of Dream. It seems that the "Dream In development" (http://developer.mindtouch.com/en/docs/Dream/Releases/In_Development) page has maybe what I'm looking for : "http event streams"

Could you give me more info about these "http even stream" ?

The last dream svn log message seems to announce a new release of dream called Hudson ? right ? when :-) ?


r26317@domU-12-31-39-0E-CD-C5 (orig r24696): arnec | 2011-01-20 14:56:03 -0500
dream (trunk):
* some test fixes to prep Dream for Hudson

Thanks

arnec
01-27-2011, 07:10 PM
That "in development" page should probably deleted as it has no relation to what we are doing at this point.

I've create http://youtrack.developer.mindtouch.com/issue/MT-9578 for the double encoding issue and hope to get it in for the trunk push/2.2 release on github.

The log message about Hudson refers to your continuous integration environment. We are trying to get unit test runs for Dream to be part of the build, but had some tests that would fail in the Hudson environment

Regarding the issue with ToStream(), try using InvokeEx() instead of Get(). We memorize (i.e. read the entire stream) on first access by default. Only InvokeEx() let's you control the network stream directly.

vdaron
01-31-2011, 08:59 AM
InvokeEx works perfectly

Thanks

arnec
01-31-2011, 07:22 PM
Vincent,

Just committed http://youtrack.developer.mindtouch.com/issue/MT-9578 to trunk. It adds WithSegmentDoubleEncoding() and WithoutSegmentDoubleEncoding() to XUri and Plug.

I hope to push Dream to github tonight and officially branch trunk as 2.2.0

vdaron
01-31-2011, 08:47 PM
I still have a problem with InvokeEx...

It seems that you surround the NetworkStream with a BufferedStream.

The BeginRead call block even if some data has been received (waiting for buffer to be filled in ?).

As a quick workaround, I'm using a buffer of 1 byte. It works.. but ...

Is it possible to not wrap the Stream in a BufferedStream when calling InvoicEx ? Any other tips ?

Thanks

vdaron
01-31-2011, 08:58 PM
I've filled a bug : MT-9598 (http://youtrack.developer.mindtouch.com/issue/MT-9598)