Sergey A
unread,Jun 3, 2011, 1:39:35 PM6/3/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message as abuse
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to RestSharp
Maybe this is not a right place to submit these, but please forgive me
- I'm new to open source ;) With these you can do sync calls in SL
like
response = Client.ExecuteAsync(request).First();
...............................................................
public static class ObservableEx
{
public static IObservable<TResult> FromCallbackPattern<T,
TResult>(T param, Action<T, Action<TResult>> asyncCall)
{
return Observable
.Create<TResult>(observer =>
{
var subscribed = true;
asyncCall(param, value =>
{
if (!subscribed) return;
observer.OnNext(value);
observer.OnCompleted();
});
return () =>
{
subscribed = false;
};
});
}
public static IObservable<string> ExecuteAsync(this RestClient
client, RestRequest request)
{
Action<RestRequest, Action<RestResponse>> callback = (r,
a) => client.ExecuteAsync(r, a);
return FromCallbackPattern(request, callback).Select(x =>
x.Content);
}
public static IObservable<T> ExecuteAsync<T>(this RestClient
client, RestRequest request) where T : new()
{
Action<RestRequest, Action<RestResponse<T>>> callback =
(r, a) => client.ExecuteAsync(r, a);
return FromCallbackPattern(request, callback).Select(x =>
x.Data);
}
}