This project has moved. For the latest updates, please go here.

Working with Hammock and AgFx

Aug 22, 2011 at 2:14 PM

Sorry if the question I am asking makes nonsense as I am really new to this. :(

I have a project which is already using Hammock for oAuth (version 1.0) authentication. And then I saw your awesome data caching framework AgFx and I really want to be able to use it within my project.

But the problem I am having is, with Hammock I can easily make a request by using

    var request = new RestRequest
    {
        Credentials = _credentials,
        Path = "/fav.xml",
        Method = WebMethod.Post
    };

where I store access token, consumer key, etc. in the _credentials object. And it does its magic for me so I don't need to convert them into the long oauth signature string.

But with AgFx, my understanding is, I need to use WebLoadRequest to request for the data, which looks like this

return new WebLoadRequest(loadContext, new Uri(myUri), "POST", "post-data");

where "post-data" should be the oauth signature string. Then basically I need to throw away what Hammock gives to me and rewrite the code to get the signature.

I just wonder if there's a better way of doing this?

Any help would be much appreciated!!

Cheers,

Xin

Coordinator
Aug 23, 2011 at 7:05 AM

Hi Xin -

I am not familiar with Hammock so I would need to take a look at that.

One thing to note is that WebLoadRequest derives from the abstract LoadRequest base class.  So you may be able to either derive from WebLoadRequest and fiddle with it or write some kind of a HammockLoadRequest that leverages the RestRequest you reference above.

LoadRequest basically does one thing, which is to return a Stream (asynchronously) from it's Execute method.  How it fetches that stream is up to the LoadRequest - WebLoadRequest is just a common implementation that boils down to HttpWebRequest.

Hope that helps,

 

Shawn

Aug 24, 2011 at 3:23 AM

Hi Shawn,

Thanks so much for your reply and I finally got it all working! What I did was I took your advice and created my own HammockLoadRequest which inherits from LoadRequest and replaced the HttpWebRequest with Hammock's RestRequest in the Execute method.

Just one more question, what is the reason that you convert the response's content to a stream rather than the actual typed object? What's the benefit of doing this?

 

Thanks again for your help!

 

Cheers,
Xin

Coordinator
Aug 24, 2011 at 7:14 AM

Hi -

It's to make it generic for good separation of concerns.  IDataLoader has two functions that are designed to be treated separately:

1) GetLoadRequest tells AgFx how to fetch the resource (e.g. from the web, but could be from disk or from a database)

2) Deserialize is responsible for turning the result of (1) into a typed object.

If it's all done in one step then you can't do automatic caching.  AgFx takes the result of (1) and dumps it on disk.  So you have built in caching - notice that Deserialize has no idea if it's loading from the cache or "live" new data.  So if LoadRequest did both, you wouldn't have that ability.

Make sense?

Shawn

Aug 24, 2011 at 7:57 AM
Edited Aug 24, 2011 at 7:58 AM

All clear now, thanks A LOT!!!

Xin