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
}
}
}
/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
@@ -37,9 +37,8 @@
/// <summary>
/// Specify the UserAgent (and UserAgent version) string to use in requests
/// </summary>
string UserAgentVersion { get; set; }
 
 
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
@@ -107,4 +106,4 @@
/// <param name="dstFilePath">Destination path and filename of the file on the server</param>
Task<bool> MoveFile(string srcFilePath, string dstFilePath);
}
}
}
/wasDAVClient/Properties/AssemblyInfo.cs
@@ -2,7 +2,7 @@
using System.Resources;
using System.Runtime.InteropServices;
 
// General Information about an assembly is controlled through the following
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
 
@@ -16,8 +16,8 @@
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
 
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
 
[assembly: ComVisible(false)]
@@ -29,12 +29,12 @@
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
 
[assembly: AssemblyVersion("1.4.*")]
[assembly: AssemblyVersion("1.5.*")]
/wasDAVClient/wasDAVClient.csproj
@@ -38,6 +38,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Client.cs" />
<Compile Include="Constants.cs" />
<Compile Include="Helpers\ResponseParser.cs" />
<Compile Include="Helpers\wasDAVConflictException.cs" />
<Compile Include="Helpers\wasDAVException.cs" />