private AtomEntry UpdateEntry(string url, AtomEntry entry) { Guard.ArgumentNotNull(entry, "entry"); try { var eTag = entry.GetSDataHttpETag(); var batchItem = new SDataBatchRequestItem { Url = url, Method = HttpMethod.Put, Entry = entry, ETag = eTag }; if (BatchProcess.Instance.AddToBatch(batchItem)) { return null; } var operation = new RequestOperation(HttpMethod.Put, entry) {ETag = eTag}; var response = ExecuteRequest(url, operation, MediaType.AtomEntry, MediaType.Xml); entry = (AtomEntry) response.Content; if (!string.IsNullOrEmpty(response.ETag)) { entry.SetSDataHttpETag(response.ETag); } return entry; } catch (Exception ex) { throw new SDataClientException(ex.Message, ex); } }
private bool DeleteEntry(string url, AtomEntry entry) { try { var eTag = entry != null ? entry.GetSDataHttpETag() : null; var batchItem = new SDataBatchRequestItem { Url = url, Method = HttpMethod.Delete, ETag = eTag }; if (BatchProcess.Instance.AddToBatch(batchItem)) { return true; } var operation = new RequestOperation(HttpMethod.Delete) {ETag = eTag}; var response = ExecuteRequest(url, operation, MediaType.AtomEntry, MediaType.Xml); return response.StatusCode == HttpStatusCode.OK; } catch (Exception ex) { throw new SDataClientException(ex.Message, ex); } }
/// <summary> /// Updates information about a syndication resource in the data source. /// </summary> /// <param name="request">The url from the syndication data source for the resource to be updated.</param> /// <param name="entry"> /// An object that implements the <see cref="ISyndicationResource"/> interface that represents the updated information for the resource. /// </param> public virtual AtomEntry UpdateEntry(SDataBaseRequest request, AtomEntry entry) { Guard.ArgumentNotNull(request, "request"); Guard.ArgumentNotNull(entry, "entry"); try { var url = request.ToString(); var eTag = entry.GetSDataHttpETag(); var batchItem = new SDataBatchRequestItem { Url = url, Method = HttpMethod.Put, Entry = entry, ETag = eTag }; if (BatchProcess.Instance.AddToBatch(batchItem)) { return null; } var operation = new RequestOperation(HttpMethod.Put, entry) {ETag = eTag}; return ExecuteEntryRequest(url, operation); } catch (SDataClientException) { throw; } catch (Exception ex) { throw new SDataClientException(ex.Message, ex); } }
/// <summary> /// Reads resource information from the data source based on the URL and the ETag of the specified entry. /// </summary> /// <param name="request"></param> /// <param name="entry"></param> /// <returns></returns> public virtual AtomEntry ReadEntry(SDataBaseRequest request, AtomEntry entry) { Guard.ArgumentNotNull(request, "request"); try { var requestUrl = request.ToString(); var eTag = entry != null ? entry.GetSDataHttpETag() : null; var batchItem = new SDataBatchRequestItem { Url = requestUrl, Method = HttpMethod.Get, ETag = eTag }; if (BatchProcess.Instance.AddToBatch(batchItem)) { return null; } var operation = new RequestOperation(HttpMethod.Get) {ETag = eTag}; var response = ExecuteRequest(requestUrl, operation, MediaType.AtomEntry, MediaType.Xml); entry = (AtomEntry) response.Content; if (!string.IsNullOrEmpty(response.ETag)) { entry.SetSDataHttpETag(response.ETag); } return entry; } catch (Exception ex) { throw new SDataClientException(ex.Message, ex); } }
/// <summary> /// Removes a resource from the syndication data source. /// </summary> /// <param name="request">The request from the syndication data source for the resource to be removed.</param> /// <param name="entry">the resource that is being deleted</param> /// <returns><b>true</b> if the syndication resource was successfully deleted; otherwise, <b>false</b>.</returns> public virtual bool DeleteEntry(SDataBaseRequest request, AtomEntry entry) { Guard.ArgumentNotNull(request, "request"); try { var url = request.ToString(); var eTag = entry != null ? entry.GetSDataHttpETag() : null; var batchItem = new SDataBatchRequestItem { Url = url, Method = HttpMethod.Delete, ETag = eTag }; if (BatchProcess.Instance.AddToBatch(batchItem)) { return true; } var operation = new RequestOperation(HttpMethod.Delete) {ETag = eTag}; var response = ExecuteRequest(url, operation, MediaType.AtomEntry, MediaType.Xml); return response.StatusCode == HttpStatusCode.OK; } catch (Exception ex) { throw new SDataClientException(ex.Message, ex); } }