wasDAVClient – Diff between revs 6 and 8
?pathlinks?
Rev 6 | Rev 8 | |||
---|---|---|---|---|
Line 122... | Line 122... | |||
122 | /// <summary> |
122 | /// <summary> |
|
123 | /// The HTTP request timeout in seconds. |
123 | /// The HTTP request timeout in seconds. |
|
124 | /// </summary> |
124 | /// </summary> |
|
125 | public int Timeout { get; set; } = 60; |
125 | public int Timeout { get; set; } = 60; |
|
Line 126... | Line 126... | |||
126 | |
126 | |
|
Line 127... | Line 127... | |||
127 | #endregion |
127 | #endregion WebDAV connection parameters |
|
Line 128... | Line 128... | |||
128 | |
128 | |
|
129 | #region WebDAV operations |
129 | #region WebDAV operations |
|
130 | |
130 | |
|
131 | /// <summary> |
131 | /// <summary> |
|
132 | /// List all files present on the server. |
132 | /// List all files present on the server. |
|
133 | /// </summary> |
133 | /// </summary> |
|
134 | /// <param name="path">List only files in this path</param> |
134 | /// <param name="path">List only files in this path</param> |
|
135 | /// <param name="depth">Recursion depth</param> |
135 | /// <param name="depth">Recursion depth</param> |
|
136 | /// <returns>A list of files (entries without a trailing slash) and directories (entries with a trailing slash)</returns> |
136 | /// <returns>A list of files (entries without a trailing slash) and directories (entries with a trailing slash)</returns> |
|
Line 137... | Line 137... | |||
137 | public async Task<IEnumerable<Item>> List(string path = "/", int? depth = 1) |
137 | public async Task<IEnumerable<Item>> List(string path = "/", string depth = Constants.DavDepth.MEMBERS) |
|
138 | { |
138 | { |
|
139 | var listUri = await GetServerUrl(path, true).ConfigureAwait(false); |
- | ||
140 | |
- | ||
141 | // Depth header: http://webdav.org/specs/rfc4918.html#rfc.section.9.1.4 |
139 | var listUri = await GetServerUrl(path, true).ConfigureAwait(false); |
|
142 | IDictionary<string, string> headers = new Dictionary<string, string>(); |
- | ||
Line 143... | Line 140... | |||
143 | if (depth != null) |
140 | |
|
Line 144... | Line 141... | |||
144 | { |
141 | // Depth header: http://webdav.org/specs/rfc4918.html#rfc.section.9.1.4 |
|
145 | headers.Add("Depth", depth.ToString()); |
142 | IDictionary<string, string> headers = new Dictionary<string, string>(); |
|
Line 175... | Line 172... | |||
175 | { |
172 | { |
|
176 | switch (!item.IsCollection) |
173 | switch (!item.IsCollection) |
|
177 | { |
174 | { |
|
178 | case true: |
175 | case true: |
|
179 | return item; |
176 | return item; |
|
- | 177 | |
||
180 | default: |
178 | default: |
|
181 | // If it's not the requested parent folder, add it to the result |
179 | // If it's not the requested parent folder, add it to the result |
|
182 | if (!string.Equals((await GetServerUrl(item.Href, true).ConfigureAwait(false)).ToString(), |
180 | if (!string.Equals((await GetServerUrl(item.Href, true).ConfigureAwait(false)).ToString(), |
|
183 | listUrl, StringComparison.CurrentCultureIgnoreCase)) |
181 | listUrl, StringComparison.CurrentCultureIgnoreCase)) |
|
184 | { |
182 | { |
|
Line 213... | Line 211... | |||
213 | public async Task<Item> GetFile(string path = "/") |
211 | public async Task<Item> GetFile(string path = "/") |
|
214 | { |
212 | { |
|
215 | return await Get((await GetServerUrl(path, false).ConfigureAwait(false)).Uri).ConfigureAwait(false); |
213 | return await Get((await GetServerUrl(path, false).ConfigureAwait(false)).Uri).ConfigureAwait(false); |
|
216 | } |
214 | } |
|
Line 217... | Line -... | |||
217 | |
- | ||
218 | |
215 | |
|
219 | /// <summary> |
216 | /// <summary> |
|
220 | /// List all files present on the server. |
217 | /// List all files present on the server. |
|
221 | /// </summary> |
218 | /// </summary> |
|
222 | /// <returns>A list of files (entries without a trailing slash) and directories (entries with a trailing slash)</returns> |
219 | /// <returns>A list of files (entries without a trailing slash) and directories (entries with a trailing slash)</returns> |
|
Line 309... | Line 306... | |||
309 | { |
306 | { |
|
310 | response?.Dispose(); |
307 | response?.Dispose(); |
|
311 | } |
308 | } |
|
312 | } |
309 | } |
|
Line 313... | Line -... | |||
313 | |
- | ||
314 | |
310 | |
|
315 | /// <summary> |
311 | /// <summary> |
|
316 | /// Create a directory on the server |
312 | /// Create a directory on the server |
|
317 | /// </summary> |
313 | /// </summary> |
|
318 | /// <param name="remotePath">Destination path of the directory on the server.</param> |
314 | /// <param name="remotePath">Destination path of the directory on the server.</param> |
|
Line 355... | Line 351... | |||
355 | public async Task DeleteFile(string href) |
351 | public async Task DeleteFile(string href) |
|
356 | { |
352 | { |
|
357 | await Delete((await GetServerUrl(href, false).ConfigureAwait(false)).Uri).ConfigureAwait(false); |
353 | await Delete((await GetServerUrl(href, false).ConfigureAwait(false)).Uri).ConfigureAwait(false); |
|
358 | } |
354 | } |
|
Line 359... | Line -... | |||
359 | |
- | ||
360 | |
355 | |
|
361 | private async Task Delete(Uri listUri) |
356 | private async Task Delete(Uri listUri) |
|
362 | { |
357 | { |
|
Line 363... | Line 358... | |||
363 | var response = await HttpRequest(listUri, HttpMethod.Delete).ConfigureAwait(false); |
358 | var response = await HttpRequest(listUri, HttpMethod.Delete).ConfigureAwait(false); |
|
Line 385... | Line 380... | |||
385 | await |
380 | await |
|
386 | Move((await GetServerUrl(srcFilePath, false).ConfigureAwait(false)).Uri, |
381 | Move((await GetServerUrl(srcFilePath, false).ConfigureAwait(false)).Uri, |
|
387 | (await GetServerUrl(dstFilePath, false).ConfigureAwait(false)).Uri).ConfigureAwait(false); |
382 | (await GetServerUrl(dstFilePath, false).ConfigureAwait(false)).Uri).ConfigureAwait(false); |
|
388 | } |
383 | } |
|
Line 389... | Line -... | |||
389 | |
- | ||
390 | |
384 | |
|
391 | private async Task<bool> Move(Uri srcUri, Uri dstUri) |
385 | private async Task<bool> Move(Uri srcUri, Uri dstUri) |
|
392 | { |
386 | { |
|
Line 393... | Line 387... | |||
393 | const string requestContent = "MOVE"; |
387 | const string requestContent = "MOVE"; |
|
Line 409... | Line 403... | |||
409 | } |
403 | } |
|
Line 410... | Line 404... | |||
410 | |
404 | |
|
411 | return response.IsSuccessStatusCode; |
405 | return response.IsSuccessStatusCode; |
|
Line 412... | Line 406... | |||
412 | } |
406 | } |
|
Line 413... | Line 407... | |||
413 | |
407 | |
|
Line 414... | Line 408... | |||
414 | #endregion |
408 | #endregion WebDAV operations |
|
415 | |
409 | |
|
Line 512... | Line 506... | |||
512 | var root = await Get(baseUri.Uri).ConfigureAwait(false); |
506 | var root = await Get(baseUri.Uri).ConfigureAwait(false); |
|
Line 513... | Line 507... | |||
513 | |
507 | |
|
514 | _encodedBasePath = root.Href; |
508 | _encodedBasePath = root.Href; |
|
Line 515... | Line -... | |||
515 | } |
- | ||
516 | |
509 | } |
|
517 | |
510 | |
|
518 | // If we've been asked for the "root" folder |
511 | // If we've been asked for the "root" folder |
|
519 | if (string.IsNullOrEmpty(path)) |
512 | if (string.IsNullOrEmpty(path)) |
|
520 | { |
513 | { |
|
Line 564... | Line 557... | |||
564 | finalPath = finalPath.TrimEnd('/') + "/"; |
557 | finalPath = finalPath.TrimEnd('/') + "/"; |
|
Line 565... | Line 558... | |||
565 | |
558 | |
|
566 | baseUri.Path = finalPath; |
559 | baseUri.Path = finalPath; |
|
Line 567... | Line -... | |||
567 | } |
- | ||
568 | |
560 | } |
|
569 | |
561 | |
|
570 | return baseUri; |
562 | return baseUri; |
|
Line 571... | Line 563... | |||
571 | } |
563 | } |
|
572 | } |
564 | } |
|
573 | |
565 | |
|
574 | public void Dispose() |
566 | public void Dispose() |
|
575 | { |
567 | { |
|
Line 576... | Line 568... | |||
576 | _client?.Dispose(); |
568 | _client?.Dispose(); |
|
577 | _uploadClient?.Dispose(); |
569 | _uploadClient?.Dispose(); |
|
578 | } |
570 | } |
|
579 | |
571 | |