wasDAVClient

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 8  →  ?path2? @ 7
File deleted
/wasDAVClient/Constants.cs
/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.5.*")]
[assembly: AssemblyVersion("1.4.*")]
/wasDAVClient/wasDAVClient.csproj
@@ -38,7 +38,6 @@
</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" />
/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 WebDAV connection parameters
#endregion
 
#region WebDAV operations
 
@@ -134,13 +134,16 @@
/// <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 = "/", string depth = Constants.DavDepth.MEMBERS)
public async Task<IEnumerable<Item>> List(string path = "/", int? depth = 1)
{
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>();
headers.Add("Depth", depth);
if (depth != null)
{
headers.Add("Depth", depth.ToString());
}
 
HttpResponseMessage response = null;
 
@@ -152,9 +155,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))
@@ -174,7 +177,6 @@
{
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(),
@@ -213,6 +215,7 @@
return await Get((await GetServerUrl(path, false).ConfigureAwait(false)).Uri).ConfigureAwait(false);
}
 
 
/// <summary>
/// List all files present on the server.
/// </summary>
@@ -233,9 +236,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})");
}
 
@@ -266,11 +269,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);
}
@@ -297,7 +300,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;
@@ -308,6 +311,7 @@
}
}
 
 
/// <summary>
/// Create a directory on the server
/// </summary>
@@ -326,13 +330,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;
@@ -353,6 +357,7 @@
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);
@@ -360,7 +365,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.");
}
}
 
@@ -382,6 +387,7 @@
(await GetServerUrl(dstFilePath, false).ConfigureAwait(false)).Uri).ConfigureAwait(false);
}
 
 
private async Task<bool> Move(Uri srcUri, Uri dstUri)
{
const string requestContent = "MOVE";
@@ -399,13 +405,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 WebDAV operations
#endregion
 
#region Server communication
 
@@ -502,12 +508,13 @@
// 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))
{
@@ -519,7 +526,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;
}
 
@@ -559,6 +566,7 @@
baseUri.Path = finalPath;
}
 
 
return baseUri;
}
}
@@ -569,6 +577,6 @@
_uploadClient?.Dispose();
}
 
#endregion Server communication
#endregion
}
}
}
/wasDAVClient/IClient.cs
@@ -37,8 +37,9 @@
/// <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>
@@ -45,19 +46,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 = Constants.DIRECTORY_SEPARATOR, string depth = Constants.DavDepth.MEMBERS);
Task<IEnumerable<Item>> List(string path = "/", int? depth = 1);
 
/// <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 = Constants.DIRECTORY_SEPARATOR);
Task<Item> GetFolder(string path = "/");
 
/// <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 = Constants.DIRECTORY_SEPARATOR);
Task<Item> GetFile(string path = "/");
 
/// <summary>
/// Download a file from the server
@@ -84,13 +85,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 = Constants.DIRECTORY_SEPARATOR);
Task DeleteFolder(string path = "/");
 
/// <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 = Constants.DIRECTORY_SEPARATOR);
Task DeleteFile(string path = "/");
 
/// <summary>
/// Move a folder on the server
@@ -106,4 +107,4 @@
/// <param name="dstFilePath">Destination path and filename of the file on the server</param>
Task<bool> MoveFile(string srcFilePath, string dstFilePath);
}
}
}