Ejemplo n.º 1
0
        public static Task <IEnumerable <T> > EnumerateAsync <T>(this ISDataClient client, string path = null, SDataEnumerateOptions options = null, CancellationToken cancel = default(CancellationToken))
        {
            var parms = GetEnumerateParameters(client, GetPath <T>(path), options);
            var items = new List <T>();
            Func <Task <ISDataResults <SDataCollection <T> > > > loop = null;

            loop =
                () => client.ExecuteAsync <SDataCollection <T> >(parms, cancel)
                .ContinueWith(
                    task =>
            {
                var collection = task.Result.Content;
                if (collection.Count == 0)
                {
                    return(task);
                }

                items.AddRange(collection);
                parms.StartIndex = (parms.StartIndex ?? 1) + collection.Count;
                if (collection.TotalResults != null && parms.StartIndex > collection.TotalResults)
                {
                    return(task);
                }

                return(loop());
            }, cancel)
                .Unwrap();
            return(loop().ContinueWith(task => (IEnumerable <T>)items, cancel));
        }
Ejemplo n.º 2
0
 public static Task <T> CallServiceAsync <T>(this ISDataClient client, Expression <Func <T> > methodCall, string path = null, CancellationToken cancel = default(CancellationToken))
 {
     return(client.ExecuteAsync <SDataResource>(GetServiceParameters(client, methodCall.Body, path), cancel)
            .ContinueWith(task => GetServiceResult <T>(client, methodCall.Body, task.Result.Content), cancel));
 }
Ejemplo n.º 3
0
 public static Task CallServiceAsync(this ISDataClient client, Expression <Action> methodCall, string path = null, CancellationToken cancel = default(CancellationToken))
 {
     return(client.ExecuteAsync(GetServiceParameters(client, methodCall.Body, path), cancel));
 }
Ejemplo n.º 4
0
 public static Task DeleteAsync <T>(this ISDataClient client, T content, string path = null, CancellationToken cancel = default(CancellationToken))
 {
     return(client.ExecuteAsync(GetDeleteParameters(client, content, GetPath <T>(path)), cancel));
 }
Ejemplo n.º 5
0
 public static Task <T> PutAsync <T>(this ISDataClient client, T content, string path = null, SDataPayloadOptions options = null, CancellationToken cancel = default(CancellationToken))
 {
     return(client.ExecuteAsync <T>(GetPutParameters(client, content, GetPath <T>(path), options), cancel)
            .ContinueWith(task => task.Result.Content, cancel));
 }
Ejemplo n.º 6
0
 public static Task <T> GetAsync <T>(this ISDataClient client, T content, string path = null, SDataPayloadOptions options = null, CancellationToken cancel = default(CancellationToken))
 {
     Guard.ArgumentNotNull(content, "content");
     return(client.ExecuteAsync <T>(GetGetParameters(client, GetKey(content), GetETag(content), GetPath <T>(path), options), cancel)
            .ContinueWith(task => !Equals(task.Result.Content, default(T)) ? task.Result.Content : content, cancel));
 }