public async Task <KvMetadata> AddAsync <T>(T item)
        {
            Guard.ArgumentNotNull("item", item);

            HttpUrlBuilder uri = new HttpUrlBuilder(host)
                                 .AppendPath(CollectionName);

            var response = await restClient.SendAsync(uri, HttpMethod.Post, item);

            return(KvMetadata.Make(CollectionName, response));
        }
        public async Task <KvMetadata> TryAddAsync <T>(string key,
                                                       T item)
        {
            Guard.ArgumentNotNullOrEmpty("key", key);
            Guard.ArgumentNotNull("item", item);

            HttpUrlBuilder uri = new HttpUrlBuilder(host)
                                 .AppendPath(CollectionName)
                                 .AppendPath(key);

            var response = await restClient.SendIfNoneMatchAsync(uri, HttpMethod.Put, item);

            return(KvMetadata.Make(CollectionName, response));
        }
        public async Task <KvMetadata> PatchAsync(string key,
                                                  IEnumerable <PatchOperation> patchOperations,
                                                  string reference = null)
        {
            Guard.ArgumentNotNullOrEmpty("key", key);
            Guard.ArgumentNotNull("operations", patchOperations);

            HttpUrlBuilder uri = new HttpUrlBuilder(host)
                                 .AppendPath(CollectionName)
                                 .AppendPath(key);

            var response = await restClient.SendIfMatchAsync(uri, new HttpMethod("PATCH"), patchOperations.ToArray(), reference);

            return(KvMetadata.Make(CollectionName, response));
        }
        public async Task <KvMetadata> MergeAsync <T>(string key,
                                                      T item,
                                                      string reference = null)
        {
            Guard.ArgumentNotNullOrEmpty("key", key);
            Guard.ArgumentNotNull("item", item);

            HttpUrlBuilder uri = new HttpUrlBuilder(host)
                                 .AppendPath(CollectionName)
                                 .AppendPath(key);

            var response = await restClient.SendIfMatchAsync(uri, new HttpMethod("PATCH"), item, reference);

            return(KvMetadata.Make(CollectionName, response));
        }
Exemplo n.º 5
0
        public async Task <KvMetadata> CreateCollectionAsync <T>(string collectionName,
                                                                 string key,
                                                                 T item)
        {
            Guard.ArgumentNotNullOrEmpty("collectionName", collectionName);
            Guard.ArgumentNotNullOrEmpty("key", key);
            Guard.ArgumentNotNull("item", item);

            HttpUrlBuilder uri = new HttpUrlBuilder(application.HostUrl)
                                 .AppendPath(collectionName)
                                 .AppendPath(key);

            var response = await restClient.SendAsync(uri, HttpMethod.Put, item);

            return(KvMetadata.Make(collectionName, response));
        }
Exemplo n.º 6
0
        public async Task <KvMetadata> LinkAsync <T>(GraphNode fromNode, string kind, GraphNode toNode, T properties, string reference = null)
        {
            Guard.ArgumentNotNull("fromNode", fromNode);
            Guard.ArgumentNotNullOrEmpty("kind", kind);
            Guard.ArgumentNotNull("toNode", toNode);

            HttpUrlBuilder uri = new HttpUrlBuilder(application.HostUrl)
                                 .AppendPath(fromNode.CollectionName)
                                 .AppendPath(fromNode.Key)
                                 .AppendPath("relation")
                                 .AppendPath(kind)
                                 .AppendPath(toNode.CollectionName)
                                 .AppendPath(toNode.Key);

            var response = await restClient.SendIfMatchAsync(uri, HttpMethod.Put, properties, reference);

            return(KvMetadata.Make(fromNode.CollectionName, response));
        }
        public async Task <KvMetadata> UpdateAsync <T>(string key,
                                                       T item,
                                                       string reference = null)
        {
            Guard.ArgumentNotNullOrEmpty("key", key);
            Guard.ArgumentNotNull("item", item);

            try
            {
                await GetAsync <T>(key);
            }
            catch (NotFoundException exception)
            {
                throw exception;
            }

            HttpUrlBuilder uri = new HttpUrlBuilder(host)
                                 .AppendPath(CollectionName)
                                 .AppendPath(key);

            var response = await restClient.SendIfMatchAsync(uri, HttpMethod.Put, item, reference);

            return(KvMetadata.Make(CollectionName, response));
        }