コード例 #1
0
        public async Task DeleteEntity(WebResourceName uri, string etag)
        {
            s_logger.DebugFormat("Deleting entity '{0}'", uri);

            var absoluteEventUrl = new Uri(_serverUrl, uri.OriginalAbsolutePath);

            s_logger.DebugFormat("Absolute entity location: '{0}'", absoluteEventUrl);

            IHttpHeaders responseHeaders = await _webDavClient.ExecuteWebDavRequestAndReturnResponseHeaders(
                absoluteEventUrl,
                "DELETE",
                null,
                etag,
                null,
                null,
                string.Empty);

            IEnumerable <string> errorValues;

            if (responseHeaders.TryGetValues("X-Dav-Error", out errorValues))
            {
                var errorList = errorValues.ToList();
                if (errorList.Any(v => v != "200 No error"))
                {
                    throw new Exception(string.Format("Error deleting entity with url '{0}' and etag '{1}': {2}", uri, etag, string.Join(",", errorList)));
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Gets the HTTP header value or the given <paramref name="defaultValue"/>.
        /// </summary>
        /// <param name="headers">The headers to get the value from</param>
        /// <param name="name">The header name to get the value for</param>
        /// <param name="defaultValue">The default value when the header value couldn't be found in the headers.</param>
        /// <returns>The first HTTP header value or the given <paramref name="defaultValue"/>.</returns>
        public static string GetValue(this IHttpHeaders headers, string name, string defaultValue)
        {
            IEnumerable <string> values;

            if (!headers.TryGetValues(name, out values))
            {
                return(defaultValue);
            }
            return(values.FirstOrDefault() ?? defaultValue);
        }
コード例 #3
0
 public HttpWebResponseContent(IHttpHeaders headers, HttpWebResponse response)
 {
     Headers = headers;
     _response = response;
     IEnumerable<string> contentLength;
     if (headers.TryGetValues("content-length", out contentLength))
     {
         var headerValue = contentLength.FirstOrDefault();
         if (headerValue != null)
             _contentLength = long.Parse(headerValue);
     }
 }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HttpWebResponseContent"/> class.
        /// </summary>
        /// <param name="headers">The HTTP headers for the response content</param>
        /// <param name="response">The response</param>
        public HttpWebResponseContent([NotNull] IHttpHeaders headers, [CanBeNull] HttpWebResponse response)
        {
            Headers   = headers;
            _response = response;
            IEnumerable <string> contentLength;

            if (headers.TryGetValues("content-length", out contentLength))
            {
                var headerValue = contentLength.FirstOrDefault();
                if (headerValue != null)
                {
                    _contentLength = long.Parse(headerValue);
                }
            }
        }