Example #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
            });
        }
Example #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
     });
 }
Example #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
     });
 }
Example #4
0
 public SDataBatch(ISDataClient client, string path, SDataPayloadOptions options)
 {
     _client  = client;
     _path    = path;
     _options = options ?? new SDataPayloadOptions();
 }
Example #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));
 }
Example #6
0
 public static ISDataBatch <SDataResource> CreateBatch(this ISDataClient client, string path, SDataPayloadOptions options = null)
 {
     return(CreateBatch <SDataResource>(client, path, options));
 }
Example #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));
 }
Example #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);
 }
Example #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));
 }
Example #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));
 }
Example #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));
 }
Example #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);
        }
Example #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));
 }
Example #14
0
 public static SDataResource Get(this ISDataClient client, string key, string path, SDataPayloadOptions options = null)
 {
     return(Get <SDataResource>(client, key, path, options));
 }