/// <inheritdoc /> public async Task DeleteAsync(RemoteCollectionTarget target, CancellationToken cancellationToken) { using (var response = await Client.DeleteAsync(target.DestinationUrl, cancellationToken).ConfigureAwait(false)) { response.EnsureSuccessStatusCode(); } }
/// <inheritdoc /> public Task <IReadOnlyCollection <XName> > SetPropertiesAsync(RemoteCollectionTarget target, IEnumerable <IUntypedWriteableProperty> properties, CancellationToken cancellationToken) { return(SetPropertiesAsync(target.DestinationUrl, properties, cancellationToken)); }
/// <inheritdoc /> public abstract Task ExecuteAsync(ICollection source, RemoteCollectionTarget destination, CancellationToken cancellationToken);
/// <inheritdoc /> public async Task <ITarget> GetAsync(RemoteCollectionTarget collection, string name, CancellationToken cancellationToken) { var requestData = new propfind() { ItemsElementName = new[] { ItemsChoiceType1.prop, }, Items = new object[] { new prop() { Any = new[] { new XElement(Props.Live.ResourceTypeProperty.PropertyName), }, }, }, }; multistatus result; var targetUrl = collection.DestinationUrl.Append(name, false); using (var httpRequest = new HttpRequestMessage(_propFindHttpMethod, targetUrl) { Headers = { { "Depth", DepthHeader.Zero.Value }, }, Content = CreateContent(_propFindSerializer, requestData), }) { using (var httpResponse = await Client.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false)) { if (httpResponse.StatusCode == HttpStatusCode.NotFound) { return(new RemoteMissingTarget(collection, targetUrl, name, this)); } var resultDoc = await ReadResponseAsync(httpResponse).ConfigureAwait(false); if (resultDoc == null) { throw new RemoteTargetException("The destination server didn't return a response", targetUrl); } result = Parse(targetUrl, httpResponse, resultDoc); } } if (result.response == null || result.response.Length == 0) { throw new RemoteTargetException("The destination server didn't return a response", targetUrl); } if (result.response.Length != 1) { throw new RemoteTargetException("Received more than one multi-status response", targetUrl); } var response = result.response[0]; var hrefs = response.GetHrefs().Select(x => new Uri(x, UriKind.RelativeOrAbsolute)).ToList(); if (hrefs.Count == 0) { hrefs.Add(targetUrl); } var statusIndex = Array.IndexOf(response.ItemsElementName, ItemsChoiceType2.status); var responseStatus = GetStatusCode( response.error, statusIndex == -1 ? null : (string)response.Items[statusIndex], targetUrl, hrefs); if (responseStatus == (int)WebDavStatusCode.NotFound) { return(new RemoteMissingTarget(collection, targetUrl, name, this)); } var propStatIndex = Array.IndexOf(response.ItemsElementName, ItemsChoiceType2.propstat); if (propStatIndex == -1) { throw new RemoteTargetException("No result returned", hrefs); } var propStat = (propstat)response.Items[propStatIndex]; var location = string.IsNullOrEmpty(propStat.location?.href) ? targetUrl : new Uri(propStat.location.href, UriKind.RelativeOrAbsolute); var propStatus = GetStatusCode(propStat.error, propStat.status, location, hrefs); if (propStatus == (int)WebDavStatusCode.NotFound) { return(new RemoteMissingTarget(collection, targetUrl, name, this)); } var resourceType = propStat .prop.Any .SingleOrDefault(x => x.Name == Props.Live.ResourceTypeProperty.PropertyName); var collectionElement = resourceType?.Element(WebDavXml.Dav + "collection"); if (collectionElement == null) { return(new RemoteDocumentTarget(collection, name, targetUrl, this)); } return(new RemoteCollectionTarget(collection, name, collection.DestinationUrl.AppendDirectory(name), false, this)); }
/// <inheritdoc /> public async Task <RemoteCollectionTarget> CreateCollectionAsync( RemoteCollectionTarget collection, string name, CancellationToken cancellationToken) { var targetUrl = collection.DestinationUrl.AppendDirectory(name); using (var httpRequest = new HttpRequestMessage(_mkColHttpMethod, targetUrl)) { using (var httpResponse = await Client.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false)) { if (!httpResponse.IsSuccessStatusCode) { throw new RemoteTargetException("Failed to create"); } var resultDoc = await ReadResponseAsync(httpResponse).ConfigureAwait(false); if (resultDoc == null) { httpResponse.EnsureSuccessStatusCode(); return(new RemoteCollectionTarget(collection, name, targetUrl, true, this)); } var result = Parse(targetUrl, httpResponse, resultDoc); if (result.response.Length == 0) { return(new RemoteCollectionTarget(collection, name, targetUrl, true, this)); } if (result.response.Length > 1) { throw new RemoteTargetException("Received more than one multi-status response", targetUrl); } var response = result.response[0]; var hrefs = response.GetHrefs().Select(x => new Uri(x, UriKind.RelativeOrAbsolute)).ToList(); if (hrefs.Count == 0) { hrefs.Add(targetUrl); } if (response.error != null) { throw CreateException(targetUrl, response.error); } var statusIndex = Array.IndexOf(response.ItemsElementName, ItemsChoiceType2.status); if (statusIndex == -1) { return(new RemoteCollectionTarget(collection, name, targetUrl, true, this)); } var status = Status.Parse((string)response.Items[statusIndex]); if (!status.IsSuccessStatusCode) { throw new RemoteTargetException(status.ToString(), hrefs); } return(new RemoteCollectionTarget(collection, name, targetUrl, true, this)); } } }
/// <inheritdoc /> public override Task ExecuteAsync(ICollection source, RemoteCollectionTarget destination, CancellationToken cancellationToken) { return(Task.FromResult(0)); }
/// <inheritdoc /> public override Task ExecuteAsync(ICollection source, RemoteCollectionTarget destination, CancellationToken cancellationToken) { return(source.DeleteAsync(cancellationToken)); }