diff --git a/WebDAV-Client-Solution.sln.DotSettings b/WebDAV-Client-Solution.sln.DotSettings
index 217a787..3669ad3 100644
--- a/WebDAV-Client-Solution.sln.DotSettings
+++ b/WebDAV-Client-Solution.sln.DotSettings
@@ -1,4 +1,5 @@
True
+ True
True
True
\ No newline at end of file
diff --git a/src/WebDAV-Client/ApiParams/UnlockParameters.cs b/src/WebDAV-Client/ApiParams/UnlockParameters.cs
index 53ccdc5..cbec0ff 100644
--- a/src/WebDAV-Client/ApiParams/UnlockParameters.cs
+++ b/src/WebDAV-Client/ApiParams/UnlockParameters.cs
@@ -1,33 +1,30 @@
using System.Threading;
-using JetBrains.Annotations;
+using Stef.Validation;
-namespace WebDav
+namespace WebDav;
+
+///
+/// Represents parameters for the UNLOCK WebDAV method.
+///
+public class UnlockParameters
{
///
- /// Represents parameters for the UNLOCK WebDAV method.
+ /// Initializes a new instance of the class.
+ /// The resource lock token.
///
- public class UnlockParameters
+ public UnlockParameters(string lockToken)
{
- ///
- /// Initializes a new instance of the class.
- /// The resource lock token.
- ///
- public UnlockParameters([NotNull] string lockToken)
- {
- Check.NotNull(lockToken, nameof(lockToken));
-
- LockToken = lockToken;
- CancellationToken = CancellationToken.None;
- }
+ LockToken = Guard.NotNull(lockToken);
+ CancellationToken = CancellationToken.None;
+ }
- ///
- /// Gets the resource lock token.
- ///
- public string LockToken { get; private set; }
+ ///
+ /// Gets the resource lock token.
+ ///
+ public string LockToken { get; }
- ///
- /// Gets or sets the cancellation token.
- ///
- public CancellationToken CancellationToken { get; set; }
- }
-}
+ ///
+ /// Gets or sets the cancellation token.
+ ///
+ public CancellationToken CancellationToken { get; set; }
+}
\ No newline at end of file
diff --git a/src/WebDAV-Client/ApiParams/WebDavClientParams.cs b/src/WebDAV-Client/ApiParams/WebDavClientParams.cs
index e39215a..268c298 100644
--- a/src/WebDAV-Client/ApiParams/WebDavClientParams.cs
+++ b/src/WebDAV-Client/ApiParams/WebDavClientParams.cs
@@ -3,82 +3,82 @@
using System.Net;
using System.Net.Http;
-namespace WebDav
+// ReSharper disable once CheckNamespace
+namespace WebDav;
+
+///
+/// Represents parameters for the class.
+///
+public class WebDavClientParams
{
///
- /// Represents parameters for the class.
+ /// Initializes a new instance of the class.
///
- public class WebDavClientParams
+ public WebDavClientParams()
{
- ///
- /// Initializes a new instance of the class.
- ///
- public WebDavClientParams()
- {
- UseDefaultCredentials = true;
- DefaultRequestHeaders = new Dictionary();
- Timeout = TimeSpan.FromMilliseconds(-1); // Infinite timespan is nothing but TimeSpan with milliseconds set to -1
- UseProxy = true;
- PreAuthenticate = true;
- }
+ UseDefaultCredentials = true;
+ DefaultRequestHeaders = new Dictionary();
+ Timeout = TimeSpan.FromMilliseconds(-1); // Infinite timespan is nothing but TimeSpan with milliseconds set to -1
+ UseProxy = true;
+ PreAuthenticate = true;
+ }
- ///
- /// Gets or sets the HTTP message handler. Note that this overrides some other properties in this class like:
- /// - PreAuthenticate
- /// - UseDefaultCredentials
- /// - UseProxy
- /// - Credentials
- /// - Proxy
- ///
- public HttpMessageHandler HttpMessageHandler { get; set; }
+ ///
+ /// Gets or sets the HTTP message handler. Note that this overrides some other properties in this class like:
+ /// - PreAuthenticate
+ /// - UseDefaultCredentials
+ /// - UseProxy
+ /// - Credentials
+ /// - Proxy
+ ///
+ public HttpMessageHandler? HttpMessageHandler { get; set; }
- ///
- /// Gets or sets a value that controls whether default credentials are sent.
- ///
- ///
- /// true if the default credentials are used; otherwise false. The default value is true.
- ///
- public bool UseDefaultCredentials { get; set; }
+ ///
+ /// Gets or sets a value that controls whether default credentials are sent.
+ ///
+ ///
+ /// true if the default credentials are used; otherwise false. The default value is true.
+ ///
+ public bool UseDefaultCredentials { get; set; }
- ///
- /// Gets or sets the base address of the resource's URI used when sending requests.
- ///
- public Uri BaseAddress { get; set; }
+ ///
+ /// Gets or sets the base address of the resource's URI used when sending requests.
+ ///
+ public Uri BaseAddress { get; set; }
- ///
- /// Gets or sets authentication information used by the WebDavClient.
- ///
- public ICredentials Credentials { get; set; }
+ ///
+ /// Gets or sets authentication information used by the WebDavClient.
+ ///
+ public ICredentials? Credentials { get; set; }
- ///
- /// Gets or sets the headers which should be sent with each request.
- ///
- public IDictionary DefaultRequestHeaders { get; set; }
+ ///
+ /// Gets or sets the headers which should be sent with each request.
+ ///
+ public IDictionary DefaultRequestHeaders { get; set; }
- ///
- /// Gets or sets a value that indicates whether an Authorization header should be sent with the request.
- ///
- ///
- /// true if an HTTP Authorization header should be send with requests after authentication has taken place; otherwise, false. The default value is true.
- ///
- public bool PreAuthenticate { get; set; }
+ ///
+ /// Gets or sets a value that indicates whether an Authorization header should be sent with the request.
+ ///
+ ///
+ /// true if an HTTP Authorization header should be send with requests after authentication has taken place; otherwise, false. The default value is true.
+ ///
+ public bool PreAuthenticate { get; set; }
- ///
- /// Gets or sets proxy information used by the WebDavClient.
- ///
- public IWebProxy Proxy { get; set; }
+ ///
+ /// Gets or sets proxy information used by the WebDavClient.
+ ///
+ public IWebProxy? Proxy { get; set; }
- ///
- /// Gets or sets a timeout for WebDAV operations.
- ///
- public TimeSpan Timeout { get; set; }
+ ///
+ /// Gets or sets a timeout for WebDAV operations.
+ ///
+ public TimeSpan Timeout { get; set; }
- ///
- /// Gets or sets a value indicating whether a proxy should be used for requests.
- ///
- ///
- /// true if a proxy should be used for requests; otherwise, false. The default value is true.
- ///
- public bool UseProxy { get; set; }
- }
-}
+ ///
+ /// Gets or sets a value indicating whether a proxy should be used for requests.
+ ///
+ ///
+ /// true if a proxy should be used for requests; otherwise, false. The default value is true.
+ ///
+ public bool UseProxy { get; set; }
+}
\ No newline at end of file
diff --git a/src/WebDAV-Client/Domain/PrincipalLockOwner.cs b/src/WebDAV-Client/Domain/PrincipalLockOwner.cs
index ba5b06e..a6ecbe9 100644
--- a/src/WebDAV-Client/Domain/PrincipalLockOwner.cs
+++ b/src/WebDAV-Client/Domain/PrincipalLockOwner.cs
@@ -1,25 +1,24 @@
using JetBrains.Annotations;
+using Stef.Validation;
-namespace WebDav
+namespace WebDav;
+
+///
+/// Represents a lock owner identified by principal name.
+///
+public class PrincipalLockOwner : LockOwner
{
///
- /// Represents a lock owner identified by principal name.
+ /// Initializes a new instance of the class.
///
- public class PrincipalLockOwner : LockOwner
+ /// Name of the principal.
+ public PrincipalLockOwner(string principalName)
{
- ///
- /// Initializes a new instance of the class.
- ///
- /// Name of the principal.
- public PrincipalLockOwner([NotNull] string principalName)
- {
- Check.NotNull(principalName, nameof(principalName));
- Value = principalName;
- }
-
- ///
- /// Gets a value representing an owner.
- ///
- public override string Value { get; }
+ Value = Guard.NotNull(principalName);
}
-}
+
+ ///
+ /// Gets a value representing an owner.
+ ///
+ public override string Value { get; }
+}
\ No newline at end of file
diff --git a/src/WebDAV-Client/Domain/WebDavProperty.cs b/src/WebDAV-Client/Domain/WebDavProperty.cs
index 4f2f6e2..aa229dc 100644
--- a/src/WebDAV-Client/Domain/WebDavProperty.cs
+++ b/src/WebDAV-Client/Domain/WebDavProperty.cs
@@ -1,38 +1,36 @@
using System.Xml.Linq;
+using Stef.Validation;
-namespace WebDav
+namespace WebDav;
+
+///
+/// Represents a WebDAV resource property.
+///
+public class WebDavProperty
{
///
- /// Represents a WebDAV resource property.
+ /// Initializes a new instance of the class.
///
- public class WebDavProperty
+ /// The property name.
+ /// The property value.
+ public WebDavProperty(XName name, string value)
{
- ///
- /// Initializes a new instance of the class.
- ///
- /// The property name.
- /// The property value.
- public WebDavProperty(XName name, string value)
- {
- Check.NotEmpty((name ?? "").ToString(), nameof(name));
-
- Name = name;
- Value = value;
- }
+ Name = Guard.NotNullOrEmpty((name ?? "").ToString());
+ Value = value;
+ }
- ///
- /// Gets the property name.
- ///
- public XName Name { get; private set; }
+ ///
+ /// Gets the property name.
+ ///
+ public XName Name { get; private set; }
- ///
- /// Gets the property value.
- ///
- public string Value { get; private set; }
+ ///
+ /// Gets the property value.
+ ///
+ public string Value { get; private set; }
- public override string ToString()
- {
- return string.Format("{{ Name: {0}, Value: {1} }}", Name, Value);
- }
+ public override string ToString()
+ {
+ return string.Format("{{ Name: {0}, Value: {1} }}", Name, Value);
}
-}
+}
\ No newline at end of file
diff --git a/src/WebDAV-Client/Domain/WebDavPropertyStatus.cs b/src/WebDAV-Client/Domain/WebDavPropertyStatus.cs
index 60c1c11..8e56664 100644
--- a/src/WebDAV-Client/Domain/WebDavPropertyStatus.cs
+++ b/src/WebDAV-Client/Domain/WebDavPropertyStatus.cs
@@ -1,63 +1,63 @@
using System.Xml.Linq;
+using Stef.Validation;
-namespace WebDav
+namespace WebDav;
+
+///
+/// Represents a status of an operation on a resource property.
+///
+public class WebDavPropertyStatus
{
///
- /// Represents a status of an operation on a resource property.
+ /// Initializes a new instance of the class.
+ ///
+ /// The property name.
+ /// The status code of the operation.
+ public WebDavPropertyStatus(XName name, int statusCode)
+ :this (name, statusCode, null)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The property name.
+ /// The status code of the operation.
+ /// The description of the operation.
+ public WebDavPropertyStatus(XName name, int statusCode, string description)
+ {
+ Guard.NotNullOrEmpty((name ?? "").ToString());
+
+ Name = name;
+ StatusCode = statusCode;
+ Description = description;
+ }
+
+ ///
+ /// Gets the property name.
+ ///
+ public XName Name { get; private set; }
+
+ ///
+ /// Gets the status code of the operation.
///
- public class WebDavPropertyStatus
+ public int StatusCode { get; private set; }
+
+ ///
+ /// Gets the description of the operation.
+ ///
+ public string Description { get; private set; }
+
+ ///
+ /// Gets a value indicating whether the operation on the property was successful.
+ ///
+ ///
+ /// true if the operation was successful; otherwise, false.
+ ///
+ public virtual bool IsSuccessful => StatusCode >= 200 && StatusCode <= 299;
+
+ public override string ToString()
{
- ///
- /// Initializes a new instance of the class.
- ///
- /// The property name.
- /// The status code of the operation.
- public WebDavPropertyStatus(XName name, int statusCode)
- :this (name, statusCode, null)
- {
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The property name.
- /// The status code of the operation.
- /// The description of the operation.
- public WebDavPropertyStatus(XName name, int statusCode, string description)
- {
- Check.NotEmpty((name ?? "").ToString(), nameof(name));
-
- Name = name;
- StatusCode = statusCode;
- Description = description;
- }
-
- ///
- /// Gets the property name.
- ///
- public XName Name { get; private set; }
-
- ///
- /// Gets the status code of the operation.
- ///
- public int StatusCode { get; private set; }
-
- ///
- /// Gets the description of the operation.
- ///
- public string Description { get; private set; }
-
- ///
- /// Gets a value indicating whether the operation on the property was successful.
- ///
- ///
- /// true if the operation was successfull; otherwise, false.
- ///
- public virtual bool IsSuccessful => StatusCode >= 200 && StatusCode <= 299;
-
- public override string ToString()
- {
- return string.Format("{{ Name: {0}, StatusCode: {1}, Description: {2} }}", Name, StatusCode, Description);
- }
+ return $"{{ Name: {Name}, StatusCode: {StatusCode}, Description: {Description} }}";
}
-}
+}
\ No newline at end of file
diff --git a/src/WebDAV-Client/Domain/WebDavResource.cs b/src/WebDAV-Client/Domain/WebDavResource.cs
index b904d87..37c41cb 100644
--- a/src/WebDAV-Client/Domain/WebDavResource.cs
+++ b/src/WebDAV-Client/Domain/WebDavResource.cs
@@ -1,273 +1,270 @@
using System;
using System.Collections.Generic;
-using JetBrains.Annotations;
+using Stef.Validation;
-namespace WebDav
+namespace WebDav;
+
+///
+/// Represents a WebDAV resource.
+///
+public class WebDavResource
{
///
- /// Represents a WebDAV resource.
+ /// Prevents a default instance of the class from being created.
+ ///
+ private WebDavResource()
+ {
+ Properties = new List();
+ PropertyStatuses = new List();
+ }
+
+ ///
+ /// Gets a collection locks on this resource.
+ ///
+ public IReadOnlyCollection ActiveLocks { get; private set; }
+
+ ///
+ /// Gets the content language of this resource.
+ ///
+ public string ContentLanguage { get; private set; }
+
+ ///
+ /// Gets the content length of this resource.
+ ///
+ public int? ContentLength { get; private set; }
+
+ ///
+ /// Gets the content type of this resource.
+ ///
+ public string ContentType { get; private set; }
+
+ ///
+ /// Gets the creation date of this resource.
+ ///
+ public DateTime? CreationDate { get; private set; }
+
+ ///
+ /// Gets the display name of this resource.
+ ///
+ public string DisplayName { get; private set; }
+
+ ///
+ /// Gets the ETag of this resource.
+ ///
+ public string ETag { get; private set; }
+
+ ///
+ /// Gets the URI of this resource.
+ ///
+ public string Uri { get; private set; }
+
+ ///
+ /// Gets a value indicating whether this resource is a collection.
+ ///
+ ///
+ /// true if this resource is a collection; otherwise, false. The default value is false.
+ ///
+ public bool IsCollection { get; private set; }
+
+ ///
+ /// Gets a value indicating whether this resource is hidden.
///
- public class WebDavResource
+ ///
+ /// true if this resource is hidden; otherwise, false. The default value is false.
+ ///
+ public bool IsHidden { get; private set; }
+
+ ///
+ /// Gets the last modified date of this resource.
+ ///
+ public DateTime? LastModifiedDate { get; private set; }
+
+ ///
+ /// Gets the collection of properties of this resource.
+ ///
+ public IReadOnlyCollection Properties { get; private set; }
+
+ ///
+ /// Gets the collection of property statuses of this resource.
+ ///
+ public IReadOnlyCollection PropertyStatuses { get; private set; }
+
+ ///
+ /// Represents a builder of the class.
+ ///
+ public class Builder
{
+ private IReadOnlyCollection _activeLocks;
+ private string _contentLanguage;
+ private int? _contentLength;
+ private string _contentType;
+ private DateTime? _creationDate;
+ private string _displayName;
+ private string _eTag;
+ private string _uri;
+ private bool _isCollection;
+ private bool _isHidden;
+ private DateTime? _lastModifiedDate;
+ private IReadOnlyCollection _properties;
+ private IReadOnlyCollection _propertyStatuses;
+
///
- /// Prevents a default instance of the class from being created.
+ /// Sets the ActiveLocks parameter of an instance of the class.
///
- private WebDavResource()
+ public Builder WithActiveLocks(IReadOnlyCollection activeLocks)
{
- Properties = new List();
- PropertyStatuses = new List();
+ _activeLocks = activeLocks;
+ return this;
}
///
- /// Gets a collection locks on this resource.
+ /// Sets the ContentLanguage parameter of an instance of the class.
///
- public IReadOnlyCollection ActiveLocks { get; private set; }
+ public Builder WithContentLanguage(string contentLanguage)
+ {
+ _contentLanguage = contentLanguage;
+ return this;
+ }
///
- /// Gets the content language of this resource.
+ /// Sets the ContentLength parameter of an instance of the class.
///
- public string ContentLanguage { get; private set; }
+ public Builder WithContentLength(int? contentLength)
+ {
+ _contentLength = contentLength;
+ return this;
+ }
///
- /// Gets the content length of this resource.
+ /// Sets the ContentType parameter of an instance of the class.
///
- public int? ContentLength { get; private set; }
+ public Builder WithContentType(string contentType)
+ {
+ _contentType = contentType;
+ return this;
+ }
///
- /// Gets the content type of this resource.
+ /// Sets the CreationDate parameter of an instance of the class.
///
- public string ContentType { get; private set; }
+ public Builder WithCreationDate(DateTime? creationDate)
+ {
+ _creationDate = creationDate;
+ return this;
+ }
///
- /// Gets the creation date of this resource.
+ /// Sets the DisplayName parameter of an instance of the class.
///
- public DateTime? CreationDate { get; private set; }
+ public Builder WithDisplayName(string displayName)
+ {
+ _displayName = displayName;
+ return this;
+ }
///
- /// Gets the display name of this resource.
+ /// Sets the ETag parameter of an instance of the class.
///
- public string DisplayName { get; private set; }
+ public Builder WithETag(string eTag)
+ {
+ _eTag = eTag;
+ return this;
+ }
///
- /// Gets the ETag of this resource.
+ /// Sets the Uri parameter of an instance of the class.
///
- public string ETag { get; private set; }
+ public Builder WithUri(string uri)
+ {
+ _uri = uri;
+ return this;
+ }
///
- /// Gets the URI of this resource.
+ /// Sets the IsCollection parameter of an instance of the class to true.
///
- public string Uri { get; private set; }
+ public Builder IsCollection()
+ {
+ _isCollection = true;
+ return this;
+ }
///
- /// Gets a value indicating whether this resource is a collection.
+ /// Sets the IsCollection parameter of an instance of the class to false.
///
- ///
- /// true if this resource is a collection; otherwise, false. The default value is false.
- ///
- public bool IsCollection { get; private set; }
+ public Builder IsNotCollection()
+ {
+ _isCollection = false;
+ return this;
+ }
+
+ ///
+ /// Sets the IsHidden parameter of an instance of the class to true.
+ ///
+ public Builder IsHidden()
+ {
+ _isHidden = true;
+ return this;
+ }
///
- /// Gets a value indicating whether this resource is hidden.
+ /// Sets the IsHidden parameter of an instance of the class to false.
///
- ///
- /// true if this resource is hidden; otherwise, false. The default value is false.
- ///
- public bool IsHidden { get; private set; }
+ public Builder IsNotHidden()
+ {
+ _isHidden = false;
+ return this;
+ }
///
- /// Gets the last modified date of this resource.
+ /// Sets the LastModifiedDate parameter of an instance of the class.
///
- public DateTime? LastModifiedDate { get; private set; }
+ public Builder WithLastModifiedDate(DateTime? lastModifiedDate)
+ {
+ _lastModifiedDate = lastModifiedDate;
+ return this;
+ }
///
- /// Gets the collection of properties of this resource.
+ /// Sets the Properties parameter of an instance of the class.
///
- public IReadOnlyCollection Properties { get; private set; }
+ public Builder WithProperties(IReadOnlyCollection properties)
+ {
+ _properties = Guard.NotNull(properties);
+ return this;
+ }
///
- /// Gets the collection of property statuses of this resource.
+ /// Sets the PropertyStatuses parameter of an instance of the class.
///
- public IReadOnlyCollection PropertyStatuses { get; private set; }
+ public Builder WithPropertyStatuses(IReadOnlyCollection propertyStatuses)
+ {
+ _propertyStatuses = Guard.NotNull(propertyStatuses);
+ return this;
+ }
///
- /// Represents a builder of the class.
+ /// Builds a new instance of the class.
///
- public class Builder
+ /// A new instance of the class.
+ public WebDavResource Build()
{
- private IReadOnlyCollection _activeLocks;
- private string _contentLanguage;
- private int? _contentLength;
- private string _contentType;
- private DateTime? _creationDate;
- private string _displayName;
- private string _eTag;
- private string _uri;
- private bool _isCollection;
- private bool _isHidden;
- private DateTime? _lastModifiedDate;
- private IReadOnlyCollection _properties;
- private IReadOnlyCollection _propertyStatuses;
-
- ///
- /// Sets the ActiveLocks parameter of an instance of the class.
- ///
- public Builder WithActiveLocks(IReadOnlyCollection activeLocks)
- {
- _activeLocks = activeLocks;
- return this;
- }
-
- ///
- /// Sets the ContentLanguage parameter of an instance of the class.
- ///
- public Builder WithContentLanguage(string contentLanguage)
- {
- _contentLanguage = contentLanguage;
- return this;
- }
-
- ///
- /// Sets the ContentLength parameter of an instance of the class.
- ///
- public Builder WithContentLength(int? contentLength)
- {
- _contentLength = contentLength;
- return this;
- }
-
- ///
- /// Sets the ContentType parameter of an instance of the class.
- ///
- public Builder WithContentType(string contentType)
- {
- _contentType = contentType;
- return this;
- }
-
- ///
- /// Sets the CreationDate parameter of an instance of the class.
- ///
- public Builder WithCreationDate(DateTime? creationDate)
- {
- _creationDate = creationDate;
- return this;
- }
-
- ///
- /// Sets the DisplayName parameter of an instance of the class.
- ///
- public Builder WithDisplayName(string displayName)
- {
- _displayName = displayName;
- return this;
- }
-
- ///
- /// Sets the ETag parameter of an instance of the class.
- ///
- public Builder WithETag(string eTag)
- {
- _eTag = eTag;
- return this;
- }
-
- ///
- /// Sets the Uri parameter of an instance of the class.
- ///
- public Builder WithUri(string uri)
- {
- _uri = uri;
- return this;
- }
-
- ///
- /// Sets the IsCollection parameter of an instance of the class to true.
- ///
- public Builder IsCollection()
- {
- _isCollection = true;
- return this;
- }
-
- ///
- /// Sets the IsCollection parameter of an instance of the class to false.
- ///
- public Builder IsNotCollection()
- {
- _isCollection = false;
- return this;
- }
-
- ///
- /// Sets the IsHidden parameter of an instance of the class to true.
- ///
- public Builder IsHidden()
- {
- _isHidden = true;
- return this;
- }
-
- ///
- /// Sets the IsHidden parameter of an instance of the class to false.
- ///
- public Builder IsNotHidden()
- {
- _isHidden = false;
- return this;
- }
-
- ///
- /// Sets the LastModifiedDate parameter of an instance of the class.
- ///
- public Builder WithLastModifiedDate(DateTime? lastModifiedDate)
- {
- _lastModifiedDate = lastModifiedDate;
- return this;
- }
-
- ///
- /// Sets the Properties parameter of an instance of the class.
- ///
- public Builder WithProperties([NotNull] IReadOnlyCollection properties)
- {
- Check.NotNull(properties, nameof(properties));
- _properties = properties;
- return this;
- }
-
- ///
- /// Sets the PropertyStatuses parameter of an instance of the class.
- ///
- public Builder WithPropertyStatuses([NotNull] IReadOnlyCollection propertyStatuses)
- {
- Check.NotNull(propertyStatuses, nameof(propertyStatuses));
- _propertyStatuses = propertyStatuses;
- return this;
- }
-
- ///
- /// Builds a new instance of the class.
- ///
- /// A new instance of the class.
- public WebDavResource Build()
+ return new WebDavResource
{
- return new WebDavResource
- {
- ActiveLocks = _activeLocks,
- ContentLanguage = _contentLanguage,
- ContentLength = _contentLength,
- ContentType = _contentType,
- CreationDate = _creationDate,
- DisplayName = _displayName,
- ETag = _eTag,
- Uri = _uri,
- IsCollection = _isCollection,
- IsHidden = _isHidden,
- LastModifiedDate = _lastModifiedDate,
- Properties = _properties,
- PropertyStatuses = _propertyStatuses
- };
- }
+ ActiveLocks = _activeLocks,
+ ContentLanguage = _contentLanguage,
+ ContentLength = _contentLength,
+ ContentType = _contentType,
+ CreationDate = _creationDate,
+ DisplayName = _displayName,
+ ETag = _eTag,
+ Uri = _uri,
+ IsCollection = _isCollection,
+ IsHidden = _isHidden,
+ LastModifiedDate = _lastModifiedDate,
+ Properties = _properties,
+ PropertyStatuses = _propertyStatuses
+ };
}
}
-}
+}
\ No newline at end of file
diff --git a/src/WebDAV-Client/Extensions/XDocumentExtensions.cs b/src/WebDAV-Client/Extensions/XDocumentExtensions.cs
index fd77427..86b8152 100644
--- a/src/WebDAV-Client/Extensions/XDocumentExtensions.cs
+++ b/src/WebDAV-Client/Extensions/XDocumentExtensions.cs
@@ -1,19 +1,18 @@
using System.Xml.Linq;
-namespace WebDav
+namespace WebDav;
+
+internal static class XDocumentExtensions
{
- internal static class XDocumentExtensions
+ public static XDocument? TryParse(string text)
{
- public static XDocument TryParse(string text)
+ try
+ {
+ return XDocument.Parse(text);
+ }
+ catch
{
- try
- {
- return XDocument.Parse(text);
- }
- catch
- {
- return null;
- }
+ return null;
}
}
-}
+}
\ No newline at end of file
diff --git a/src/WebDAV-Client/Infrastructure/WebDavDispatcher.cs b/src/WebDAV-Client/Infrastructure/WebDavDispatcher.cs
index f56a86b..0be0e76 100644
--- a/src/WebDAV-Client/Infrastructure/WebDavDispatcher.cs
+++ b/src/WebDAV-Client/Infrastructure/WebDavDispatcher.cs
@@ -3,56 +3,51 @@
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
-using JetBrains.Annotations;
+using Stef.Validation;
-namespace WebDav.Infrastructure
-{
- internal class WebDavDispatcher : IWebDavDispatcher, IDisposable
- {
- private readonly HttpClient _httpClient;
+namespace WebDav.Infrastructure;
- public WebDavDispatcher([NotNull] HttpClient httpClient)
- {
- Check.NotNull(httpClient, nameof(httpClient));
+internal class WebDavDispatcher : IWebDavDispatcher, IDisposable
+{
+ private readonly HttpClient _httpClient;
- _httpClient = httpClient;
- }
+ public WebDavDispatcher(HttpClient httpClient)
+ {
+ _httpClient = Guard.NotNull(httpClient);
+ }
- public Uri BaseAddress => _httpClient.BaseAddress;
+ public Uri BaseAddress => _httpClient.BaseAddress;
- public async Task Send(Uri requestUri, HttpMethod method, RequestParameters requestParams, CancellationToken cancellationToken)
+ public async Task Send(Uri requestUri, HttpMethod method, RequestParameters requestParams, CancellationToken cancellationToken)
+ {
+ using (var request = new HttpRequestMessage(method, requestUri))
{
- using (var request = new HttpRequestMessage(method, requestUri))
+ foreach (var header in requestParams.Headers)
{
- foreach (var header in requestParams.Headers)
- {
- request.Headers.Add(header.Key, header.Value);
- }
-
- if (requestParams.Content != null)
- {
- request.Content = requestParams.Content;
- if (!string.IsNullOrEmpty(requestParams.ContentType))
- request.Content.Headers.ContentType = new MediaTypeHeaderValue(requestParams.ContentType);
- }
-
- var response = await _httpClient.SendAsync(request, cancellationToken).ConfigureAwait(false);
- return new HttpResponse(response.Content, (int)response.StatusCode, response.ReasonPhrase);
+ request.Headers.Add(header.Key, header.Value);
}
- }
- #region IDisposable
+ if (requestParams.Content != null)
+ {
+ request.Content = requestParams.Content;
+ if (!string.IsNullOrEmpty(requestParams.ContentType))
+ request.Content.Headers.ContentType = new MediaTypeHeaderValue(requestParams.ContentType);
+ }
- public void Dispose()
- {
- DisposeManagedResources();
+ var response = await _httpClient.SendAsync(request, cancellationToken).ConfigureAwait(false);
+ return new HttpResponse(response.Content, (int)response.StatusCode, response.ReasonPhrase);
}
+ }
- protected virtual void DisposeManagedResources()
- {
- _httpClient?.Dispose();
- }
+ #region IDisposable
+ public void Dispose()
+ {
+ DisposeManagedResources();
+ }
- #endregion
+ protected virtual void DisposeManagedResources()
+ {
+ _httpClient?.Dispose();
}
-}
+ #endregion
+}
\ No newline at end of file
diff --git a/src/WebDAV-Client/Response/LockResponse.cs b/src/WebDAV-Client/Response/LockResponse.cs
index 1fe1547..32d38d0 100644
--- a/src/WebDAV-Client/Response/LockResponse.cs
+++ b/src/WebDAV-Client/Response/LockResponse.cs
@@ -1,65 +1,62 @@
-
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Linq;
-using JetBrains.Annotations;
+using Stef.Validation;
-namespace WebDav
+namespace WebDav;
+
+///
+/// Represents a response of the LOCK operation.
+///
+public class LockResponse : WebDavResponse
{
///
- /// Represents a response of the LOCK operation.
+ /// Initializes a new instance of the class.
///
- public class LockResponse : WebDavResponse
+ /// The status code of the operation.
+ public LockResponse(int statusCode)
+ : this(statusCode, null, new List())
{
- ///
- /// Initializes a new instance of the class.
- ///
- /// The status code of the operation.
- public LockResponse(int statusCode)
- : this(statusCode, null, new List())
- {
- }
+ }
- ///
- /// Initializes a new instance of the class.
- ///
- /// The status code of the response.
- /// The active locks of the resource.
- public LockResponse(int statusCode, IEnumerable activeLocks)
- : this(statusCode, null, activeLocks)
- {
- }
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The status code of the response.
+ /// The active locks of the resource.
+ public LockResponse(int statusCode, IEnumerable activeLocks)
+ : this(statusCode, null, activeLocks)
+ {
+ }
- ///
- /// Initializes a new instance of the class.
- ///
- /// The status code of the response.
- /// The description of the response.
- public LockResponse(int statusCode, string description)
- : this(statusCode, description, new List())
- {
- }
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The status code of the response.
+ /// The description of the response.
+ public LockResponse(int statusCode, string description)
+ : this(statusCode, description, new List())
+ {
+ }
- ///
- /// Initializes a new instance of the class.
- ///
- /// The status code of the response.
- /// The description of the response.
- /// The active locks of the resource.
- public LockResponse(int statusCode, string description, [NotNull] IEnumerable activeLocks)
- : base(statusCode, description)
- {
- Check.NotNull(activeLocks, nameof(activeLocks));
- ActiveLocks = activeLocks.ToList();
- }
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The status code of the response.
+ /// The description of the response.
+ /// The active locks of the resource.
+ public LockResponse(int statusCode, string description, IEnumerable activeLocks)
+ : base(statusCode, description)
+ {
+ ActiveLocks = Guard.NotNull(activeLocks).ToList();
+ }
- ///
- /// Gets a collection locks on this resource.
- ///
- public IReadOnlyCollection ActiveLocks { get; private set; }
+ ///
+ /// Gets a collection locks on this resource.
+ ///
+ public IReadOnlyCollection ActiveLocks { get; private set; }
- public override string ToString()
- {
- return string.Format("LOCK response - StatusCode: {0}, Description: {1}", StatusCode, Description);
- }
+ public override string ToString()
+ {
+ return $"LOCK response - StatusCode: {StatusCode}, Description: {Description}";
}
-}
+}
\ No newline at end of file
diff --git a/src/WebDAV-Client/Response/PropfindResponse.cs b/src/WebDAV-Client/Response/PropfindResponse.cs
index 37be3c0..0601564 100644
--- a/src/WebDAV-Client/Response/PropfindResponse.cs
+++ b/src/WebDAV-Client/Response/PropfindResponse.cs
@@ -1,64 +1,62 @@
using System.Collections.Generic;
using System.Linq;
-using JetBrains.Annotations;
+using Stef.Validation;
-namespace WebDav
+namespace WebDav;
+
+///
+/// Represents a response of the PROPFIND operation.
+///
+public class PropfindResponse : WebDavResponse
{
///
- /// Represents a response of the PROPFIND operation.
+ /// Initializes a new instance of the class.
///
- public class PropfindResponse : WebDavResponse
+ /// The status code of the operation.
+ public PropfindResponse(int statusCode)
+ : this(statusCode, null, new List())
{
- ///
- /// Initializes a new instance of the class.
- ///
- /// The status code of the operation.
- public PropfindResponse(int statusCode)
- : this(statusCode, null, new List())
- {
- }
+ }
- ///
- /// Initializes a new instance of the class.
- ///
- /// The status code of the response.
- /// The collection of WebDAV resources.
- public PropfindResponse(int statusCode, IEnumerable resources)
- : this(statusCode, null, resources)
- {
- }
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The status code of the response.
+ /// The collection of WebDAV resources.
+ public PropfindResponse(int statusCode, IEnumerable resources)
+ : this(statusCode, null, resources)
+ {
+ }
- ///
- /// Initializes a new instance of the class.
- ///
- /// The status code of the response.
- /// The description of the response.
- public PropfindResponse(int statusCode, string description)
- : this(statusCode, description, new List())
- {
- }
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The status code of the response.
+ /// The description of the response.
+ public PropfindResponse(int statusCode, string? description)
+ : this(statusCode, description, new List())
+ {
+ }
- ///
- /// Initializes a new instance of the class.
- ///
- /// The status code of the response.
- /// The description of the response.
- /// The collection of WebDAV resources.
- public PropfindResponse(int statusCode, string description, [NotNull] IEnumerable resources)
- : base(statusCode, description)
- {
- Check.NotNull(resources, nameof(resources));
- Resources = resources.ToList();
- }
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The status code of the response.
+ /// The description of the response.
+ /// The collection of WebDAV resources.
+ public PropfindResponse(int statusCode, string? description, IEnumerable resources)
+ : base(statusCode, description)
+ {
+ Resources = Guard.NotNull(resources).ToList();
+ }
- ///
- /// Gets the collection of WebDAV resources.
- ///
- public IReadOnlyCollection Resources { get; private set; }
+ ///
+ /// Gets the collection of WebDAV resources.
+ ///
+ public IReadOnlyCollection Resources { get; }
- public override string ToString()
- {
- return string.Format("PROPFIND WebDAV response - StatusCode: {0}, Description: {1}", StatusCode, Description);
- }
+ public override string ToString()
+ {
+ return $"PROPFIND WebDAV response - StatusCode: {StatusCode}, Description: {Description}";
}
-}
+}
\ No newline at end of file
diff --git a/src/WebDAV-Client/Response/PropfindResponseParser.cs b/src/WebDAV-Client/Response/PropfindResponseParser.cs
index f466783..843fdd6 100644
--- a/src/WebDAV-Client/Response/PropfindResponseParser.cs
+++ b/src/WebDAV-Client/Response/PropfindResponseParser.cs
@@ -4,77 +4,76 @@
using System.Linq;
using System.Xml.Linq;
using JetBrains.Annotations;
+using Stef.Validation;
-namespace WebDav.Response
+namespace WebDav.Response;
+
+internal class PropfindResponseParser : IResponseParser
{
- internal class PropfindResponseParser : IResponseParser
- {
- private readonly LockResponseParser _lockResponseParser;
+ private readonly LockResponseParser _lockResponseParser;
- public PropfindResponseParser([NotNull] LockResponseParser lockResponseParser)
- {
- Check.NotNull(lockResponseParser, nameof(lockResponseParser));
- _lockResponseParser = lockResponseParser;
- }
+ public PropfindResponseParser(LockResponseParser lockResponseParser)
+ {
+ _lockResponseParser = Guard.NotNull(lockResponseParser);
+ }
- public PropfindResponse Parse(string response, int statusCode, string description)
- {
- if (string.IsNullOrEmpty(response))
- return new PropfindResponse(statusCode, description);
+ public PropfindResponse Parse(string response, int statusCode, string description)
+ {
+ if (string.IsNullOrEmpty(response))
+ return new PropfindResponse(statusCode, description);
- var xresponse = XDocumentExtensions.TryParse(response);
- if (xresponse == null || xresponse.Root == null)
- return new PropfindResponse(statusCode, description);
+ var xresponse = XDocumentExtensions.TryParse(response);
+ if (xresponse == null || xresponse.Root == null)
+ return new PropfindResponse(statusCode, description);
- var resources = xresponse.Root.LocalNameElements("response", StringComparison.OrdinalIgnoreCase)
- .Select(ParseResource)
- .ToList();
- return new PropfindResponse(statusCode, description, resources);
- }
+ var resources = xresponse.Root.LocalNameElements("response", StringComparison.OrdinalIgnoreCase)
+ .Select(ParseResource)
+ .ToList();
+ return new PropfindResponse(statusCode, description, resources);
+ }
- private WebDavResource ParseResource(XElement xresponse)
- {
- var uriValue = xresponse.LocalNameElement("href", StringComparison.OrdinalIgnoreCase).GetValueOrNull();
- var propstats = MultiStatusParser.GetPropstats(xresponse);
- return CreateResource(uriValue, propstats);
- }
+ private WebDavResource ParseResource(XElement xresponse)
+ {
+ var uriValue = xresponse.LocalNameElement("href", StringComparison.OrdinalIgnoreCase).GetValueOrNull();
+ var propstats = MultiStatusParser.GetPropstats(xresponse);
+ return CreateResource(uriValue, propstats);
+ }
- private WebDavResource CreateResource(string uri, List propstats)
- {
- var properties = MultiStatusParser.GetProperties(propstats);
- var resourceBuilder = new WebDavResource.Builder()
- .WithActiveLocks(_lockResponseParser.ParseLockDiscovery(FindProp("{DAV:}lockdiscovery", properties)))
- .WithContentLanguage(PropertyValueParser.ParseString(FindProp("{DAV:}getcontentlanguage", properties)))
- .WithContentLength(PropertyValueParser.ParseInteger(FindProp("{DAV:}getcontentlength", properties)))
- .WithContentType(PropertyValueParser.ParseString(FindProp("{DAV:}getcontenttype", properties)))
- .WithCreationDate(PropertyValueParser.ParseDateTime(FindProp("{DAV:}creationdate", properties)))
- .WithDisplayName(PropertyValueParser.ParseString(FindProp("{DAV:}displayname", properties)))
- .WithETag(PropertyValueParser.ParseString(FindProp("{DAV:}getetag", properties)))
- .WithLastModifiedDate(PropertyValueParser.ParseDateTime(FindProp("{DAV:}getlastmodified", properties)))
- .WithProperties(new ReadOnlyCollection(properties.Select(x => new WebDavProperty(x.Name, x.GetInnerXml())).ToList()))
- .WithPropertyStatuses(MultiStatusParser.GetPropertyStatuses(propstats));
+ private WebDavResource CreateResource(string uri, List propstats)
+ {
+ var properties = MultiStatusParser.GetProperties(propstats);
+ var resourceBuilder = new WebDavResource.Builder()
+ .WithActiveLocks(_lockResponseParser.ParseLockDiscovery(FindProp("{DAV:}lockdiscovery", properties)))
+ .WithContentLanguage(PropertyValueParser.ParseString(FindProp("{DAV:}getcontentlanguage", properties)))
+ .WithContentLength(PropertyValueParser.ParseInteger(FindProp("{DAV:}getcontentlength", properties)))
+ .WithContentType(PropertyValueParser.ParseString(FindProp("{DAV:}getcontenttype", properties)))
+ .WithCreationDate(PropertyValueParser.ParseDateTime(FindProp("{DAV:}creationdate", properties)))
+ .WithDisplayName(PropertyValueParser.ParseString(FindProp("{DAV:}displayname", properties)))
+ .WithETag(PropertyValueParser.ParseString(FindProp("{DAV:}getetag", properties)))
+ .WithLastModifiedDate(PropertyValueParser.ParseDateTime(FindProp("{DAV:}getlastmodified", properties)))
+ .WithProperties(new ReadOnlyCollection(properties.Select(x => new WebDavProperty(x.Name, x.GetInnerXml())).ToList()))
+ .WithPropertyStatuses(MultiStatusParser.GetPropertyStatuses(propstats));
- var isHidden = PropertyValueParser.ParseInteger(FindProp("{DAV:}ishidden", properties)) > 0;
- if (isHidden)
- resourceBuilder.IsHidden();
+ var isHidden = PropertyValueParser.ParseInteger(FindProp("{DAV:}ishidden", properties)) > 0;
+ if (isHidden)
+ resourceBuilder.IsHidden();
- var isCollection = PropertyValueParser.ParseInteger(FindProp("{DAV:}iscollection", properties)) > 0 ||
- PropertyValueParser.ParseResourceType(FindProp("{DAV:}resourcetype", properties)) == ResourceType.Collection;
- if (isCollection)
- {
- resourceBuilder.IsCollection();
- resourceBuilder.WithUri(uri.TrimEnd('/') + "/");
- }
- else
- {
- resourceBuilder.WithUri(uri);
- }
- return resourceBuilder.Build();
+ var isCollection = PropertyValueParser.ParseInteger(FindProp("{DAV:}iscollection", properties)) > 0 ||
+ PropertyValueParser.ParseResourceType(FindProp("{DAV:}resourcetype", properties)) == ResourceType.Collection;
+ if (isCollection)
+ {
+ resourceBuilder.IsCollection();
+ resourceBuilder.WithUri(uri.TrimEnd('/') + "/");
}
-
- private static XElement FindProp(XName name, IEnumerable properties)
+ else
{
- return properties.FirstOrDefault(x => x.Name.Equals(name));
+ resourceBuilder.WithUri(uri);
}
+ return resourceBuilder.Build();
+ }
+
+ private static XElement? FindProp(XName name, IEnumerable properties)
+ {
+ return properties.FirstOrDefault(x => x.Name.Equals(name));
}
-}
+}
\ No newline at end of file
diff --git a/src/WebDAV-Client/Response/ProppatchResponse.cs b/src/WebDAV-Client/Response/ProppatchResponse.cs
index 384a2d3..ff9f512 100644
--- a/src/WebDAV-Client/Response/ProppatchResponse.cs
+++ b/src/WebDAV-Client/Response/ProppatchResponse.cs
@@ -1,63 +1,64 @@
using System.Collections.Generic;
-using JetBrains.Annotations;
+using System.Diagnostics.CodeAnalysis;
+using Stef.Validation;
-namespace WebDav
+namespace WebDav;
+
+///
+/// Represents a response of the PROPPATCH operation.
+///
+[SuppressMessage("ReSharper", "PossibleMultipleEnumeration")]
+public class ProppatchResponse : WebDavResponse
{
///
- /// Represents a response of the PROPPATCH operation.
+ /// Initializes a new instance of the class.
///
- public class ProppatchResponse : WebDavResponse
+ /// The status code of the operation.
+ public ProppatchResponse(int statusCode)
+ : this(statusCode, null, new List())
{
- ///
- /// Initializes a new instance of the class.
- ///
- /// The status code of the operation.
- public ProppatchResponse(int statusCode)
- : this(statusCode, null, new List())
- {
- }
+ }
- ///
- /// Initializes a new instance of the class.
- ///
- /// The status code of the response.
- /// The collection of property statuses.
- public ProppatchResponse(int statusCode, IEnumerable propertyStatuses)
- : this(statusCode, null, propertyStatuses)
- {
- }
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The status code of the response.
+ /// The collection of property statuses.
+ public ProppatchResponse(int statusCode, IEnumerable propertyStatuses)
+ : this(statusCode, null, propertyStatuses)
+ {
+ }
- ///
- /// Initializes a new instance of the class.
- ///
- /// The status code of the response.
- /// The description of the response.
- public ProppatchResponse(int statusCode, string description)
- : this(statusCode, description, new List())
- {
- }
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The status code of the response.
+ /// The description of the response.
+ public ProppatchResponse(int statusCode, string description)
+ : this(statusCode, description, new List())
+ {
+ }
- ///
- /// Initializes a new instance of the class.
- ///
- /// The status code of the response.
- /// The description of the response.
- /// The collection of property statuses.
- public ProppatchResponse(int statusCode, string description, [NotNull] IEnumerable propertyStatuses)
- : base(statusCode, description)
- {
- Check.NotNull(propertyStatuses, nameof(propertyStatuses));
- PropertyStatuses = new List(propertyStatuses);
- }
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The status code of the response.
+ /// The description of the response.
+ /// The collection of property statuses.
+ public ProppatchResponse(int statusCode, string? description, IEnumerable propertyStatuses)
+ : base(statusCode, description)
+ {
+ Guard.NotNull(propertyStatuses);
+ PropertyStatuses = new List(propertyStatuses);
+ }
- ///
- /// Gets the collection statuses of set/delete operation on the resource's properties.
- ///
- public IReadOnlyCollection PropertyStatuses { get; private set; }
+ ///
+ /// Gets the collection statuses of set/delete operation on the resource's properties.
+ ///
+ public IReadOnlyCollection PropertyStatuses { get; private set; }
- public override string ToString()
- {
- return string.Format("PROPPATCH WebDAV response - StatusCode: {0}, Description: {1}", StatusCode, Description);
- }
+ public override string ToString()
+ {
+ return $"PROPPATCH WebDAV response - StatusCode: {StatusCode}, Description: {Description}";
}
-}
+}
\ No newline at end of file
diff --git a/src/WebDAV-Client/Response/WebDavResponse.cs b/src/WebDAV-Client/Response/WebDavResponse.cs
index 88d1739..0546cc3 100644
--- a/src/WebDAV-Client/Response/WebDavResponse.cs
+++ b/src/WebDAV-Client/Response/WebDavResponse.cs
@@ -1,51 +1,50 @@
-namespace WebDav
+namespace WebDav;
+
+///
+/// Represents a response of a WebDAV operation.
+///
+public class WebDavResponse
{
///
- /// Represents a response of a WebDAV operation.
+ /// Initializes a new instance of the class.
///
- public class WebDavResponse
+ /// The status code of the operation.
+ public WebDavResponse(int statusCode)
{
- ///
- /// Initializes a new instance of the class.
- ///
- /// The status code of the operation.
- public WebDavResponse(int statusCode)
- {
- StatusCode = statusCode;
- }
+ StatusCode = statusCode;
+ }
- ///
- /// Initializes a new instance of the class.
- ///
- /// The status code of the response.
- /// The description of the response.
- public WebDavResponse(int statusCode, string description)
- {
- StatusCode = statusCode;
- Description = description;
- }
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The status code of the response.
+ /// The description of the response.
+ public WebDavResponse(int statusCode, string? description)
+ {
+ StatusCode = statusCode;
+ Description = description;
+ }
- ///
- /// Gets the status code of the response.
- ///
- public int StatusCode { get; private set; }
+ ///
+ /// Gets the status code of the response.
+ ///
+ public int StatusCode { get; }
- ///
- /// Gets the description of the response.
- ///
- public string Description { get; private set; }
+ ///
+ /// Gets the description of the response.
+ ///
+ public string? Description { get; }
- ///
- /// Gets a value indicating whether the operation was successful.
- ///
- ///
- /// true if the operation was successful; otherwise, false.
- ///
- public virtual bool IsSuccessful => StatusCode >= 200 && StatusCode <= 299;
+ ///
+ /// Gets a value indicating whether the operation was successful.
+ ///
+ ///
+ /// true if the operation was successful; otherwise, false.
+ ///
+ public virtual bool IsSuccessful => StatusCode is >= 200 and <= 299;
- public override string ToString()
- {
- return string.Format("WebDAV response - StatusCode: {0}, Description: {1}", StatusCode, Description);
- }
+ public override string ToString()
+ {
+ return $"WebDAV response - StatusCode: {StatusCode}, Description: {Description}";
}
-}
+}
\ No newline at end of file
diff --git a/src/WebDAV-Client/System/RuntimeUtils.cs b/src/WebDAV-Client/System/RuntimeUtils.cs
index 6d6a511..f1c7c16 100644
--- a/src/WebDAV-Client/System/RuntimeUtils.cs
+++ b/src/WebDAV-Client/System/RuntimeUtils.cs
@@ -1,10 +1,9 @@
using System;
// ReSharper disable once CheckNamespace
-namespace WebDav
+namespace WebDav;
+
+internal static class RuntimeUtils
{
- internal static class RuntimeUtils
- {
- public static bool IsBlazorWASM => Type.GetType("Mono.Runtime") != null;
- }
+ public static bool IsBlazorWASM => Type.GetType("Mono.Runtime") != null;
}
\ No newline at end of file
diff --git a/src/WebDAV-Client/Validation/Check.cs b/src/WebDAV-Client/Validation/Check.cs
deleted file mode 100644
index ffe4c18..0000000
--- a/src/WebDAV-Client/Validation/Check.cs
+++ /dev/null
@@ -1,128 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using JetBrains.Annotations;
-
-// Copied from https://github.com/aspnet/EntityFramework/blob/dev/src/Shared/Check.cs
-namespace WebDav
-{
- [DebuggerStepThrough]
- internal static class Check
- {
- [ContractAnnotation("value:null => halt")]
- public static T Condition([NoEnumeration] T value, [NotNull] Predicate condition, [InvokerParameterName] [NotNull] string parameterName)
- {
- NotNull(condition, nameof(condition));
- NotNull(value, nameof(value));
-
- if (!condition(value))
- {
- NotEmpty(parameterName, nameof(parameterName));
-
- throw new ArgumentOutOfRangeException(parameterName);
- }
-
- return value;
- }
-
- [ContractAnnotation("value:null => halt")]
- public static T NotNull([NoEnumeration] T value, [InvokerParameterName] [NotNull] string parameterName)
- {
- if (ReferenceEquals(value, null))
- {
- NotEmpty(parameterName, nameof(parameterName));
-
- throw new ArgumentNullException(parameterName);
- }
-
- return value;
- }
-
- [ContractAnnotation("value:null => halt")]
- public static T NotNull(
- [NoEnumeration] T value,
- [InvokerParameterName] [NotNull] string parameterName,
- [NotNull] string propertyName)
- {
- if (ReferenceEquals(value, null))
- {
- NotEmpty(parameterName, nameof(parameterName));
- NotEmpty(propertyName, nameof(propertyName));
-
- throw new ArgumentException(CoreStrings.ArgumentPropertyNull(propertyName, parameterName));
- }
-
- return value;
- }
-
- [ContractAnnotation("value:null => halt")]
- public static IList NotEmpty(IList value, [InvokerParameterName] [NotNull] string parameterName)
- {
- NotNull(value, parameterName);
-
- if (value.Count == 0)
- {
- NotEmpty(parameterName, nameof(parameterName));
-
- throw new ArgumentException(CoreStrings.CollectionArgumentIsEmpty(parameterName));
- }
-
- return value;
- }
-
- [ContractAnnotation("value:null => halt")]
- public static string NotEmpty(string value, [InvokerParameterName] [NotNull] string parameterName)
- {
- Exception e = null;
- if (ReferenceEquals(value, null))
- {
- e = new ArgumentNullException(parameterName);
- }
- else if (value.Trim().Length == 0)
- {
- e = new ArgumentException(CoreStrings.ArgumentIsEmpty(parameterName));
- }
-
- if (e != null)
- {
- NotEmpty(parameterName, nameof(parameterName));
-
- throw e;
- }
-
- return value;
- }
-
- public static string NullButNotEmpty(string value, [InvokerParameterName] [NotNull] string parameterName)
- {
- if (!ReferenceEquals(value, null)
- && (value.Length == 0))
- {
- NotEmpty(parameterName, nameof(parameterName));
-
- throw new ArgumentException(CoreStrings.ArgumentIsEmpty(parameterName));
- }
-
- return value;
- }
-
- public static IList HasNoNulls(IList value, [InvokerParameterName] [NotNull] string parameterName)
- where T : class
- {
- NotNull(value, parameterName);
-
- if (value.Any(e => e == null))
- {
- NotEmpty(parameterName, nameof(parameterName));
-
- throw new ArgumentException(parameterName);
- }
-
- return value;
- }
- }
-}
\ No newline at end of file
diff --git a/src/WebDAV-Client/Validation/CoreStrings.cs b/src/WebDAV-Client/Validation/CoreStrings.cs
deleted file mode 100644
index bc15356..0000000
--- a/src/WebDAV-Client/Validation/CoreStrings.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-using System;
-using JetBrains.Annotations;
-
-// copied from https://github.com/aspnet/EntityFramework/blob/dev/src/Microsoft.EntityFrameworkCore/Properties/CoreStrings.resx
-namespace WebDav
-{
- internal static class CoreStrings
- {
- ///
- /// The property '{property}' of the argument '{argument}' cannot be null.
- ///
- public static string ArgumentPropertyNull([CanBeNull] string property, [CanBeNull] string argument)
- {
- return string.Format($"The property '{property}' of the argument '{argument}' cannot be null.", property, argument);
- }
-
- ///
- /// The string argument '{argumentName}' cannot be empty.
- ///
- public static string ArgumentIsEmpty([CanBeNull] string argumentName)
- {
- return string.Format($"The string argument '{argumentName}' cannot be empty.", argumentName);
- }
-
- ///
- /// The entity type '{type}' provided for the argument '{argumentName}' must be a reference type.
- ///
- public static string InvalidEntityType([CanBeNull] Type type, [CanBeNull] string argumentName)
- {
- return string.Format($"The entity type '{type}' provided for the argument '{argumentName}' must be a reference type.", type, argumentName);
- }
-
- ///
- /// The collection argument '{argumentName}' must contain at least one element.
- ///
- public static string CollectionArgumentIsEmpty([CanBeNull] string argumentName)
- {
- return string.Format($"The collection argument '{argumentName}' must contain at least one element.", argumentName);
- }
- }
-}
\ No newline at end of file
diff --git a/src/WebDAV-Client/WebDAV-Client.csproj b/src/WebDAV-Client/WebDAV-Client.csproj
index 569b068..c30c84f 100644
--- a/src/WebDAV-Client/WebDAV-Client.csproj
+++ b/src/WebDAV-Client/WebDAV-Client.csproj
@@ -4,7 +4,7 @@
An easy-to-use async WebDAV client for .NET, .NETStandard, Blazor-WASM and Portable based on https://github.com/skazantsev/WebDavClient.
WebDAV-Client
WebDav
- 1.1.2.0
+ 1.1.3
Sergey Kazantsev;Stef Heyenrath
net45;net46;netstandard1.1;netstandard1.2;netstandard2.0;netstandard2.1;net6.0;net7.0
WebDAV-Client
@@ -16,6 +16,8 @@
git
https://github.com/stefh/WebDAV-Client
true
+ enable
+ 11
@@ -30,6 +32,7 @@
All
+
diff --git a/src/WebDAV-Client/WebDavClient.cs b/src/WebDAV-Client/WebDavClient.cs
index 44756c4..32e926a 100644
--- a/src/WebDAV-Client/WebDavClient.cs
+++ b/src/WebDAV-Client/WebDavClient.cs
@@ -7,894 +7,890 @@
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
+using Stef.Validation;
using WebDav.Infrastructure;
using WebDav.Request;
using WebDav.Response;
using RequestHeaders = System.Collections.Generic.List>;
-namespace WebDav
+namespace WebDav;
+
+///
+/// Represents a WebDAV client that can perform WebDAV operations.
+///
+public class WebDavClient : IDisposable
{
- ///
- /// Represents a WebDAV client that can perform WebDAV operations.
- ///
- public class WebDavClient : IDisposable
- {
- private const string MediaTypeXml = "application/xml";
- private static readonly Encoding DefaultEncoding = Encoding.UTF8;
- private static readonly Encoding FallbackEncoding = Encoding.UTF8;
+ private const string MediaTypeXml = "application/xml";
+ private static readonly Encoding DefaultEncoding = Encoding.UTF8;
+ private static readonly Encoding FallbackEncoding = Encoding.UTF8;
- private IWebDavDispatcher _dispatcher;
+ private IWebDavDispatcher _dispatcher;
- private IResponseParser _propfindResponseParser;
+ private IResponseParser _propfindResponseParser;
- private IResponseParser _proppatchResponseParser;
+ private IResponseParser _proppatchResponseParser;
- private IResponseParser _lockResponseParser;
+ private IResponseParser _lockResponseParser;
- ///
- /// Initializes a new instance of the class.
- ///
- [PublicAPI]
- public WebDavClient()
- : this(new WebDavClientParams())
- {
- }
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ [PublicAPI]
+ public WebDavClient() : this(new WebDavClientParams())
+ {
+ }
- ///
- /// Initializes a new instance of the class.
- ///
- /// The parameters of the WebDAV client.
- [PublicAPI]
- public WebDavClient([NotNull] WebDavClientParams @params) : this(ConfigureHttpClient(@params))
- {
- Check.NotNull(@params, nameof(@params));
- }
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The parameters of the WebDAV client.
+ [PublicAPI]
+ public WebDavClient(WebDavClientParams @params) : this(ConfigureHttpClient(@params))
+ {
+ Guard.NotNull(@params);
+ }
- ///
- /// Initializes a new instance of the class using a HttpClient.
- ///
- /// The HTTP client.
- [PublicAPI]
- public WebDavClient([NotNull] HttpClient httpClient)
- {
- Check.NotNull(httpClient, nameof(httpClient));
+ ///
+ /// Initializes a new instance of the class using a HttpClient.
+ ///
+ /// The HTTP client.
+ [PublicAPI]
+ public WebDavClient(HttpClient httpClient)
+ {
+ Guard.NotNull(httpClient);
- SetWebDavDispatcher(new WebDavDispatcher(httpClient));
+ SetWebDavDispatcher(new WebDavDispatcher(httpClient));
- var lockResponseParser = new LockResponseParser();
- SetPropfindResponseParser(new PropfindResponseParser(lockResponseParser));
- SetProppatchResponseParser(new ProppatchResponseParser());
- SetLockResponseParser(lockResponseParser);
- }
+ var lockResponseParser = new LockResponseParser();
+ SetPropfindResponseParser(new PropfindResponseParser(lockResponseParser));
+ SetProppatchResponseParser(new ProppatchResponseParser());
+ SetLockResponseParser(lockResponseParser);
+ }
- ///
- /// Retrieves properties defined on the resource identified by the request URI.
- ///
- /// A string that represents the request .
- /// An instance of
- public Task Propfind(string requestUri)
- {
- return Propfind(CreateUri(requestUri), new PropfindParameters());
- }
+ ///
+ /// Retrieves properties defined on the resource identified by the request URI.
+ ///
+ /// A string that represents the request .
+ /// An instance of
+ public Task Propfind(string requestUri)
+ {
+ return Propfind(CreateUri(requestUri), new PropfindParameters());
+ }
- ///
- /// Retrieves properties defined on the resource identified by the request URI.
- ///
- /// The to request.
- /// An instance of
- public Task Propfind(Uri requestUri)
- {
- return Propfind(requestUri, new PropfindParameters());
- }
+ ///
+ /// Retrieves properties defined on the resource identified by the request URI.
+ ///
+ /// The to request.
+ /// An instance of
+ public Task Propfind(Uri requestUri)
+ {
+ return Propfind(requestUri, new PropfindParameters());
+ }
- ///
- /// Retrieves properties defined on the resource identified by the request URI.
- ///
- /// A string that represents the request .
- /// Parameters of the PROPFIND operation.
- /// An instance of
- public Task Propfind(string requestUri, PropfindParameters parameters)
- {
- return Propfind(CreateUri(requestUri), parameters);
- }
+ ///
+ /// Retrieves properties defined on the resource identified by the request URI.
+ ///
+ /// A string that represents the request .
+ /// Parameters of the PROPFIND operation.
+ /// An instance of
+ public Task Propfind(string requestUri, PropfindParameters parameters)
+ {
+ return Propfind(CreateUri(requestUri), parameters);
+ }
- ///
- /// Retrieves properties defined on the resource identified by the request URI.
- ///
- /// The to request.
- /// Parameters of the PROPFIND operation.
- /// An instance of
- public async Task Propfind([NotNull] Uri requestUri, [NotNull] PropfindParameters parameters)
- {
- Check.NotNull(requestUri, nameof(requestUri));
- Check.NotNull(parameters, nameof(parameters));
+ ///
+ /// Retrieves properties defined on the resource identified by the request URI.
+ ///
+ /// The to request.
+ /// Parameters of the PROPFIND operation.
+ /// An instance of
+ public async Task Propfind(Uri requestUri, PropfindParameters parameters)
+ {
+ Guard.NotNull(requestUri);
+ Guard.NotNull(parameters);
+
+ var applyTo = parameters.ApplyTo ?? ApplyTo.Propfind.ResourceAndChildren;
+ var headers = new RequestHeaders
+ {
+ new KeyValuePair("Depth", DepthHeaderHelper.GetValueForPropfind(applyTo))
+ };
+ string requestBody = PropfindRequestBuilder.BuildRequestBody(parameters.CustomProperties, parameters.Namespaces);
+ var requestParams = new RequestParameters { Headers = headers, Content = new StringContent(requestBody, DefaultEncoding, MediaTypeXml) };
+ var response = await _dispatcher.Send(requestUri, WebDavMethod.Propfind, requestParams, parameters.CancellationToken);
+ var responseContent = await ReadContentAsString(response.Content).ConfigureAwait(false);
+ return _propfindResponseParser.Parse(responseContent, response.StatusCode, response.Description);
+ }
- var applyTo = parameters.ApplyTo ?? ApplyTo.Propfind.ResourceAndChildren;
- var headers = new RequestHeaders
- {
- new KeyValuePair("Depth", DepthHeaderHelper.GetValueForPropfind(applyTo))
- };
- string requestBody = PropfindRequestBuilder.BuildRequestBody(parameters.CustomProperties, parameters.Namespaces);
- var requestParams = new RequestParameters { Headers = headers, Content = new StringContent(requestBody, DefaultEncoding, MediaTypeXml) };
- var response = await _dispatcher.Send(requestUri, WebDavMethod.Propfind, requestParams, parameters.CancellationToken);
- var responseContent = await ReadContentAsString(response.Content).ConfigureAwait(false);
- return _propfindResponseParser.Parse(responseContent, response.StatusCode, response.Description);
- }
+ ///
+ /// Sets and/or removes properties defined on the resource identified by the request URI.
+ ///
+ /// A string that represents the request .
+ /// Parameters of the PROPPATCH operation.
+ /// An instance of
+ public Task Proppatch(string requestUri, ProppatchParameters parameters)
+ {
+ return Proppatch(CreateUri(requestUri), parameters);
+ }
- ///
- /// Sets and/or removes properties defined on the resource identified by the request URI.
- ///
- /// A string that represents the request .
- /// Parameters of the PROPPATCH operation.
- /// An instance of
- public Task Proppatch(string requestUri, ProppatchParameters parameters)
- {
- return Proppatch(CreateUri(requestUri), parameters);
- }
+ ///
+ /// Sets and/or removes properties defined on the resource identified by the request URI.
+ ///
+ /// The to request.
+ /// Parameters of the PROPPATCH operation.
+ /// An instance of
+ public async Task Proppatch(Uri requestUri, ProppatchParameters parameters)
+ {
+ Guard.NotNull(requestUri, nameof(requestUri));
+ Guard.NotNull(parameters, nameof(parameters));
- ///
- /// Sets and/or removes properties defined on the resource identified by the request URI.
- ///
- /// The to request.
- /// Parameters of the PROPPATCH operation.
- /// An instance of
- public async Task Proppatch([NotNull] Uri requestUri, [NotNull] ProppatchParameters parameters)
- {
- Check.NotNull(requestUri, nameof(requestUri));
- Check.NotNull(parameters, nameof(parameters));
+ var headers = new RequestHeaders();
+ if (!string.IsNullOrEmpty(parameters.LockToken))
+ headers.Add(new KeyValuePair("If", IfHeaderHelper.GetHeaderValue(parameters.LockToken)));
- var headers = new RequestHeaders();
- if (!string.IsNullOrEmpty(parameters.LockToken))
- headers.Add(new KeyValuePair("If", IfHeaderHelper.GetHeaderValue(parameters.LockToken)));
+ string requestBody = ProppatchRequestBuilder.BuildRequestBody(
+ parameters.PropertiesToSet,
+ parameters.PropertiesToRemove,
+ parameters.Namespaces);
- string requestBody = ProppatchRequestBuilder.BuildRequestBody(
- parameters.PropertiesToSet,
- parameters.PropertiesToRemove,
- parameters.Namespaces);
+ var requestParams = new RequestParameters { Headers = headers, Content = new StringContent(requestBody, DefaultEncoding, MediaTypeXml) };
- var requestParams = new RequestParameters { Headers = headers, Content = new StringContent(requestBody, DefaultEncoding, MediaTypeXml) };
+ var response = await _dispatcher.Send(requestUri, WebDavMethod.Proppatch, requestParams, parameters.CancellationToken);
+ var responseContent = await ReadContentAsString(response.Content).ConfigureAwait(false);
- var response = await _dispatcher.Send(requestUri, WebDavMethod.Proppatch, requestParams, parameters.CancellationToken);
- var responseContent = await ReadContentAsString(response.Content).ConfigureAwait(false);
+ return _proppatchResponseParser.Parse(responseContent, response.StatusCode, response.Description);
+ }
- return _proppatchResponseParser.Parse(responseContent, response.StatusCode, response.Description);
- }
+ ///
+ /// Creates a new collection resource at the location specified by the request URI.
+ ///
+ /// A string that represents the request .
+ /// An instance of
+ public Task Mkcol(string requestUri)
+ {
+ return Mkcol(CreateUri(requestUri), new MkColParameters());
+ }
- ///
- /// Creates a new collection resource at the location specified by the request URI.
- ///
- /// A string that represents the request .
- /// An instance of
- public Task Mkcol(string requestUri)
- {
- return Mkcol(CreateUri(requestUri), new MkColParameters());
- }
+ ///
+ /// Creates a new collection resource at the location specified by the request URI.
+ ///
+ /// The to request.
+ /// An instance of
+ public Task Mkcol(Uri requestUri)
+ {
+ return Mkcol(requestUri, new MkColParameters());
+ }
- ///
- /// Creates a new collection resource at the location specified by the request URI.
- ///
- /// The to request.
- /// An instance of
- public Task Mkcol(Uri requestUri)
- {
- return Mkcol(requestUri, new MkColParameters());
- }
+ ///
+ /// Creates a new collection resource at the location specified by the request URI.
+ ///
+ /// A string that represents the request .
+ /// Parameters of the MKCOL operation.
+ /// An instance of
+ public Task Mkcol(string requestUri, MkColParameters parameters)
+ {
+ return Mkcol(CreateUri(requestUri), parameters);
+ }
- ///
- /// Creates a new collection resource at the location specified by the request URI.
- ///
- /// A string that represents the request .
- /// Parameters of the MKCOL operation.
- /// An instance of
- public Task Mkcol(string requestUri, MkColParameters parameters)
- {
- return Mkcol(CreateUri(requestUri), parameters);
- }
+ ///
+ /// Creates a new collection resource at the location specified by the request URI.
+ ///
+ /// The to request.
+ /// Parameters of the MKCOL operation.
+ /// An instance of
+ public async Task Mkcol(Uri requestUri, MkColParameters parameters)
+ {
+ Guard.NotNull(requestUri, nameof(requestUri));
+ Guard.NotNull(parameters, nameof(parameters));
- ///
- /// Creates a new collection resource at the location specified by the request URI.
- ///
- /// The to request.
- /// Parameters of the MKCOL operation.
- /// An instance of
- public async Task Mkcol([NotNull] Uri requestUri, [NotNull] MkColParameters parameters)
- {
- Check.NotNull(requestUri, nameof(requestUri));
- Check.NotNull(parameters, nameof(parameters));
+ var headers = new RequestHeaders();
+ if (!string.IsNullOrEmpty(parameters.LockToken))
+ headers.Add(new KeyValuePair("If", IfHeaderHelper.GetHeaderValue(parameters.LockToken)));
- var headers = new RequestHeaders();
- if (!string.IsNullOrEmpty(parameters.LockToken))
- headers.Add(new KeyValuePair("If", IfHeaderHelper.GetHeaderValue(parameters.LockToken)));
+ var requestParams = new RequestParameters { Headers = headers };
- var requestParams = new RequestParameters { Headers = headers };
+ var response = await _dispatcher.Send(requestUri, WebDavMethod.Mkcol, requestParams, parameters.CancellationToken);
- var response = await _dispatcher.Send(requestUri, WebDavMethod.Mkcol, requestParams, parameters.CancellationToken);
+ return new WebDavResponse(response.StatusCode, response.Description);
+ }
- return new WebDavResponse(response.StatusCode, response.Description);
- }
+ ///
+ /// Retrieves the file identified by the request URI telling the server to return it without processing.
+ ///
+ /// A string that represents the request .
+ /// An instance of
+ public Task GetRawFile(string requestUri)
+ {
+ return GetFile(CreateUri(requestUri), false, CancellationToken.None);
+ }
- ///
- /// Retrieves the file identified by the request URI telling the server to return it without processing.
- ///
- /// A string that represents the request .
- /// An instance of
- public Task GetRawFile(string requestUri)
- {
- return GetFile(CreateUri(requestUri), false, CancellationToken.None);
- }
+ ///
+ /// Retrieves the file identified by the request URI telling the server to return it without processing.
+ ///
+ /// The to request.
+ /// An instance of
+ public Task GetRawFile(Uri requestUri)
+ {
+ return GetFile(requestUri, false, CancellationToken.None);
+ }
- ///
- /// Retrieves the file identified by the request URI telling the server to return it without processing.
- ///
- /// The to request.
- /// An instance of
- public Task GetRawFile(Uri requestUri)
- {
- return GetFile(requestUri, false, CancellationToken.None);
- }
+ ///
+ /// Retrieves the file identified by the request URI telling the server to return it without processing.
+ ///
+ /// A string that represents the request .
+ /// Parameters of the GET operation.
+ /// An instance of
+ public Task GetRawFile(string requestUri, GetFileParameters parameters)
+ {
+ return GetFile(CreateUri(requestUri), false, parameters.CancellationToken);
+ }
- ///
- /// Retrieves the file identified by the request URI telling the server to return it without processing.
- ///
- /// A string that represents the request .
- /// Parameters of the GET operation.
- /// An instance of
- public Task GetRawFile(string requestUri, GetFileParameters parameters)
- {
- return GetFile(CreateUri(requestUri), false, parameters.CancellationToken);
- }
+ ///
+ /// Retrieves the file identified by the request URI telling the server to return it without processing.
+ ///
+ /// The to request.
+ /// Parameters of the GET operation.
+ /// An instance of
+ public Task GetRawFile(Uri requestUri, GetFileParameters parameters)
+ {
+ return GetFile(requestUri, false, parameters.CancellationToken);
+ }
- ///
- /// Retrieves the file identified by the request URI telling the server to return it without processing.
- ///
- /// The to request.
- /// Parameters of the GET operation.
- /// An instance of
- public Task GetRawFile(Uri requestUri, GetFileParameters parameters)
- {
- return GetFile(requestUri, false, parameters.CancellationToken);
- }
+ ///
+ /// Retrieves the file identified by the request URI telling the server to return a processed response, if possible.
+ ///
+ /// A string that represents the request .
+ /// An instance of
+ public Task GetProcessedFile(string requestUri)
+ {
+ return GetFile(CreateUri(requestUri), true, CancellationToken.None);
+ }
- ///
- /// Retrieves the file identified by the request URI telling the server to return a processed response, if possible.
- ///
- /// A string that represents the request .
- /// An instance of
- public Task GetProcessedFile(string requestUri)
- {
- return GetFile(CreateUri(requestUri), true, CancellationToken.None);
- }
+ ///
+ /// Retrieves the file identified by the request URI telling the server to return a processed response, if possible.
+ ///
+ /// The to request.
+ /// An instance of
+ public Task GetProcessedFile(Uri requestUri)
+ {
+ return GetFile(requestUri, true, CancellationToken.None);
+ }
- ///
- /// Retrieves the file identified by the request URI telling the server to return a processed response, if possible.
- ///
- /// The to request.
- /// An instance of
- public Task GetProcessedFile(Uri requestUri)
- {
- return GetFile(requestUri, true, CancellationToken.None);
- }
+ ///
+ /// Retrieves the file identified by the request URI telling the server to return a processed response, if possible.
+ ///
+ /// A string that represents the request .
+ /// Parameters of the GET operation.
+ /// An instance of
+ public Task GetProcessedFile(string requestUri, GetFileParameters parameters)
+ {
+ return GetFile(CreateUri(requestUri), true, parameters.CancellationToken);
+ }
- ///
- /// Retrieves the file identified by the request URI telling the server to return a processed response, if possible.
- ///
- /// A string that represents the request .
- /// Parameters of the GET operation.
- /// An instance of
- public Task GetProcessedFile(string requestUri, GetFileParameters parameters)
- {
- return GetFile(CreateUri(requestUri), true, parameters.CancellationToken);
- }
+ ///
+ /// Retrieves the file identified by the request URI telling the server to return a processed response, if possible.
+ ///
+ /// The to request.
+ /// Parameters of the GET operation.
+ /// An instance of
+ public Task GetProcessedFile(Uri requestUri, GetFileParameters parameters)
+ {
+ return GetFile(requestUri, true, parameters.CancellationToken);
+ }
- ///
- /// Retrieves the file identified by the request URI telling the server to return a processed response, if possible.
- ///
- /// The to request.
- /// Parameters of the GET operation.
- /// An instance of
- public Task GetProcessedFile(Uri requestUri, GetFileParameters parameters)
- {
- return GetFile(requestUri, true, parameters.CancellationToken);
- }
+ internal virtual async Task GetFile(Uri requestUri, bool translate, CancellationToken cancellationToken)
+ {
+ Guard.NotNull(requestUri, nameof(requestUri));
- internal virtual async Task GetFile([NotNull] Uri requestUri, bool translate, CancellationToken cancellationToken)
+ var headers = new RequestHeaders
{
- Check.NotNull(requestUri, nameof(requestUri));
+ new KeyValuePair("Translate", translate ? "t" : "f")
+ };
- var headers = new RequestHeaders
- {
- new KeyValuePair("Translate", translate ? "t" : "f")
- };
+ var requestParams = new RequestParameters { Headers = headers };
- var requestParams = new RequestParameters { Headers = headers };
+ var response = await _dispatcher.Send(requestUri, HttpMethod.Get, requestParams, cancellationToken);
- var response = await _dispatcher.Send(requestUri, HttpMethod.Get, requestParams, cancellationToken);
+ var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
- var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
+ return new WebDavStreamResponse(response.StatusCode, response.Description, stream);
+ }
- return new WebDavStreamResponse(response.StatusCode, response.Description, stream);
- }
+ ///
+ /// Deletes the resource identified by the request URI.
+ ///
+ /// A string that represents the request .
+ /// An instance of
+ public Task Delete(string requestUri)
+ {
+ return Delete(CreateUri(requestUri), new DeleteParameters());
+ }
- ///
- /// Deletes the resource identified by the request URI.
- ///
- /// A string that represents the request .
- /// An instance of
- public Task Delete(string requestUri)
- {
- return Delete(CreateUri(requestUri), new DeleteParameters());
- }
+ ///
+ /// Deletes the resource identified by the request URI.
+ ///
+ /// The to request.
+ /// An instance of
+ public Task Delete(Uri requestUri)
+ {
+ return Delete(requestUri, new DeleteParameters());
+ }
- ///
- /// Deletes the resource identified by the request URI.
- ///
- /// The to request.
- /// An instance of
- public Task Delete(Uri requestUri)
- {
- return Delete(requestUri, new DeleteParameters());
- }
+ ///
+ /// Deletes the resource identified by the request URI.
+ ///
+ /// A string that represents the request .
+ /// Parameters of the DELETE operation.
+ /// An instance of
+ public Task Delete(string requestUri, DeleteParameters parameters)
+ {
+ return Delete(CreateUri(requestUri), parameters);
+ }
- ///
- /// Deletes the resource identified by the request URI.
- ///
- /// A string that represents the request .
- /// Parameters of the DELETE operation.
- /// An instance of
- public Task Delete(string requestUri, DeleteParameters parameters)
- {
- return Delete(CreateUri(requestUri), parameters);
- }
+ ///
+ /// Deletes the resource identified by the request URI.
+ ///
+ /// The to request.
+ /// Parameters of the DELETE operation.
+ /// An instance of
+ public async Task Delete(Uri requestUri, DeleteParameters parameters)
+ {
+ Guard.NotNull(requestUri, nameof(requestUri));
+ Guard.NotNull(parameters, nameof(parameters));
- ///
- /// Deletes the resource identified by the request URI.
- ///
- /// The to request.
- /// Parameters of the DELETE operation.
- /// An instance of
- public async Task Delete([NotNull] Uri requestUri, [NotNull] DeleteParameters parameters)
- {
- Check.NotNull(requestUri, nameof(requestUri));
- Check.NotNull(parameters, nameof(parameters));
+ var headers = new RequestHeaders();
+ if (!string.IsNullOrEmpty(parameters.LockToken))
+ headers.Add(new KeyValuePair("If", IfHeaderHelper.GetHeaderValue(parameters.LockToken)));
- var headers = new RequestHeaders();
- if (!string.IsNullOrEmpty(parameters.LockToken))
- headers.Add(new KeyValuePair("If", IfHeaderHelper.GetHeaderValue(parameters.LockToken)));
+ var requestParams = new RequestParameters { Headers = headers };
- var requestParams = new RequestParameters { Headers = headers };
+ var response = await _dispatcher.Send(requestUri, HttpMethod.Delete, requestParams, parameters.CancellationToken);
- var response = await _dispatcher.Send(requestUri, HttpMethod.Delete, requestParams, parameters.CancellationToken);
+ return new WebDavResponse(response.StatusCode, response.Description);
+ }
- return new WebDavResponse(response.StatusCode, response.Description);
- }
+ ///
+ /// Requests the resource to be stored under the request URI.
+ ///
+ /// A string that represents the request .
+ /// The stream of content of the resource.
+ /// An instance of
+ public Task PutFile(string requestUri, Stream stream)
+ {
+ return PutFile(CreateUri(requestUri), stream, new PutFileParameters());
+ }
- ///
- /// Requests the resource to be stored under the request URI.
- ///
- /// A string that represents the request .
- /// The stream of content of the resource.
- /// An instance of
- public Task PutFile(string requestUri, Stream stream)
- {
- return PutFile(CreateUri(requestUri), stream, new PutFileParameters());
- }
+ ///
+ /// Requests the resource to be stored under the request URI.
+ ///
+ /// The to request.
+ /// The stream of content of the resource.
+ /// An instance of
+ public Task PutFile(Uri requestUri, Stream stream)
+ {
+ return PutFile(requestUri, stream, new PutFileParameters());
+ }
- ///
- /// Requests the resource to be stored under the request URI.
- ///
- /// The to request.
- /// The stream of content of the resource.
- /// An instance of
- public Task PutFile(Uri requestUri, Stream stream)
- {
- return PutFile(requestUri, stream, new PutFileParameters());
- }
+ ///
+ /// Requests the resource to be stored under the request URI.
+ ///
+ /// A string that represents the request .
+ /// The stream of content of the resource.
+ /// The content type of the request body.
+ /// An instance of
+ public Task PutFile(string requestUri, Stream stream, string contentType)
+ {
+ return PutFile(CreateUri(requestUri), stream, new PutFileParameters { ContentType = contentType });
+ }
- ///
- /// Requests the resource to be stored under the request URI.
- ///
- /// A string that represents the request .
- /// The stream of content of the resource.
- /// The content type of the request body.
- /// An instance of
- public Task PutFile(string requestUri, Stream stream, string contentType)
- {
- return PutFile(CreateUri(requestUri), stream, new PutFileParameters { ContentType = contentType });
- }
+ ///
+ /// Requests the resource to be stored under the request URI.
+ ///
+ /// The to request.
+ /// The stream of content of the resource.
+ /// The content type of the request body.
+ /// An instance of
+ public Task PutFile(Uri requestUri, Stream stream, string contentType)
+ {
+ return PutFile(requestUri, stream, new PutFileParameters { ContentType = contentType });
+ }
- ///
- /// Requests the resource to be stored under the request URI.
- ///
- /// The to request.
- /// The stream of content of the resource.
- /// The content type of the request body.
- /// An instance of
- public Task PutFile(Uri requestUri, Stream stream, string contentType)
- {
- return PutFile(requestUri, stream, new PutFileParameters { ContentType = contentType });
- }
+ ///
+ /// Requests the resource to be stored under the request URI.
+ ///
+ /// A string that represents the request .
+ /// The stream of content of the resource.
+ /// Parameters of the PUT operation.
+ /// An instance of
+ public Task PutFile(string requestUri, Stream stream, PutFileParameters parameters)
+ {
+ return PutFile(CreateUri(requestUri), stream, parameters);
+ }
- ///
- /// Requests the resource to be stored under the request URI.
- ///
- /// A string that represents the request .
- /// The stream of content of the resource.
- /// Parameters of the PUT operation.
- /// An instance of
- public Task PutFile(string requestUri, Stream stream, PutFileParameters parameters)
- {
- return PutFile(CreateUri(requestUri), stream, parameters);
- }
+ ///
+ /// Requests the resource to be stored under the request URI.
+ ///
+ /// The to request.
+ /// The stream of content of the resource.
+ /// Parameters of the PUT operation.
+ /// An instance of
+ public async Task PutFile(Uri requestUri, Stream stream, PutFileParameters parameters)
+ {
+ Guard.NotNull(requestUri, nameof(requestUri));
+ Guard.NotNull(stream, nameof(stream));
+ Guard.NotNull(parameters, nameof(parameters));
- ///
- /// Requests the resource to be stored under the request URI.
- ///
- /// The to request.
- /// The stream of content of the resource.
- /// Parameters of the PUT operation.
- /// An instance of
- public async Task PutFile([NotNull] Uri requestUri, [NotNull] Stream stream, [NotNull] PutFileParameters parameters)
- {
- Check.NotNull(requestUri, nameof(requestUri));
- Check.NotNull(stream, nameof(stream));
- Check.NotNull(parameters, nameof(parameters));
+ var headers = new RequestHeaders();
+ if (!string.IsNullOrEmpty(parameters.LockToken))
+ headers.Add(new KeyValuePair("If", IfHeaderHelper.GetHeaderValue(parameters.LockToken)));
- var headers = new RequestHeaders();
- if (!string.IsNullOrEmpty(parameters.LockToken))
- headers.Add(new KeyValuePair("If", IfHeaderHelper.GetHeaderValue(parameters.LockToken)));
+ var requestParams = new RequestParameters { Headers = headers, Content = new StreamContent(stream), ContentType = parameters.ContentType };
- var requestParams = new RequestParameters { Headers = headers, Content = new StreamContent(stream), ContentType = parameters.ContentType };
+ var response = await _dispatcher.Send(requestUri, HttpMethod.Put, requestParams, parameters.CancellationToken);
- var response = await _dispatcher.Send(requestUri, HttpMethod.Put, requestParams, parameters.CancellationToken);
+ return new WebDavResponse(response.StatusCode, response.Description);
+ }
- return new WebDavResponse(response.StatusCode, response.Description);
- }
+ ///
+ /// Creates a duplicate of the source resource identified by the source URI in the destination resource identified by the destination URI.
+ ///
+ /// A string that represents the source .
+ /// A string that represents the destination .
+ /// An instance of
+ public Task Copy(string sourceUri, string destUri)
+ {
+ return Copy(CreateUri(sourceUri), CreateUri(destUri), new CopyParameters());
+ }
- ///
- /// Creates a duplicate of the source resource identified by the source URI in the destination resource identified by the destination URI.
- ///
- /// A string that represents the source .
- /// A string that represents the destination .
- /// An instance of
- public Task Copy(string sourceUri, string destUri)
- {
- return Copy(CreateUri(sourceUri), CreateUri(destUri), new CopyParameters());
- }
+ ///
+ /// Creates a duplicate of the source resource identified by the source URI in the destination resource identified by the destination URI.
+ ///
+ /// The source .
+ /// The destination .
+ /// An instance of
+ public Task Copy(Uri sourceUri, Uri destUri)
+ {
+ return Copy(sourceUri, destUri, new CopyParameters());
+ }
- ///
- /// Creates a duplicate of the source resource identified by the source URI in the destination resource identified by the destination URI.
- ///
- /// The source .
- /// The destination .
- /// An instance of
- public Task Copy(Uri sourceUri, Uri destUri)
- {
- return Copy(sourceUri, destUri, new CopyParameters());
- }
+ ///
+ /// Creates a duplicate of the source resource identified by the source URI in the destination resource identified by the destination URI.
+ ///
+ /// A string that represents the source .
+ /// A string that represents the destination .
+ /// Parameters of the COPY operation.
+ /// An instance of
+ public Task Copy(string sourceUri, string destUri, CopyParameters parameters)
+ {
+ return Copy(CreateUri(sourceUri), CreateUri(destUri), parameters);
+ }
- ///
- /// Creates a duplicate of the source resource identified by the source URI in the destination resource identified by the destination URI.
- ///
- /// A string that represents the source .
- /// A string that represents the destination .
- /// Parameters of the COPY operation.
- /// An instance of
- public Task Copy(string sourceUri, string destUri, CopyParameters parameters)
- {
- return Copy(CreateUri(sourceUri), CreateUri(destUri), parameters);
- }
+ ///
+ /// Creates a duplicate of the source resource identified by the source URI in the destination resource identified by the destination URI.
+ ///
+ /// The source .
+ /// The destination .
+ /// Parameters of the COPY operation.
+ /// An instance of
+ public async Task Copy(Uri sourceUri, Uri destUri, CopyParameters parameters)
+ {
+ Guard.NotNull(sourceUri, nameof(sourceUri));
+ Guard.NotNull(destUri, nameof(destUri));
+ Guard.NotNull(parameters, nameof(parameters));
- ///
- /// Creates a duplicate of the source resource identified by the source URI in the destination resource identified by the destination URI.
- ///
- /// The source .
- /// The destination .
- /// Parameters of the COPY operation.
- /// An instance of
- public async Task Copy([NotNull] Uri sourceUri, [NotNull] Uri destUri, [NotNull] CopyParameters parameters)
+ var applyTo = parameters.ApplyTo ?? ApplyTo.Copy.ResourceAndAncestors;
+ var headers = new RequestHeaders
{
- Check.NotNull(sourceUri, nameof(sourceUri));
- Check.NotNull(destUri, nameof(destUri));
- Check.NotNull(parameters, nameof(parameters));
+ new KeyValuePair("Destination", GetAbsoluteUri(destUri).ToString()),
+ new KeyValuePair("Depth", DepthHeaderHelper.GetValueForCopy(applyTo)),
+ new KeyValuePair("Overwrite", parameters.Overwrite ? "T" : "F")
+ };
- var applyTo = parameters.ApplyTo ?? ApplyTo.Copy.ResourceAndAncestors;
- var headers = new RequestHeaders
- {
- new KeyValuePair("Destination", GetAbsoluteUri(destUri).ToString()),
- new KeyValuePair("Depth", DepthHeaderHelper.GetValueForCopy(applyTo)),
- new KeyValuePair("Overwrite", parameters.Overwrite ? "T" : "F")
- };
+ if (!string.IsNullOrEmpty(parameters.DestLockToken))
+ headers.Add(new KeyValuePair("If", IfHeaderHelper.GetHeaderValue(parameters.DestLockToken)));
- if (!string.IsNullOrEmpty(parameters.DestLockToken))
- headers.Add(new KeyValuePair("If", IfHeaderHelper.GetHeaderValue(parameters.DestLockToken)));
+ var requestParams = new RequestParameters { Headers = headers };
- var requestParams = new RequestParameters { Headers = headers };
+ var response = await _dispatcher.Send(sourceUri, WebDavMethod.Copy, requestParams, parameters.CancellationToken);
- var response = await _dispatcher.Send(sourceUri, WebDavMethod.Copy, requestParams, parameters.CancellationToken);
+ return new WebDavResponse(response.StatusCode, response.Description);
+ }
- return new WebDavResponse(response.StatusCode, response.Description);
- }
+ ///
+ /// Moves the resource identified by the source URI to the destination identified by the destination URI.
+ ///
+ /// A string that represents the source .
+ /// A string that represents the destination .
+ /// An instance of
+ public Task Move(string sourceUri, string destUri)
+ {
+ return Move(CreateUri(sourceUri), CreateUri(destUri), new MoveParameters());
+ }
- ///
- /// Moves the resource identified by the source URI to the destination identified by the destination URI.
- ///
- /// A string that represents the source .
- /// A string that represents the destination .
- /// An instance of
- public Task Move(string sourceUri, string destUri)
- {
- return Move(CreateUri(sourceUri), CreateUri(destUri), new MoveParameters());
- }
+ ///
+ /// Moves the resource identified by the source URI to the destination identified by the destination URI.
+ ///
+ /// The source .
+ /// The destination .
+ /// An instance of
+ public Task Move(Uri sourceUri, Uri destUri)
+ {
+ return Move(sourceUri, destUri, new MoveParameters());
+ }
- ///
- /// Moves the resource identified by the source URI to the destination identified by the destination URI.
- ///
- /// The source .
- /// The destination .
- /// An instance of
- public Task Move(Uri sourceUri, Uri destUri)
- {
- return Move(sourceUri, destUri, new MoveParameters());
- }
+ ///
+ /// Moves the resource identified by the source URI to the destination identified by the destination URI.
+ ///
+ /// A string that represents the source .
+ /// A string that represents the destination .
+ /// Parameters of the MOVE operation.
+ /// An instance of
+ public Task Move(string sourceUri, string destUri, MoveParameters parameters)
+ {
+ return Move(CreateUri(sourceUri), CreateUri(destUri), parameters);
+ }
- ///
- /// Moves the resource identified by the source URI to the destination identified by the destination URI.
- ///
- /// A string that represents the source .
- /// A string that represents the destination .
- /// Parameters of the MOVE operation.
- /// An instance of
- public Task Move(string sourceUri, string destUri, MoveParameters parameters)
- {
- return Move(CreateUri(sourceUri), CreateUri(destUri), parameters);
- }
+ ///
+ /// Moves the resource identified by the source URI to the destination identified by the destination URI.
+ ///
+ /// The source .
+ /// The destination .
+ /// Parameters of the MOVE operation.
+ /// An instance of
+ public async Task Move(Uri sourceUri, Uri destUri, MoveParameters parameters)
+ {
+ Guard.NotNull(sourceUri, nameof(sourceUri));
+ Guard.NotNull(destUri, nameof(destUri));
+ Guard.NotNull(parameters, nameof(parameters));
- ///
- /// Moves the resource identified by the source URI to the destination identified by the destination URI.
- ///
- /// The source .
- /// The destination .
- /// Parameters of the MOVE operation.
- /// An instance of
- public async Task Move([NotNull] Uri sourceUri, [NotNull] Uri destUri, [NotNull] MoveParameters parameters)
+ var headers = new RequestHeaders
{
- Check.NotNull(sourceUri, nameof(sourceUri));
- Check.NotNull(destUri, nameof(destUri));
- Check.NotNull(parameters, nameof(parameters));
+ new KeyValuePair("Destination", GetAbsoluteUri(destUri).ToString()),
+ new KeyValuePair("Overwrite", parameters.Overwrite ? "T" : "F")
+ };
- var headers = new RequestHeaders
- {
- new KeyValuePair("Destination", GetAbsoluteUri(destUri).ToString()),
- new KeyValuePair("Overwrite", parameters.Overwrite ? "T" : "F")
- };
+ if (!string.IsNullOrEmpty(parameters.SourceLockToken))
+ headers.Add(new KeyValuePair("If", IfHeaderHelper.GetHeaderValue(parameters.SourceLockToken)));
- if (!string.IsNullOrEmpty(parameters.SourceLockToken))
- headers.Add(new KeyValuePair("If", IfHeaderHelper.GetHeaderValue(parameters.SourceLockToken)));
+ if (!string.IsNullOrEmpty(parameters.DestLockToken))
+ headers.Add(new KeyValuePair("If", IfHeaderHelper.GetHeaderValue(parameters.DestLockToken)));
- if (!string.IsNullOrEmpty(parameters.DestLockToken))
- headers.Add(new KeyValuePair("If", IfHeaderHelper.GetHeaderValue(parameters.DestLockToken)));
+ var requestParams = new RequestParameters { Headers = headers };
- var requestParams = new RequestParameters { Headers = headers };
+ var response = await _dispatcher.Send(sourceUri, WebDavMethod.Move, requestParams, parameters.CancellationToken);
- var response = await _dispatcher.Send(sourceUri, WebDavMethod.Move, requestParams, parameters.CancellationToken);
+ return new WebDavResponse(response.StatusCode, response.Description);
+ }
- return new WebDavResponse(response.StatusCode, response.Description);
- }
+ ///
+ /// Takes out a shared lock or refreshes an existing lock of the resource identified by the request URI.
+ ///
+ /// A string that represents the request .
+ /// An instance of
+ public Task Lock(string requestUri)
+ {
+ return Lock(CreateUri(requestUri), new LockParameters());
+ }
- ///
- /// Takes out a shared lock or refreshes an existing lock of the resource identified by the request URI.
- ///
- /// A string that represents the request .
- /// An instance of
- public Task Lock(string requestUri)
- {
- return Lock(CreateUri(requestUri), new LockParameters());
- }
+ ///
+ /// Takes out a shared lock or refreshes an existing lock of the resource identified by the request URI.
+ ///
+ /// The to request.
+ /// An instance of
+ public Task Lock(Uri requestUri)
+ {
+ return Lock(requestUri, new LockParameters());
+ }
- ///
- /// Takes out a shared lock or refreshes an existing lock of the resource identified by the request URI.
- ///
- /// The to request.
- /// An instance of
- public Task Lock(Uri requestUri)
- {
- return Lock(requestUri, new LockParameters());
- }
+ ///
+ /// Takes out a lock of any type or refreshes an existing lock of the resource identified by the request URI.
+ ///
+ /// A string that represents the request .
+ /// Parameters of the LOCK operation.
+ /// An instance of
+ public Task Lock(string requestUri, LockParameters parameters)
+ {
+ return Lock(CreateUri(requestUri), parameters);
+ }
- ///
- /// Takes out a lock of any type or refreshes an existing lock of the resource identified by the request URI.
- ///
- /// A string that represents the request .
- /// Parameters of the LOCK operation.
- /// An instance of
- public Task Lock(string requestUri, LockParameters parameters)
- {
- return Lock(CreateUri(requestUri), parameters);
- }
+ ///
+ /// Takes out a lock of any type or refreshes an existing lock of the resource identified by the request URI.
+ ///
+ /// The to request.
+ /// Parameters of the LOCK operation.
+ /// An instance of
+ public async Task Lock(Uri requestUri, LockParameters parameters)
+ {
+ Guard.NotNull(requestUri, nameof(requestUri));
+ Guard.NotNull(parameters, nameof(parameters));
- ///
- /// Takes out a lock of any type or refreshes an existing lock of the resource identified by the request URI.
- ///
- /// The to request.
- /// Parameters of the LOCK operation.
- /// An instance of
- public async Task Lock([NotNull] Uri requestUri, [NotNull] LockParameters parameters)
- {
- Check.NotNull(requestUri, nameof(requestUri));
- Check.NotNull(parameters, nameof(parameters));
+ var headers = new RequestHeaders();
+ if (parameters.ApplyTo.HasValue)
+ headers.Add(new KeyValuePair("Depth", DepthHeaderHelper.GetValueForLock(parameters.ApplyTo.Value)));
- var headers = new RequestHeaders();
- if (parameters.ApplyTo.HasValue)
- headers.Add(new KeyValuePair("Depth", DepthHeaderHelper.GetValueForLock(parameters.ApplyTo.Value)));
+ if (parameters.Timeout.HasValue)
+ headers.Add(new KeyValuePair("Timeout", $"Second-{parameters.Timeout.Value.TotalSeconds}"));
- if (parameters.Timeout.HasValue)
- headers.Add(new KeyValuePair("Timeout", $"Second-{parameters.Timeout.Value.TotalSeconds}"));
+ string requestBody = LockRequestBuilder.BuildRequestBody(parameters);
- string requestBody = LockRequestBuilder.BuildRequestBody(parameters);
+ var requestParams = new RequestParameters { Headers = headers, Content = new StringContent(requestBody, DefaultEncoding, MediaTypeXml) };
- var requestParams = new RequestParameters { Headers = headers, Content = new StringContent(requestBody, DefaultEncoding, MediaTypeXml) };
+ var response = await _dispatcher.Send(requestUri, WebDavMethod.Lock, requestParams, parameters.CancellationToken);
- var response = await _dispatcher.Send(requestUri, WebDavMethod.Lock, requestParams, parameters.CancellationToken);
+ if (!response.IsSuccessful)
+ return new LockResponse(response.StatusCode, response.Description);
- if (!response.IsSuccessful)
- return new LockResponse(response.StatusCode, response.Description);
+ var responseContent = await ReadContentAsString(response.Content).ConfigureAwait(false);
- var responseContent = await ReadContentAsString(response.Content).ConfigureAwait(false);
+ return _lockResponseParser.Parse(responseContent, response.StatusCode, response.Description);
+ }
- return _lockResponseParser.Parse(responseContent, response.StatusCode, response.Description);
- }
+ ///
+ /// Removes the lock identified by the lock token from the resource identified by the request URI.
+ ///
+ /// A string that represents the request .
+ /// The resource lock token.
+ /// An instance of
+ public Task Unlock(string requestUri, string lockToken)
+ {
+ return Unlock(CreateUri(requestUri), new UnlockParameters(lockToken));
+ }
- ///
- /// Removes the lock identified by the lock token from the resource identified by the request URI.
- ///
- /// A string that represents the request .
- /// The resource lock token.
- /// An instance of
- public Task Unlock(string requestUri, string lockToken)
- {
- return Unlock(CreateUri(requestUri), new UnlockParameters(lockToken));
- }
+ ///
+ /// Removes the lock identified by the lock token from the resource identified by the request URI.
+ ///
+ /// The to request.
+ /// The resource lock token.
+ /// An instance of
+ public Task Unlock(Uri requestUri, string lockToken)
+ {
+ return Unlock(requestUri, new UnlockParameters(lockToken));
+ }
- ///
- /// Removes the lock identified by the lock token from the resource identified by the request URI.
- ///
- /// The to request.
- /// The resource lock token.
- /// An instance of
- public Task Unlock(Uri requestUri, string lockToken)
- {
- return Unlock(requestUri, new UnlockParameters(lockToken));
- }
+ ///
+ /// Removes the lock identified by the lock token from the resource identified by the request URI.
+ ///
+ /// A string that represents the request .
+ /// Parameters of the UNLOCK operation.
+ /// An instance of
+ public Task Unlock(string requestUri, UnlockParameters parameters)
+ {
+ return Unlock(CreateUri(requestUri), parameters);
+ }
- ///
- /// Removes the lock identified by the lock token from the resource identified by the request URI.
- ///
- /// A string that represents the request .
- /// Parameters of the UNLOCK operation.
- /// An instance of
- public Task Unlock(string requestUri, UnlockParameters parameters)
- {
- return Unlock(CreateUri(requestUri), parameters);
- }
+ ///
+ /// Removes the lock identified by the lock token from the resource identified by the request URI.
+ ///
+ /// The to request.
+ /// Parameters of the UNLOCK operation.
+ /// An instance of
+ public async Task Unlock(Uri requestUri, UnlockParameters parameters)
+ {
+ Guard.NotNull(requestUri, nameof(requestUri));
+ Guard.NotNull(parameters, nameof(parameters));
- ///
- /// Removes the lock identified by the lock token from the resource identified by the request URI.
- ///
- /// The to request.
- /// Parameters of the UNLOCK operation.
- /// An instance of
- public async Task Unlock([NotNull] Uri requestUri, [NotNull] UnlockParameters parameters)
+ var headers = new RequestHeaders
{
- Check.NotNull(requestUri, nameof(requestUri));
- Check.NotNull(parameters, nameof(parameters));
+ new KeyValuePair("Lock-Token", $"<{parameters.LockToken}>")
+ };
- var headers = new RequestHeaders
- {
- new KeyValuePair("Lock-Token", $"<{parameters.LockToken}>")
- };
+ var requestParams = new RequestParameters { Headers = headers };
- var requestParams = new RequestParameters { Headers = headers };
+ var response = await _dispatcher.Send(requestUri, WebDavMethod.Unlock, requestParams, parameters.CancellationToken);
- var response = await _dispatcher.Send(requestUri, WebDavMethod.Unlock, requestParams, parameters.CancellationToken);
+ return new WebDavResponse(response.StatusCode, response.Description);
+ }
- return new WebDavResponse(response.StatusCode, response.Description);
- }
+ ///
+ /// Sets the dispatcher of WebDAV requests.
+ ///
+ /// The dispatcher of WebDAV http requests.
+ /// This instance of to support chain calls.
+ internal WebDavClient SetWebDavDispatcher(IWebDavDispatcher dispatcher)
+ {
+ Guard.NotNull(dispatcher, nameof(dispatcher));
+ _dispatcher = dispatcher;
+ return this;
+ }
- ///
- /// Sets the dispatcher of WebDAV requests.
- ///
- /// The dispatcher of WebDAV http requests.
- /// This instance of to support chain calls.
- internal WebDavClient SetWebDavDispatcher([NotNull] IWebDavDispatcher dispatcher)
- {
- Check.NotNull(dispatcher, nameof(dispatcher));
- _dispatcher = dispatcher;
- return this;
- }
+ ///
+ /// Sets the parser of PROPFIND responses.
+ ///
+ /// The parser of WebDAV PROPFIND responses.
+ /// This instance of to support chain calls.
+ internal WebDavClient SetPropfindResponseParser(IResponseParser responseParser)
+ {
+ Guard.NotNull(responseParser, nameof(responseParser));
+ _propfindResponseParser = responseParser;
+ return this;
+ }
- ///
- /// Sets the parser of PROPFIND responses.
- ///
- /// The parser of WebDAV PROPFIND responses.
- /// This instance of to support chain calls.
- internal WebDavClient SetPropfindResponseParser([NotNull] IResponseParser responseParser)
- {
- Check.NotNull(responseParser, nameof(responseParser));
- _propfindResponseParser = responseParser;
- return this;
- }
+ ///
+ /// Sets the parser of PROPPATCH responses.
+ ///
+ /// The parser of WebDAV PROPPATCH responses.
+ /// This instance of to support chain calls.
+ internal WebDavClient SetProppatchResponseParser(IResponseParser responseParser)
+ {
+ Guard.NotNull(responseParser, nameof(responseParser));
+ _proppatchResponseParser = responseParser;
+ return this;
+ }
- ///
- /// Sets the parser of PROPPATCH responses.
- ///
- /// The parser of WebDAV PROPPATCH responses.
- /// This instance of to support chain calls.
- internal WebDavClient SetProppatchResponseParser([NotNull] IResponseParser responseParser)
- {
- Check.NotNull(responseParser, nameof(responseParser));
- _proppatchResponseParser = responseParser;
- return this;
- }
+ ///
+ /// Sets the parser of LOCK responses.
+ ///
+ /// The parser of WebDAV LOCK responses.
+ /// This instance of to support chain calls.
+ internal WebDavClient SetLockResponseParser(IResponseParser responseParser)
+ {
+ Guard.NotNull(responseParser, nameof(responseParser));
+ _lockResponseParser = responseParser;
+ return this;
+ }
- ///
- /// Sets the parser of LOCK responses.
- ///
- /// The parser of WebDAV LOCK responses.
- /// This instance of to support chain calls.
- internal WebDavClient SetLockResponseParser([NotNull] IResponseParser responseParser)
+ private static HttpClient ConfigureHttpClient(WebDavClientParams @params, HttpClient? httpClient)
+ {
+ var httpMessageHandler = @params.HttpMessageHandler;
+ if (httpMessageHandler == null)
{
- Check.NotNull(responseParser, nameof(responseParser));
- _lockResponseParser = responseParser;
- return this;
- }
+ var httpHandler = new HttpClientHandler();
- private static HttpClient ConfigureHttpClient(WebDavClientParams @params)
- {
- HttpMessageHandler httpMessageHandler = @params.HttpMessageHandler;
- if (httpMessageHandler == null)
+ // Fixes for Blazor WASM
+ if (!RuntimeUtils.IsBlazorWASM)
{
- var httpHandler = new HttpClientHandler();
+ httpHandler.UseDefaultCredentials = @params.UseDefaultCredentials;
+ httpHandler.PreAuthenticate = @params.PreAuthenticate;
+ httpHandler.UseProxy = @params.UseProxy;
- // Fixes for Blazor WASM
- if (!RuntimeUtils.IsBlazorWASM)
+ if (@params.Credentials != null)
{
- httpHandler.UseDefaultCredentials = @params.UseDefaultCredentials;
- httpHandler.PreAuthenticate = @params.PreAuthenticate;
- httpHandler.UseProxy = @params.UseProxy;
-
- if (@params.Credentials != null)
- {
- httpHandler.Credentials = @params.Credentials;
- }
-
- if (@params.Proxy != null)
- {
- httpHandler.Proxy = @params.Proxy;
- }
+ httpHandler.Credentials = @params.Credentials;
}
- // Fix for Blazor WASM
- if (httpHandler.SupportsAutomaticDecompression)
+ if (@params.Proxy != null)
{
- httpHandler.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
+ httpHandler.Proxy = @params.Proxy;
}
-
- httpMessageHandler = httpHandler;
- }
-
- HttpClient httpClient;
- if (RuntimeUtils.IsBlazorWASM)
- {
- httpClient = new HttpClient
- {
- BaseAddress = @params.BaseAddress,
- Timeout = @params.Timeout
- };
- }
- else
- {
- httpClient = new HttpClient(httpMessageHandler, true)
- {
- BaseAddress = @params.BaseAddress,
- Timeout = @params.Timeout
- };
}
- foreach (var header in @params.DefaultRequestHeaders)
+ // Fix for Blazor WASM
+ if (httpHandler.SupportsAutomaticDecompression)
{
- httpClient.DefaultRequestHeaders.Add(header.Key, header.Value);
+ httpHandler.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
}
- return httpClient;
+ httpMessageHandler = httpHandler;
}
- private static Uri CreateUri(string requestUri)
+ HttpClient newHttpClient;
+ if (RuntimeUtils.IsBlazorWASM)
{
- return !string.IsNullOrEmpty(requestUri) ? new Uri(requestUri, UriKind.RelativeOrAbsolute) : null;
+ newHttpClient = new HttpClient
+ {
+ BaseAddress = @params.BaseAddress,
+ Timeout = @params.Timeout
+ };
}
-
- private static Exception CreateInvalidUriException()
+ else
{
- return new InvalidOperationException("An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set.");
+ newHttpClient = new HttpClient(httpMessageHandler, true)
+ {
+ BaseAddress = @params.BaseAddress,
+ Timeout = @params.Timeout
+ };
}
- private static Encoding GetResponseEncoding(HttpContent content)
+ foreach (var header in @params.DefaultRequestHeaders)
{
- if (content.Headers.ContentType?.CharSet == null)
- {
- return FallbackEncoding;
- }
+ newHttpClient.DefaultRequestHeaders.Add(header.Key, header.Value);
+ }
- try
- {
- return Encoding.GetEncoding(content.Headers.ContentType.CharSet);
- }
- catch (ArgumentException)
- {
- return FallbackEncoding;
- }
+ return newHttpClient;
+ }
+
+ private static Uri? CreateUri(string requestUri)
+ {
+ return !string.IsNullOrEmpty(requestUri) ? new Uri(requestUri, UriKind.RelativeOrAbsolute) : null;
+ }
+
+ private static Exception CreateInvalidUriException()
+ {
+ return new InvalidOperationException("An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set.");
+ }
+
+ private static Encoding GetResponseEncoding(HttpContent content)
+ {
+ if (content.Headers.ContentType?.CharSet == null)
+ {
+ return FallbackEncoding;
}
- private static async Task ReadContentAsString(HttpContent content)
+ try
+ {
+ return Encoding.GetEncoding(content.Headers.ContentType.CharSet);
+ }
+ catch (ArgumentException)
{
- byte[] bytes = await content.ReadAsByteArrayAsync();
- Encoding encoding = GetResponseEncoding(content);
+ return FallbackEncoding;
+ }
+ }
+
+ private static async Task ReadContentAsString(HttpContent content)
+ {
+ byte[] bytes = await content.ReadAsByteArrayAsync();
+ Encoding encoding = GetResponseEncoding(content);
#if NETSTANDARD1_1 || NETSTANDARD1_2 || PORTABLE
- return encoding.GetString(bytes, 0, bytes.Length);
+ return encoding.GetString(bytes, 0, bytes.Length);
#else
- return encoding.GetString(bytes);
+ return encoding.GetString(bytes);
#endif
- }
+ }
- private Uri GetAbsoluteUri(Uri uri)
+ private Uri GetAbsoluteUri(Uri uri)
+ {
+ if (uri == null && _dispatcher.BaseAddress == null)
{
- if (uri == null && _dispatcher.BaseAddress == null)
- {
- throw CreateInvalidUriException();
- }
-
- if (uri == null)
- {
- return _dispatcher.BaseAddress;
- }
-
- if (uri.IsAbsoluteUri)
- {
- return uri;
- }
-
- if (_dispatcher.BaseAddress == null)
- {
- throw CreateInvalidUriException();
- }
-
- return new Uri(_dispatcher.BaseAddress, uri);
+ throw CreateInvalidUriException();
}
- #region IDisposable
+ if (uri == null)
+ {
+ return _dispatcher.BaseAddress;
+ }
- ///
- /// Performs application-defined tasks associated with freeing, releasing, or resetting managed/unmanaged resources.
- /// Disposes the underlying HttpClient.
- ///
- public void Dispose()
+ if (uri.IsAbsoluteUri)
{
- DisposeManagedResources();
+ return uri;
}
- ///
- /// Disposes the managed resources.
- ///
- protected virtual void DisposeManagedResources()
+ if (_dispatcher.BaseAddress == null)
{
- var disposableDispatcher = _dispatcher as IDisposable;
- if (disposableDispatcher != null)
- {
- disposableDispatcher.Dispose();
- }
+ throw CreateInvalidUriException();
}
- #endregion
+ return new Uri(_dispatcher.BaseAddress, uri);
+ }
+
+ #region IDisposable
+ ///
+ /// Performs application-defined tasks associated with freeing, releasing, or resetting managed/unmanaged resources.
+ /// Disposes the underlying HttpClient.
+ ///
+ public void Dispose()
+ {
+ DisposeManagedResources();
+ }
+
+ ///
+ /// Disposes the managed resources.
+ ///
+ protected virtual void DisposeManagedResources()
+ {
+ if (_dispatcher is IDisposable disposableDispatcher)
+ {
+ disposableDispatcher.Dispose();
+ }
}
-}
+ #endregion
+}
\ No newline at end of file