wasDAVClient

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 7  →  ?path2? @ 8
/wasDAVClient/Client.cs
@@ -70,10 +70,10 @@
handler.PreAuthenticate = true;
}
 
_client = new HttpClient(handler) {Timeout = TimeSpan.FromSeconds(Timeout)};
_client = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(Timeout) };
_client.DefaultRequestHeaders.ExpectContinue = false;
 
_uploadClient = new HttpClient(handler) {Timeout = TimeSpan.FromSeconds(Timeout)};
_uploadClient = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(Timeout) };
_uploadClient.DefaultRequestHeaders.ExpectContinue = false;
}
 
@@ -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;
 
@@ -155,9 +152,9 @@
.ConfigureAwait(false);
 
if (response.StatusCode != HttpStatusCode.OK &&
(int) response.StatusCode != HttpStatusCode_MultiStatus)
(int)response.StatusCode != HttpStatusCode_MultiStatus)
{
throw new wasDAVException((int) response.StatusCode, "Failed retrieving items in folder.");
throw new wasDAVException((int)response.StatusCode, "Failed retrieving items in folder.");
}
 
using (var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
@@ -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>
@@ -236,9 +233,9 @@
.ConfigureAwait(false);
 
if (response.StatusCode != HttpStatusCode.OK &&
(int) response.StatusCode != HttpStatusCode_MultiStatus)
(int)response.StatusCode != HttpStatusCode_MultiStatus)
{
throw new wasDAVException((int) response.StatusCode,
throw new wasDAVException((int)response.StatusCode,
$"Failed retrieving item/folder (Status Code: {response.StatusCode})");
}
 
@@ -269,11 +266,11 @@
// Should not have a trailing slash.
var downloadUri = await GetServerUrl(remoteFilePath, false).ConfigureAwait(false);
 
var dictionary = new Dictionary<string, string> {{"translate", "f"}};
var dictionary = new Dictionary<string, string> { { "translate", "f" } };
var response = await HttpRequest(downloadUri.Uri, HttpMethod.Get, dictionary).ConfigureAwait(false);
if (response.StatusCode != HttpStatusCode.OK)
{
throw new wasDAVException((int) response.StatusCode, "Failed retrieving file.");
throw new wasDAVException((int)response.StatusCode, "Failed retrieving file.");
}
return await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
}
@@ -300,7 +297,7 @@
response.StatusCode != HttpStatusCode.NoContent &&
response.StatusCode != HttpStatusCode.Created)
{
throw new wasDAVException((int) response.StatusCode, "Failed uploading file.");
throw new wasDAVException((int)response.StatusCode, "Failed uploading file.");
}
 
return response.IsSuccessStatusCode;
@@ -311,7 +308,6 @@
}
}
 
 
/// <summary>
/// Create a directory on the server
/// </summary>
@@ -330,13 +326,13 @@
response = await HttpRequest(dirUri.Uri, MkCol).ConfigureAwait(false);
 
if (response.StatusCode == HttpStatusCode.Conflict)
throw new wasDAVConflictException((int) response.StatusCode, "Failed creating folder.");
throw new wasDAVConflictException((int)response.StatusCode, "Failed creating folder.");
 
if (response.StatusCode != HttpStatusCode.OK &&
response.StatusCode != HttpStatusCode.NoContent &&
response.StatusCode != HttpStatusCode.Created)
{
throw new wasDAVException((int) response.StatusCode, "Failed creating folder.");
throw new wasDAVException((int)response.StatusCode, "Failed creating folder.");
}
 
return response.IsSuccessStatusCode;
@@ -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);
@@ -365,7 +360,7 @@
if (response.StatusCode != HttpStatusCode.OK &&
response.StatusCode != HttpStatusCode.NoContent)
{
throw new wasDAVException((int) response.StatusCode, "Failed deleting item.");
throw new wasDAVException((int)response.StatusCode, "Failed deleting item.");
}
}
 
@@ -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";
@@ -405,13 +399,13 @@
if (response.StatusCode != HttpStatusCode.OK &&
response.StatusCode != HttpStatusCode.Created)
{
throw new wasDAVException((int) response.StatusCode, "Failed moving file.");
throw new wasDAVException((int)response.StatusCode, "Failed moving file.");
}
 
return response.IsSuccessStatusCode;
}
 
#endregion
#endregion WebDAV operations
 
#region Server communication
 
@@ -508,13 +502,12 @@
// Resolve the base path on the server
if (_encodedBasePath == null)
{
var baseUri = new UriBuilder(_server) {Path = _basePath};
var baseUri = new UriBuilder(_server) { Path = _basePath };
var root = await Get(baseUri.Uri).ConfigureAwait(false);
 
_encodedBasePath = root.Href;
}
 
 
// If we've been asked for the "root" folder
if (string.IsNullOrEmpty(path))
{
@@ -526,7 +519,7 @@
}
 
// Otherwise, use the resolved base path relatively to the server
var baseUri = new UriBuilder(_server) {Path = _encodedBasePath};
var baseUri = new UriBuilder(_server) { Path = _encodedBasePath };
return baseUri;
}
 
@@ -566,7 +559,6 @@
baseUri.Path = finalPath;
}
 
 
return baseUri;
}
}
@@ -577,6 +569,6 @@
_uploadClient?.Dispose();
}
 
#endregion
#endregion Server communication
}
}
}