Ejemplo n.º 1
0
        private static SDataParameters GetPostParameters <T>(ISDataClient client, T content, string path, SDataPayloadOptions options)
        {
            Guard.ArgumentNotNull(client, "client");
            Guard.ArgumentNotNull(content, "content");
            Guard.ArgumentNotNullOrEmptyString(path, "path");
            if (options == null)
            {
                options = new SDataPayloadOptions();
            }

            var resource = ContentHelper.Serialize(content, client.NamingScheme) as SDataResource;

            if (resource == null)
            {
                throw new SDataClientException("Only resources can be posted");
            }
            resource.HttpMethod = HttpMethod.Post;

            return(new SDataParameters
            {
                Method = HttpMethod.Post,
                Path = path,
                Content = resource,
                Include = options.Include,
                Select = options.Select,
                Precedence = options.Precedence
            });
        }
Ejemplo n.º 2
0
 private static SDataParameters GetGetParameters(ISDataClient client, string key, string etag, string path, SDataPayloadOptions options)
 {
     Guard.ArgumentNotNull(client, "client");
     Guard.ArgumentNotNullOrEmptyString(key, "key");
     Guard.ArgumentNotNullOrEmptyString(path, "path");
     if (options == null)
     {
         options = new SDataPayloadOptions();
     }
     return(new SDataParameters
     {
         Path = string.Format("{0}({1})", path, SDataUri.FormatConstant(key)),
         ETag = etag,
         Include = options.Include,
         Select = options.Select,
         Precedence = options.Precedence
     });
 }
Ejemplo n.º 3
0
 private static SDataParameters GetPutParameters <T>(ISDataClient client, T content, string path, SDataPayloadOptions options)
 {
     Guard.ArgumentNotNull(client, "client");
     Guard.ArgumentNotNull(content, "content");
     Guard.ArgumentNotNullOrEmptyString(path, "path");
     if (options == null)
     {
         options = new SDataPayloadOptions();
     }
     return(new SDataParameters
     {
         Method = HttpMethod.Put,
         Path = string.Format("{0}({1})", path, SDataUri.FormatConstant(GetKey(content))),
         Content = content,
         ETag = GetETag(content),
         Include = options.Include,
         Select = options.Select,
         Precedence = options.Precedence
     });
 }
Ejemplo n.º 4
0
 public SDataBatch(ISDataClient client, string path, SDataPayloadOptions options)
 {
     _client  = client;
     _path    = path;
     _options = options ?? new SDataPayloadOptions();
 }
Ejemplo n.º 5
0
 public static ISDataBatch <T> CreateBatch <T>(this ISDataClient client, string path = null, SDataPayloadOptions options = null)
 {
     Guard.ArgumentNotNull(client, "client");
     return(new SDataBatch <T>(client, GetPath <T>(path), options));
 }
Ejemplo n.º 6
0
 public static ISDataBatch <SDataResource> CreateBatch(this ISDataClient client, string path, SDataPayloadOptions options = null)
 {
     return(CreateBatch <SDataResource>(client, path, options));
 }
Ejemplo n.º 7
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.º 8
0
 public static T Put <T>(this ISDataClient client, T content, string path = null, SDataPayloadOptions options = null)
 {
     return(client.Execute <T>(GetPutParameters(client, content, GetPath <T>(path), options)).Content);
 }
Ejemplo n.º 9
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));
 }
Ejemplo n.º 10
0
 public static Task <T> GetAsync <T>(this ISDataClient client, string key, string path, T prototype, SDataPayloadOptions options = null, CancellationToken cancel = default(CancellationToken))
 {
     return(GetAsync <T>(client, key, path, options, cancel));
 }
Ejemplo n.º 11
0
 public static Task <SDataResource> GetAsync(this ISDataClient client, string key, string path = null, SDataPayloadOptions options = null, CancellationToken cancel = default(CancellationToken))
 {
     return(GetAsync <SDataResource>(client, key, path, options, cancel));
 }
Ejemplo n.º 12
0
        public static T Get <T>(this ISDataClient client, T content, string path = null, SDataPayloadOptions options = null)
        {
            Guard.ArgumentNotNull(content, "content");
            var results = client.Execute <T>(GetGetParameters(client, GetKey(content), GetETag(content), GetPath <T>(path), options));

            return(!Equals(results.Content, default(T)) ? results.Content : content);
        }
Ejemplo n.º 13
0
 public static T Get <T>(this ISDataClient client, string key, string path, T prototype, SDataPayloadOptions options = null)
 {
     return(Get <T>(client, key, path, options));
 }
Ejemplo n.º 14
0
 public static SDataResource Get(this ISDataClient client, string key, string path, SDataPayloadOptions options = null)
 {
     return(Get <SDataResource>(client, key, path, options));
 }