Represents parameters for the PUT WebDAV method.
Esempio n. 1
0
        /// <summary>
        /// Requests the resource to be stored under the request URI.
        /// </summary>
        /// <param name="requestUri">The <see cref="Uri"/> to request.</param>
        /// <param name="stream">The stream of content of the resource.</param>
        /// <param name="contentType">The content type of the request body.</param>
        /// <returns>An instance of <see cref="WebDavResponse" />.</returns>
        public Task <WebDavResponse> PutFile(Uri requestUri, Stream stream, string contentType)
        {
            var @params = new PutFileParameters {
                ContentType = new MediaTypeHeaderValue(contentType)
            };

            return(PutFile(requestUri, new StreamContent(stream), @params));
        }
Esempio n. 2
0
        /// <summary>
        /// Requests the resource to be stored under the request URI.
        /// </summary>
        /// <param name="requestUri">The <see cref="System.Uri"/> to request.</param>
        /// <param name="stream">The stream of content of the resource.</param>
        /// <param name="parameters">Parameters of the PUT operation.</param>
        /// <returns>An instance of <see cref="WebDavResponse" /></returns>
        public async Task <WebDavResponse> PutFile(Uri requestUri, Stream stream, PutFileParameters parameters)
        {
            Guard.NotNull(requestUri, "requestUri");
            Guard.NotNull(stream, "stream");

            var headers = new RequestHeaders();

            if (!string.IsNullOrEmpty(parameters.LockToken))
            {
                headers.Add(new KeyValuePair <string, string>("If", IfHeaderHelper.GetHeaderValue(parameters.LockToken)));
            }
            var requestParams = new RequestParameters {
                Headers = headers, Content = new StreamContent(stream), ContentType = parameters.ContentType
            };
            var response = await _dispatcher.Send(requestUri, HttpMethod.Put, requestParams, parameters.CancellationToken);

            return(new WebDavResponse(response.StatusCode, response.Description));
        }
        public void Upload(string webDavLocation, string localFile, WebDavOperationCallback operationProgress = null)
        {
            webDavLocation = webDavLocation.Replace("\\", "/").Trim('/');

            var webDavFile = new Uri($"{this.BaseAddress}{webDavLocation}");

            using (var stream = new FileStream(localFile, FileMode.Open))
            {
                var putFileParams = new PutFileParameters();
                putFileParams.OperationProgress = operationProgress;

                var response = this.PutFile(webDavFile, stream, putFileParams);
                if (!response.IsSuccessful)
                {
                    throw new ApplicationException($"Unable save file: --> {response.StatusCode} {response.Description}");
                }
            }

            var name = XName.Get("x-lastmodified", "DataSync");

            FileInfo fi = new FileInfo(localFile);

            int attempt = 5;

            while (true)
            {
                var patch = new ProppatchParameters();
                patch.PropertiesToSet.Add(name, fi.LastWriteTimeUtc.ToString("u"));
                patch.Namespaces.Add(new NamespaceAttr("u", "DataSync"));

                var propPatch = this.Proppatch(webDavFile, patch);
                if (propPatch.IsSuccessful)
                {
                    break;
                }

                attempt = attempt - 1;
                if (attempt == 0)
                {
                    throw new ApplicationException($"Unable update file properties: --> {propPatch.StatusCode} {propPatch.Description}");
                }
                Thread.Sleep(1000);
            }
        }
        /// <summary>
        /// Requests the resource to be stored under the request URI.
        /// </summary>
        /// <param name="requestUri">The <see cref="Uri"/> to request.</param>
        /// <param name="content">The content to pass to the request.</param>
        /// <param name="parameters">Parameters of the PUT operation.</param>
        /// <returns>An instance of <see cref="WebDavResponse" />.</returns>
        public WebDavResponse PutFile(Uri requestUri, HttpContent content, PutFileParameters parameters)
        {
            Guard.NotNull(requestUri, "requestUri");
            Guard.NotNull(content, "content");

            var headerBuilder = new HeaderBuilder();

            if (!string.IsNullOrEmpty(parameters.LockToken))
            {
                headerBuilder.Add(WebDavHeaders.If, IfHeaderHelper.GetHeaderValue(parameters.LockToken));
            }

            var headers       = headerBuilder.AddWithOverwrite(parameters.Headers).Build();
            var requestParams = new RequestParameters {
                Headers = headers, Content = content, ContentType = parameters.ContentType, OperationProgress = parameters.OperationProgress
            };

            using (var response = _dispatcher.Send(requestUri, HttpMethod.Put, requestParams))
            {
                return(new WebDavResponse(response));
            }
        }
 /// <summary>
 /// Requests the resource to be stored under the request URI.
 /// </summary>
 /// <param name="requestUri">A string that represents the request URI.</param>
 /// <param name="content">The content to pass to the request.</param>
 /// <param name="parameters">Parameters of the PUT operation.</param>
 /// <returns>An instance of <see cref="WebDavResponse" />.</returns>
 public WebDavResponse PutFile(string requestUri, HttpContent content, PutFileParameters parameters)
 {
     return(PutFile(CreateUri(requestUri), content, parameters));
 }
 /// <summary>
 /// Requests the resource to be stored under the request URI.
 /// </summary>
 /// <param name="requestUri">The <see cref="Uri"/> to request.</param>
 /// <param name="stream">The stream of content of the resource.</param>
 /// <param name="parameters">Parameters of the PUT operation.</param>
 /// <returns>An instance of <see cref="WebDavResponse" />.</returns>
 public WebDavResponse PutFile(Uri requestUri, Stream stream, PutFileParameters parameters)
 {
     return(PutFile(requestUri, new StreamContent(stream), parameters));
 }
 /// <summary>
 /// Requests the resource to be stored under the request URI.
 /// </summary>
 /// <param name="requestUri">A string that represents the request URI.</param>
 /// <param name="stream">The stream of content of the resource.</param>
 /// <param name="parameters">Parameters of the PUT operation.</param>
 /// <returns>An instance of <see cref="WebDavResponse" />.</returns>
 public WebDavResponse PutFile(string requestUri, Stream stream, PutFileParameters parameters)
 {
     return(PutFile(CreateUri(requestUri), new StreamContent(stream), parameters));
 }
Esempio n. 8
0
 /// <summary>
 /// Requests the resource to be stored under the request URI.
 /// </summary>
 /// <param name="requestUri">A string that represents the request <see cref="T:System.Uri"/>.</param>
 /// <param name="stream">The stream of content of the resource.</param>
 /// <param name="parameters">Parameters of the PUT operation.</param>
 /// <returns>An instance of <see cref="WebDavResponse" /></returns>
 public Task <WebDavResponse> PutFile(string requestUri, Stream stream, PutFileParameters parameters)
 {
     return(PutFile(CreateUri(requestUri), stream, parameters));
 }
Esempio n. 9
0
        /// <summary>
        /// Requests the resource to be stored under the request URI.
        /// </summary>
        /// <param name="requestUri">The <see cref="Uri"/> to request.</param>
        /// <param name="content">The content to pass to the request.</param>
        /// <param name="parameters">Parameters of the PUT operation.</param>
        /// <returns>An instance of <see cref="WebDavResponse" />.</returns>
        public async Task <WebDavResponse> PutFile(Uri requestUri, HttpContent content, PutFileParameters parameters)
        {
            Guard.NotNull(requestUri, "requestUri");
            Guard.NotNull(content, "content");

            var headerBuilder = new HeaderBuilder();

            if (!string.IsNullOrEmpty(parameters.LockToken))
            {
                headerBuilder.Add(WebDavHeaders.If, IfHeaderHelper.GetHeaderValue(parameters.LockToken));
            }

            var headers       = headerBuilder.AddWithOverwrite(parameters.Headers).Build();
            var requestParams = new RequestParameters {
                Headers = headers, Content = content, ContentType = parameters.ContentType
            };
            var response = await _dispatcher.Send(requestUri, HttpMethod.Put, requestParams, parameters.CancellationToken).ConfigureAwait(false);

            return(new WebDavResponse((int)response.StatusCode, response.ReasonPhrase));
        }