/wasDAVClient/Client.cs |
@@ -124,7 +124,7 @@ |
/// </summary> |
public int Timeout { get; set; } = 60; |
|
#endregion |
#endregion WebDAV connection parameters |
|
#region WebDAV operations |
|
@@ -134,16 +134,13 @@ |
/// <param name="path">List only files in this path</param> |
/// <param name="depth">Recursion depth</param> |
/// <returns>A list of files (entries without a trailing slash) and directories (entries with a trailing slash)</returns> |
public async Task<IEnumerable<Item>> List(string path = "/", int? depth = 1) |
public async Task<IEnumerable<Item>> List(string path = "/", string depth = Constants.DavDepth.MEMBERS) |
{ |
var listUri = await GetServerUrl(path, true).ConfigureAwait(false); |
|
// Depth header: http://webdav.org/specs/rfc4918.html#rfc.section.9.1.4 |
IDictionary<string, string> headers = new Dictionary<string, string>(); |
if (depth != null) |
{ |
headers.Add("Depth", depth.ToString()); |
} |
headers.Add("Depth", depth); |
|
HttpResponseMessage response = null; |
|
@@ -177,6 +174,7 @@ |
{ |
case true: |
return item; |
|
default: |
// If it's not the requested parent folder, add it to the result |
if (!string.Equals((await GetServerUrl(item.Href, true).ConfigureAwait(false)).ToString(), |
@@ -215,7 +213,6 @@ |
return await Get((await GetServerUrl(path, false).ConfigureAwait(false)).Uri).ConfigureAwait(false); |
} |
|
|
/// <summary> |
/// List all files present on the server. |
/// </summary> |
@@ -311,7 +308,6 @@ |
} |
} |
|
|
/// <summary> |
/// Create a directory on the server |
/// </summary> |
@@ -357,7 +353,6 @@ |
await Delete((await GetServerUrl(href, false).ConfigureAwait(false)).Uri).ConfigureAwait(false); |
} |
|
|
private async Task Delete(Uri listUri) |
{ |
var response = await HttpRequest(listUri, HttpMethod.Delete).ConfigureAwait(false); |
@@ -387,7 +382,6 @@ |
(await GetServerUrl(dstFilePath, false).ConfigureAwait(false)).Uri).ConfigureAwait(false); |
} |
|
|
private async Task<bool> Move(Uri srcUri, Uri dstUri) |
{ |
const string requestContent = "MOVE"; |
@@ -411,7 +405,7 @@ |
return response.IsSuccessStatusCode; |
} |
|
#endregion |
#endregion WebDAV operations |
|
#region Server communication |
|
@@ -514,7 +508,6 @@ |
_encodedBasePath = root.Href; |
} |
|
|
// If we've been asked for the "root" folder |
if (string.IsNullOrEmpty(path)) |
{ |
@@ -566,7 +559,6 @@ |
baseUri.Path = finalPath; |
} |
|
|
return baseUri; |
} |
} |
@@ -577,6 +569,6 @@ |
_uploadClient?.Dispose(); |
} |
|
#endregion |
#endregion Server communication |
} |
} |
} |
/wasDAVClient/Constants.cs |
@@ -0,0 +1,26 @@ |
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) Wizardry and Steamworks 2017 - License: GNU GPLv3 // |
// Please see: http://www.gnu.org/licenses/gpl.html for legal details, // |
// rights of fair usage, the disclaimer and warranty conditions. // |
/////////////////////////////////////////////////////////////////////////// |
|
using System; |
using System.Collections.Generic; |
using System.Linq; |
using System.Text; |
using System.Threading.Tasks; |
|
namespace wasDAVClient |
{ |
public class Constants |
{ |
public const string DIRECTORY_SEPARATOR = @"/"; |
|
public struct DavDepth |
{ |
public const string RESOURCE = @"0"; |
public const string MEMBERS = @"1"; |
public const string ALL = @"infinity"; |
} |
} |
} |
/wasDAVClient/IClient.cs |
@@ -39,7 +39,6 @@ |
/// </summary> |
string UserAgentVersion { get; set; } |
|
|
/// <summary> |
/// List all files present on the server. |
/// </summary> |
@@ -46,19 +45,19 @@ |
/// <param name="path">List only files in this path</param> |
/// <param name="depth">Recursion depth</param> |
/// <returns>A list of files (entries without a trailing slash) and directories (entries with a trailing slash)</returns> |
Task<IEnumerable<Item>> List(string path = "/", int? depth = 1); |
Task<IEnumerable<Item>> List(string path = Constants.DIRECTORY_SEPARATOR, string depth = Constants.DavDepth.MEMBERS); |
|
/// <summary> |
/// Get folder information from the server. |
/// </summary> |
/// <returns>A list of files (entries without a trailing slash) and directories (entries with a trailing slash)</returns> |
Task<Item> GetFolder(string path = "/"); |
Task<Item> GetFolder(string path = Constants.DIRECTORY_SEPARATOR); |
|
/// <summary> |
/// Get file information from the server. |
/// </summary> |
/// <returns>A list of files (entries without a trailing slash) and directories (entries with a trailing slash)</returns> |
Task<Item> GetFile(string path = "/"); |
Task<Item> GetFile(string path = Constants.DIRECTORY_SEPARATOR); |
|
/// <summary> |
/// Download a file from the server |
@@ -85,13 +84,13 @@ |
/// Get folder information from the server. |
/// </summary> |
/// <returns>A list of files (entries without a trailing slash) and directories (entries with a trailing slash)</returns> |
Task DeleteFolder(string path = "/"); |
Task DeleteFolder(string path = Constants.DIRECTORY_SEPARATOR); |
|
/// <summary> |
/// Get file information from the server. |
/// </summary> |
/// <returns>A list of files (entries without a trailing slash) and directories (entries with a trailing slash)</returns> |
Task DeleteFile(string path = "/"); |
Task DeleteFile(string path = Constants.DIRECTORY_SEPARATOR); |
|
/// <summary> |
/// Move a folder on the server |